简体   繁体   English

如何从Swift的Today扩展中的父iPhone应用程序中调用方法?

[英]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.

相关问题 如何从父级ios应用程序调用watchkit扩展中的方法 - How to call the method in watchkit extension from parent ios app 如何将应用程序中的数据显示到 Today Extension Swift - How to show data from app to Today Extension Swift 如何从应用程序中删除ios今天的扩展 - How to remove ios today extension from app 如何从应用程序返回到今天的扩展 - How to return to today extension from app 如何从Today扩展中更新应用 - How to update app from Today extension 从Swift 4中的Today扩展打开时,包含应用程序崩溃 - Containing App crashes when opened from Today extension in swift 4 iOS Swift Today Extension:从容器应用程序导入类? - iOS Swift Today Extension: import class from container app? 如何使用Swift在我的应用程序的“今日扩展”中的Safari中打开url - How to open a url in Safari from my Today Extension within my app using Swift 当主应用程序未打开时,Swift 如何从今天的扩展中打开特定的视图控制器 - Swift how to open specific viewcontroller from today extension when main app is not open 在Swift中,如何将永久变量从主iOS应用传递到扩展程序(例如,今天的扩展程序,自定义键盘) - In Swift, how would I pass a permanent variable from the main iOS app to an extension (e.g. today extension, custom keyboard)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM