Skip to content

How to use with Notifications

Danilo edited this page Jun 7, 2020 · 3 revisions

Overview

This framework includes the ability to manage the flow through the iOS notification center, to make the code independent of the controller.

Notification descriptions

| Notification name | Description | |---|---|---|---|---| |SOAPEngineDidFinishLoadingNotification|generate when all data are been downloaded and parsed| |SOAPEngineDidFailWithErrorNotification|generate when error occurs| |SOAPEngineDidReceiveResponseCodeNotification|generate when received a response from server| |SOAPEngineDidBeforeSendingURLRequestNotification|generated before sending request| |SOAPEngineDidBeforeParsingResponseStringNotification|generated before parsing received data| |SOAPEngineDidReceiveDataSizeNotification|generated during data reception| |SOAPEngineDidSendDataSizeNotification|generated when sending data|

Notification keys

| UserInfo Key name | Description | Value type | |---|---|---|---|---| |SOAPEngineStatusCodeKey|response status code|NSNumber| |SOAPEngineXMLResponseKey|response xml|NSString| |SOAPEngineXMLDictionaryKey|response dictionary|NSDictionary| |SOAPEngineXMLDatayKey|response data|NSData| |SOAPEngineURLRequestKey|http request|NSURLRequest| |SOAPEngineURLResponseKey|http response|NSURLResponse| |SOAPEngineErrorKey|errors|NSError| |SOAPEngineDataSizeKey|send/receive data size|NSNumber| |SOAPEngineTotalDataSizeKey|send/receive total data size|NSNumber|

Sample

	#import <SOAPEngine64/SOAPEngine.h>

	[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(soapDidFinishLoading:)
		name:SOAPEngineDidFinishLoadingNotification object:nil];
	[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(soapDidFail:)
		name:SOAPEngineDidFailWithErrorNotification object:nil];

	// standard soap service (.asmx)
	SOAPEngine *soap = [[SOAPEngine alloc] init];

	// each single value
	[soap setValue:@"my-value1" forKey:@"Param1"];
	[soap setIntegerValue:1234 forKey:@"Param2"];
	// service url without ?WSDL, and you can search the soapAction in the WSDL
	[soap requestURL:@"http://www.my-web.com/my-service.asmx" 
		  soapAction:@"http://www.my-web.com/My-Method-name"];
 
	#pragma mark - SOAPEngine Notifications

	- (void)soapDidFinishLoading:(NSNotification*)note
	{
		NSLog(@"XML: %@", note.userInfo[SOAPEngineXMLResponseKey]);
		NSLog(@"StatusCode: %@", note.userInfo[SOAPEngineStatusCodeKey]);
		NSLog(@"Dictionary: %@", note.userInfo[SOAPEngineXMLDictionaryKey]);
		NSLog(@"Data: %@", note.userInfo[SOAPEngineXMLDatayKey]);
	}

	- (void)soapDidFail:(NSNotification*)note
	{
		NSLog(@"Error: %@", note.userInfo[SOAPEngineErrorKey]);
	}