ios – Apple Watch,WatchKit Extension和主要应用程序

ios – Apple Watch,WatchKit Extension和主要应用程序,第1张

概述有逻辑的主要应用程序,我们将应用程序扩展到Apple Watch. 添加目标xCode后,再创建2个应用程序:扩展代码和监视工具包应用程序. 问题:扩展程序中的代码如何重用已准备好的主要iOS应用程序的逻辑?扩展程序应用程序如何与主App通信并发送命令. 要与包含的iPhone应用程序通信,您可以使用 (BOOL)openParentApplication:(NSDictionary *)user 有逻辑的主要应用程序,我们将应用程序扩展到Apple Watch.

添加目标xCode后,再创建2个应用程序:扩展代码和监视工具包应用程序.

问题:扩展程序中的代码如何重用已准备好的主要iOS应用程序的逻辑?扩展程序应用程序如何与主App通信并发送命令.

解决方法 要与包含的iPhone应用程序通信,您可以使用
(BOol)openParentApplication:(NSDictionary *)userInfo                        reply:(voID (^)(NSDictionary *replyInfo,NSError *error))reply

在你的WKInterfaceController中

来自Apple Docs

Use this method to communicate with your containing iOS app. Calling
the method causes iOS to launch the app in the background (as needed)
and call the application:handleWatchKitExtensionRequest:reply: method
of its app delegate. That method has the following signature:

- (voID)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInforeply:(voID(^)(NSDictionary *replyInfo))reply

The app delegate receives the dictionary you pass into the userInfo parameter and uses it to process whatever request you made. If it provIDes a reply,WatchKit executes the block you provIDed in the reply parameter of this method.

总结

以上是内存溢出为你收集整理的ios – Apple Watch,WatchKit Extension和主要应用程序全部内容,希望文章能够帮你解决ios – Apple Watch,WatchKit Extension和主要应用程序所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1100558.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存