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

有逻辑的主要应用程序,我们将应用程序扩展到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 *)userInfo
reply:(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.

相关文章

背景 前端时间产品经理决定使用百度统计,使得 工程B 中原统计sdk-友盟统计,需要被去除。之前尝试去除...
结论: alloc负责分配内存和创建对象对应的isa指针; init只是返回alloc生成的对象。 所以alloc后,多次...
更新 如果UI愿意把启动图切割成n份,按一定约束在launchscreen.storyboard中进行排版,启动图效果会更好...
最近在看一本书《Effective OC 2.0》,今天看到有个tip是OC适中循环各自优劣性,作者最终推荐此块循环。...
// // ViewController.m // paintCodeTestOC //gif // Created by LongMa on 2019/7/25. // #import &a...
背景介绍 一般情况下,出于省电、权限、合理性等因素考虑,给人的感觉是很多奇怪的需求安卓可以实现,但...