简体   繁体   English

从扩展名更新UIApplicationShortcutItem

[英]Update UIApplicationShortcutItem from extension

I am building a Today Extension to an app, and it works great to modify my application data. 我正在为应用程序构建“今日扩展”,它对修改我的应用程序数据非常有用。 But now my dynamic UIApplicationShortcutItems are out of sync. 但是现在我的动态UIApplicationShortcutItems不同步了。

I can't access UIApplication.shared from my extension. 我无法从扩展程序访问UIApplication.shared Is there a way to ask the app to update UIApplication.shared.shortcutItems without bringing it to the foreground? 有没有办法让应用程序更新UIApplication.shared.shortcutItems而不会使其前台出现?

I have found that MMWormhole is a good solution to this problem. 我发现MMWormhole是解决此问题的好方法。 It acts somewhat like an NSNotificationCenter notification between the app extension and its host application. 它的作用有点像应用程序扩展与其宿主应用程序之间的NSNotificationCenter通知。 This lets you notify the app to update its shortcut items whenever the today widget takes some action that makes the shortcuts get out of sync. 这样,您可以在Today小部件采取某些使快捷方式不同步的操作时通知应用程序更新其快捷方式项。 The only downside is that the host application must be actively running in the background for the notification to trigger its intended action. 唯一的缺点是主机应用程序必须在后台主动运行,通知才能触发其预期的操作。

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

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