SDMConnectivity

The Connectivity library exposes APIs required to set up and start HTTP requests, and retrieve the payloads. For crossing a company firewall for enterprise use cases, you need to use SUP. Therefore, the connectivity component in the OData SDK offers a connection to SUP by default. For development and demo purposes, the SDK also provides a possibility to use HTTP or HTTPS.

List of Features

SDMConnectivity Public APIs

Note: The SUP APIs and their descriptions are available after the installation of Sybase Unwired Platform at the following location within your installation folder: ...\UnwiredPlatform\ClientAPI\apidoc.
-(id)initWithURL:(NSURL *)newURL
+(id)requestWithURL:(NSURL *)newURL
-(void) setUserName:(NSString*)username
-(void) setPassword:(NSString*)username
-(void) setClientDelegate:(id)clientDelegate
-(void) setDidFinishSelector:(SEL)didFinishSelector
-(void) setDidFailSelector:(SEL)didFinishSelector
-(void) setRequestMethod:(NSString*)httpMethod
-(void) startAsynchronous
-(void) startSynchronous
-(void) cancel
-(void) setUploadProgressDelegate
-(void) setDownloadProgressDelegate
-(void) setShowAccurateProgress
-(void)setMaxConcurrentHTTPRequestCount:(const unsigned char)cnt  
-(NSInteger) getMaxConcurrentHTTPRequestCount
-(NSString*) responseString
-(NSData*) responseData
-addRequestHeader:(NSString*)header value:(NSString*)value
-appendPostData:(NSData*)postData
-(void) buildPostBody
-(void) setClientCertificateIdentity:(SecIdentityRef)anIdentity

Example - Request Initialization

NSString* serverUrlWithLanguage = [NSString stringWithFormat:@"%@?sap-language=%@",[ConnectivitySettings url],[[ConnectivitySettings instance] currentLanguage]];
[self setRequest:[SDMHTTPRequest requestWithURL:[NSURL URLWithString: serverUrlWithLanguage]]];

NSString* serverUrlWithLanguage = [NSString stringWithFormat:@"%@?sap-language=%@",[ConnectivitySettings url],[[ConnectivitySettings instance] currentLanguage]];
m_AsynchRequest = [HTTPRequest requestWithURL:[NSURL URLWithString: serverUrlWithLanguage]];

[m_AsynchRequest setDidFinishSelector:@selector(serviceDocFetchComplete:)];

[m_AsynchRequest setDidFailSelector:@selector(serviceDocFetchFailed:)];

[m_AsynchRequest setRequestMethod:@”POST”];

Example - Request Execution

[m_AsynchRequest startSynchronous];

[m_AsynchRequest cancel];

Example - Progress Tracking

[m_AsynchRequest setUploadProgressDelegate:m_ProgressIndicator]; 

Example - Request Payload

NSString* stringPayload = [m_AsynchRequest responseString];

NSData* binaryPayload = [m_AsynchRequest responseData];

Example - Request Setup

[m_AsynchRequest addRequestHeader:@"myApplicationId" value:kAppId];
[m_AsynchRequest addRequestHeader:@"deviceType" value:@"iphone"];

[m_AsynchRequest appendPostData:urlEncData];
NSData* encodedPostData = [encodedPostStr dataUsingEncoding:NSUTF8StringEncoding];
[m_AsynchRequest appendPostData:encodedPostData];
// once we have them all, build the POST body
 [m_AsynchRequest buildPostBody];

[m_AsynchRequest addRequestHeader:@"myApplicationId" value:kAppId];
[m_AsynchRequest addRequestHeader:@"deviceType" value:@"iphone"];

Technical Details

The SDMConnectivity library wraps internally the socket based CFNetwork APIs and uses NSOperationQueue to collect and fire asynchronous requests. The number of maximum concurrent HTTP requests is limited to MAX_CONCURRENT_THREADS (Default: 5).

The SDMHttpRequestDelegate protocol defines default delegate methods for request status related housekeeping. Client classes can implement this protocol to hook in for requestStarted / requestFinished / requestFailed default delegates.

In cases when clients prefer to use custom selectors for request notifications, they do not neéed to adapt the SDMHttpRequestDelegate protocol, but rather register themselves as delegates and set their own selectors as didStartSelector / didFinishSelector / didFailSelector.

The SDMProgressDelegate defines default delegate methods for upload and download progress notification. The protocol has to be adapted by client classes to hook in for didReceiveBytes / didSendBytes / incrementDownloadSizeBy / incrementUploadSizeBy delegates. You can choose to register a download or upload progress delegate using SDMHttpRequest instance methods -setUploadProgressDelegate and -setDownloadProgressDelegate.

The factory method instantiates SUPRequest by default. SUPRequest must be used to communicate through Online Data Proxy channel; it is part of the ODP SUP libraries, which have to be linked to the project. However, for development and testing purposes you can use HTTP requests. The SDMConnectivity library provides the means to transparently choose between SUPRequest using connections through the Online Data Proxy (ODP) Channel or SDMHttpRequest which leverages the usage of classical HTTP/HTTPS connections.

Protocols:
SDMHttpRequestDelegate

+ requestStarted:
+ requestFinished:
+ requestFailed:
+ requestRedirected:
+ request:didRecieveData:
+ authenticationNeededForRequest:
+ proxyAuthenticationNeededForRequest:


SDMProgressDelegate

+ setProgress:
+ request:didReceiveBytes:
+ request:didSendBytes:
+ request:incrementDownloadSizeBy:
+ request:incrementUploadSizeBy: