What is the best practice to call URL in apple wat

2019-08-14 06:52发布

问题:

What is the best practice to call API from Apple watch

  1. use sendMessage "watchConnectivity" from Apple watch to iPhone to call the API

or

  1. 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.