简体   繁体   English

在Apple Watch中调用URL的最佳做法是什么?

[英]What is the best practice to call URL in apple watch?

What is the best practice to call API from Apple watch 从Apple Watch调用API的最佳实践是什么

  1. use sendMessage "watchConnectivity" from Apple watch to iPhone to call the API 使用从Apple Watch到iPhone的sendMessage“ watchConnectivity”来调用API

or 要么

  1. use NSURLSession to call the API from the watch itself ? 使用NSURLSession从手表本身调用API?

Using the NSURLSession API, the device that performs the request is abstracted from the developer. 使用NSURLSession API,可以从开发人员中提取执行请求的设备。 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. 如果电话不可用,如果有已知的2.4 GHz网络可用,手表可以自行执行请求。

The answer is NSURLSession. 答案是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 这样,您不必担心在手机之间传递信息并使用WatchConnectivity框架进行观看,NSURLSession可以为您做到这一点

苹果公司在WWDC实验室中建议直接从手表使用NSURLSession,所以我建议#2。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM