Pallavi Konda
Pallavi Konda

Reputation: 1670

Consuming services in iOS 9.0

I have implemented following code for consuming servives in iOS.

NSString *urlStr=[NSString stringWithFormat:@“SomeURL”];
NSString *jsonStr=[NSString stringWithFormat:@“{\”SomeParameter\”:\”%@\”}”];
NSData *postData = [jsonStr dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[postData length]];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:urlStr]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/json;charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];

NSURLResponse *response;
NSData *POSTReply = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];
NSString *theReply = [[NSString alloc] initWithBytes:[POSTReply bytes] length:[POSTReply length] encoding: NSUTF8StringEncoding];
SBJSON *parser = [[SBJSON alloc] init];
NSArray *arryTerritory = (NSArray *) [parser objectWithString:theReply error:nil];

NSLog(@“%@”,[arryTerritory description]);

This is my code when I run the code with xCode 6.4 and iOS 9.0 am able to receive the data in NSData *postData and NSString *postLength.

But while compiling the code with iOS 9.0 I am unable to get the data.

OutPut is nil.

Is there any different process to consume the services in xCode 7 Beta. Need ipa which is compatible for these versions.

Upvotes: 0

Views: 111

Answers (1)

Pallavi Konda
Pallavi Konda

Reputation: 1670

Here I should add a deceleration to info.plist where it needs secure communication. This is the code i added to my info.plist.I think its new in ios 9 and xCode 7 bete versions.

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

Upvotes: 1

Related Questions