将消息从iOS Today小部件发送到应用 [英] Send message from iOS Today Widget to app

查看:103
本文介绍了将消息从iOS Today小部件发送到应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个警报应用程序,最近使用今天的窗口小部件扩展为它供电. 我需要从今天的窗口小部件打开和关闭警报,但是打开"和关闭"的代码在应用程序内部,而不是在窗口小部件中. 如何将message从今天的小部件发送到主应用?

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?

推荐答案

您应将设置写入共享组NSUserDefault值.请参阅应用程序扩展编程指南.

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

如果您需要立即从扩展名中通知应用程序,反之亦然,您也可以使用Darwin通知,但是您无法确定哪个进程将处于活动状态,因此您仍然必须将该设置保存到NSUserDefaults中.请参阅 CFNotificationCenter参考.

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.

这篇关于将消息从iOS Today小部件发送到应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆