Skip to content

How to use with Delegates

Danilo edited this page Jun 7, 2020 · 3 revisions

Overview

This framework includes the ability to manage the flow through the iOS delegates, to make the code dependent of the module where resides.

Delegate name Description Data types
didFinishLoading generate when all data are been downloaded and parsed NSString
didFinishLoadingWithDictionary generate when all data are been downloaded and parsed NSDictionary
didFailWithError generate when error occurs NSError
didReceiveDataSize generated during data reception NSUInteger
didSendDataSize generated when sending data NSUInteger
didReceiveResponseCode generate when received a response from server NSInteger
didBeforeSendingURLRequest generated before sending request NSURLRequest
didBeforeParsingResponseData generated before parsing received data NSData
didBeforeParsingResponseString generated before parsing received data NSString

Sample

	#import <SOAPEngine64/SOAPEngine.h>

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

	// 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 Delegates

	- (void)soapEngine:(SOAPEngine *)soapEngine didFailWithError:(NSError *)error
	{
	    NSLog(@"%@", error);
	}

	- ((void)soapEngine:(SOAPEngine*)soapEngine didFinishLoadingWithDictionary:(NSDictionary*)dict data:(NSData*)data
	{
	    NSLog(@"%@", dict);
	}
	
	- (BOOL)soapEngine:(SOAPEngine *)soapEngine didReceiveResponseCode:(NSInteger)statusCode
	{
		// return NO if you want to stop the continuation
		return YES;
	}
	
	- (NSMutableURLRequest*)soapEngine:(SOAPEngine*)soapEngine didBeforeSendingURLRequest:(NSMutableURLRequest*)request
	{
		// edit 'request' if you want to add a header or content customization
		return request;
	}
	
	- (NSData*)soapEngine:(SOAPEngine*)soapEngine didBeforeParsingResponseData:(NSData*)data
	{
		// return nil if you want to stop the continuation
		// and want to customize the parsing
		return data;
	}