Send message from iOS Today Widget to app

喜你入骨 提交于 2020-01-03 11:00:10

问题


I have an alarm app, recently powered it with a today widget extension. I need to turn on and off alarm from today widget, but the code to "turn on" and "turn off" is within app, not widget. How can I send a message from today widget to main app?


回答1:


You should write the setting to a shared group NSUserDefault value. See App Extension Programming Guide.

If you need to immediately notify the app from the extension or vice versa, you can also use Darwin notifications, but you can never be certain when either process will be active so you still have to persist the setting into NSUserDefaults. See CFNotificationCenter Reference.



来源:https://stackoverflow.com/questions/35204868/send-message-from-ios-today-widget-to-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!