Swift 2.0 behaved weird when fetching data using NSData (Playground give different result from the Actual App with same Code)

So I just downloaded Xcode 7 and start playing with Swift 2

I use one of my previous project and also a playground for testing new syntaxes.

However I get into trouble when I use this line of code to fetch raw data from an free online api

let dataSource = NSData(contentsOfURL: NSURL(string: "http://api.openweathermap.org/data/2.5/weather?id=5375480")!)

Inside playground, the code ran perfect and I get excactly what I what.

However I got nil for the dataSource everytime when I build the App on iOS 9b1 or either simulator, since the class is excactly same, I just can't understant why this happened.

I try the product I built from my previous project using Xcode 6.3.2 with Swift 1.2 Syntax which is running on the same iPhone with iOS 9b1, I still get perfect result back, therefore it shows that it's nothing to do with hardware settings or API problems.

Since I'm not sure if either I have missed something is important or it just an other early-pre-release bug cause this problem, please let me know if you found my bug or you are having the same problem I do. ---And sorry for my bad English

Since you are trying to access something with a plain http: url, you might be running into the new App Transport Security which is part of iOS 9 (and OS X 10.11).


https://developer.apple.com/library/prerelease/ios/technotes/App-Transport-Security-Technote/index.html


You might need to add the following to your info.plist

<key>NSAppTransportSecurity</key>
    <dict>
        <key>api.openweathermap.orgo</key>
        <dict>
            <key>NSExceptionAllowsInsecureHTTPLoads</key><true/>
        </dict>
    </dict>
Swift 2.0 behaved weird when fetching data using NSData (Playground give different result from the Actual App with same Code)
 
 
Q