[英]How to call a method in the parent iPhone app from Today Extension in Swift?
I have just created an Apple Watch extension to my iPhone App and used the following method to update my app data. 我刚刚为我的iPhone应用程序创建了Apple Watch扩展,并使用以下方法更新了我的应用程序数据。
// Call the parent application which launches a method to update the app data
WatchViewController.openParentApplication([:],
reply: { (reply, error) -> Void in
self.updateGui() // update the gui when done
})
Is there anything similar for Apple Today Extensions (widgets)? Apple Today Extensions(小工具)有类似的东西吗? It feels wrong to implement all the client-server communication again for the extension.
再次为扩展实现所有的客户端-服务器通信是不对的。
Or how do you suggest to update my data (stored in app group throughout iPhone app, WatchKit and Today Extension). 或您如何建议更新我的数据(存储在整个iPhone应用程序,WatchKit和Today Extension中的应用程序组中)。
No need to write client-server communication code separate for container app and its extension. 无需针对容器应用及其扩展名单独编写客户端-服务器通信代码。
Apple recommends embedded frameworks for the same. 苹果公司建议使用相同的嵌入式框架。 You create an embedded framework which can be used across both targets.
您创建了一个可在两个目标中使用的嵌入式框架。 Place code that will need to be used by both the container app and extension in the framework to avoid code repetition.
将容器应用程序和扩展程序都需要在框架中使用的代码避免代码重复。
And for sharing data between container app and extension, you can use NSUserDefaults through AppGroup. 为了在容器应用程序和扩展之间共享数据,您可以通过AppGroup使用NSUserDefaults。
Please check Apple documentation . 请检查Apple文档 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.