In my watchOS 2 Apple Watch WatchKit Extension, I use NSURL and NSData to request the URL and get the sent JSON. However, this only works in the simulator. At first I had a problem, because I used an unreliable address (internal IP address), but after adding some keys and values ββto Info.plist, this problem was fixed. To make sure the URL was trusted, I used the public URL from the GitHub API ( https://api.github.com/users/mralexgray/repos ). I use the following code to get a response:
var responseData: NSData? = nil
if let url = NSURL(string: "https://api.github.com/users/mralexgray/repos") {
if let data = NSData(contentsOfURL: url){
responseData = data
}
}
In my watchOS 2 simulator, responseData fills correctly, but on my Apple Watch it looks like line number 3 and its body is simply skipped. Is it a problem, a function, or am I something wrong?
Roel source
share