NSData returning nil after upgrading the phone to iOS10

Hello,


below is our code block used in our app to connect to web service. Our app worked fine in iOS9. But users upgraded to iOS10, the app failed to connect to the web service.

data on line 8 returns nil.

error returns "domain:@"NSCocoaErrorDomain" -code:256"

the url we use in this format: "https://***.***.com/xxiOSService/partFinder.svc/GetLogin/ID=2451789487"


any idea why it only fails in iOS10?

thank you!


1) NSSTRING *_login = badgeTxt.text;

2) NSSTRING *lab = [NSString stringWithFormat:@"%@", _login];

3) NSSTRING *filepath = [WcfServiceURL1 absoluteString];

4) NSSTRING *test = [URL stringByAppendingString:filePath];

5) NSSTRING *GetURL1 = [test stringByAppendingString:lab];

6) NSURL *url = [NSURL URLWithString:GetURL1];

7) NSError *error = nil;

8) NSData *data = [NSData dataWithContentsOfURL: url options:NSDataReadingUncached error:&

9) error];

10) if (!error)

11) {

12) NSDictionary* json = [NSJSONSerialization

13) JSONObjectWithData:data

14) options:NSJSONReadingMutableContainers

15) error:&error];

Replies

There are many potential reasons for this. You wrote:

But users upgraded to iOS 10, the app failed to connect to the web service.

Is it just some users? Or all users? Can you reproduce the problem yourself?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

I would suspect an authentication issue.


Have you looked at this :


http : / / stackoverflow.com/questions/18020494/nsdata-datawithcontentsofurl-not-returning-data-for-url-that-shows-in-browser

Hello,

it is for ALL iOS10 users. Yes, i can reproduce the issue.

Also, today we found out that users with iOS version 10.1.1 are not even able to download the app from our server.

If the https: site redirects you to an http: site then it will fail ATS. You may need to add an exception to your App Transport Security Settings.


Also, what do you mean by "not even able to download the app from our server"? iOS apps are downloaded through the App Store.

This is probably a TLS issue. For example, it’s possible your server is relying on RC4, which has been disabled on iOS 10 because it’s no longer secure (for this and other TLS-related news, see my App Transport Security pinned post).

The first thing I recommend is that you try to access the same resource via NSURLSession. This will give you access to the actual error that’s being returned by the networking stack. NSURLSession make it easy to run simple requests like yours. For example:

… assuming `url` is set up as per your code …
NSURLRequest * request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60.0];
[[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData * data, NSURLResponse * response, NSError * error) {
    if (error != nil) {
        NSLog(@"error %@", error);
    } else {
        NSLog(@"success");
    }
}] resume];

If you can post details about the error, I should be able to advise you as to how to proceed.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hello below is our plist. This is an enterprise app hosted on our windows server 2008 machine. do you suggest anything to add to the plist? or anything?

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<plist version="1.0">

<dict>

<key>items</key>

<array>

<dict>

<key>assets</key>

<array>

<dict>

<key>kind</key>

<string>software-package</string>

<key>url</key>

<string>https://abc.xyz.com/IphoneIPA/Myproduct.ipa</string>

</dict>

</array>

<key>metadata</key>

<dict>

<key>bundle-identifier</key>

<string>Mycompany.Myproduct</string>

<key>bundle-version</key>

<string>1.3</string>

<key>kind</key>

<string>software</string>

<key>title</key>

<string>Myproduct</string>

</dict>

</dict>

</array>

</dict>

</plist>

This is an enterprise app hosted on our … server

Is your server’s certificate issued by a system-trusted CA? Or issued by your enterprise CA? My guess is that it’s the latter, in which case it sounds like you’re having trust evaluation problems with that CA. Are you sure the CA’s root certificate is installed on the device? Can you access other resources on that server from built-in tools, like Safari?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hi,


the web service is accessible from safari and not from k2 iphone app.It used to work from k2 iphone app, like i said earlier.

the cert we use on the web server is Digicert.

the web service is accessible from safari and not from k2 iphone app.

What is “k2 iphone app” in this context?

Try accessing the resource using NSURLSession (as I suggested in my 15 Nov post). What error do you get?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Although the thread below is a deeper understanding of the problem/solution, a simple solution is to add the following lines to your info.plist:

1) add the following under "Info" in the target:

App Transport Security Settings - Dictionary

Exception Domains - Dictionary

yourWebsiteHere.com - Dictionary

NSExceptionAllowsInsecure H T TP Loads - Boolean - YES

NSIncludesSubdomains - Boolean - YES


2) or add directly to the plist:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" .......

<plist version="1.0">

<dict>

<key>NSExceptionDomains</key>

<dict>

<key>yourwebsitewhateveritishere.com</key> // this is your http website without, I think, the first h t t p : / /

<dict>

<key>NSExceptionAllowsInsecureHTTPLoads</key>

<true/>

<key>NSIncludesSubdomains</key>

<true/>

</dict>

</dict>

</dict>

</plist>