问题
What is the best practice to call API from Apple watch
- use sendMessage "watchConnectivity" from Apple watch to iPhone to call the API
or
- use NSURLSession to call the API from the watch itself ?
回答1:
Using the NSURLSession API, the device that performs the request is abstracted from the developer. If the phone is available, it will perform the request on the phone and return it to your watch app as if the watch itself performed the request. If the phone is not available, the watch can perform request on its own if there is a known 2.4 GHz network available.
The answer is NSURLSession. That way you don't have to worry about passing info between the phone and watch with the WatchConnectivity framework, NSURLSession does it for you
回答2:
Using NSURLSession directly from the watch was what Apple suggested in the WWDC labs, so I'd suggest #2.
来源:https://stackoverflow.com/questions/33854279/what-is-the-best-practice-to-call-url-in-apple-watch