简体   繁体   English

在Apple Watch上实现登录机制的最佳实践

[英]Best practice to implement login mechanism on Apple Watch

I'd like to ask for advice about what is the best practice to implement a communication mechanism for an Apple Watch app to make sure the user has logged in on the iPhone app. 我想征询有关为Apple Watch应用程序实施通信机制以确保用户已登录iPhone应用程序的最佳做法的建议。

My Watch app is paired with the corresponding iPhone app. 我的手表应用程序已与相应的iPhone应用程序配对。 The iPhone app needs to be logged in in order for the Watch app to be used (to display info, etc.) The login mechanism on the iPhone has already been implemented and it is working perfectly. iPhone应用程序需要登录才能使用Watch应用程序(以显示信息等)。iPhone上的登录机制已经实现,并且可以正常运行。 The Watch app needs to ask the corresponding iPhone app if the user has logged in. If so, it will return a code, and in turn the Watch can display data or query the server (with the login credentials) for more data. Watch应用程序需要询问相应的iPhone应用程序用户是否已登录。如果已登录,它将返回一个代码,然后Watch可以显示数据或查询服务器(使用登录凭据)以获取更多数据。 If the user has not logged in on iPhone, the Watch app will display a button asking the user to login on the iPhone app. 如果用户尚未登录iPhone,Watch应用程序将显示一个按钮,要求用户登录iPhone应用程序。

I've checked out Apple's doc and I think WCSession's - sendMessage:replyHandler:errorHandler on the Watch and its corresponding WCSessionDelegate's - session:didReceiveMessage on iOS seems to be way to go. 我已经检查了Apple的文档,并且认为Watch上的WCSession的-sendMessage:replyHandler:errorHandler和iOS上其对应的WCSessionDelegate的-session:didReceiveMessage似乎是可行的方法。

Any advice, or better ways to implement such functionality/logic? 有什么建议或更好的方法来实现这种功能/逻辑?

Thanks! 谢谢!

Using WCSession's sendMessage:replyHandler:errorHandler is indeed a good way to go about getting data from the iPhone on demand. 使用WCSession的sendMessage:replyHandler:errorHandler确实是按需从iPhone获取数据的好方法。 Since you need to ask the iPhone when the user is doing an action on the watch, I would go with this method. 由于您需要询问iPhone用户何时在手表上进行操作,因此我会采用这种方法。

You may also consider using handoff from the Apple Watch to the iPhone so your user goes right to the screen on the phone you want them to login on. 您也可以考虑使用从Apple Watch到iPhone的切换功能,以便您的用户直接转到您要他们登录的手机屏幕上。

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

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