【发布时间】:2013-11-04 21:29:38
【问题描述】:
在设置包中,我有一个多选选项。因此,当我选择某些内容时,应用程序应该接收新值并使用它来启动 UILocalNotification。我试过的,只有在我打开应用程序时才会更新值。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(defaultsChanged:)
name:NSUserDefaultsDidChangeNotification
object:nil];
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[[NSUserDefaults standardUserDefaults]synchronize];
}
【问题讨论】:
-
你的问题不清楚。如果“应用程序在后台运行”,它如何接收新值?为什么需要
defaultsChanged:选择器? -
还请澄清您所说的“在后台运行”是什么意思,它可能意味着几件事,例如播放音频、提供 GPS 或 VOIP,或执行即将到期的任务。您可能还指“暂停”
-
我正在使用选择器查看用户是否更改了设置包中的任何选项。暂停是我的意思。
-
我猜您在启动时轮询 NSUserDefaults,并在此阶段应用设置。当用户从 Settings.app 中更改设置时,如果检测到这些更改并将其应用于 NSUserDefaults,那么您的应用在下次启动之前不会知道。
-
好的,谢谢。因此,无法在下次启动时通知应用。
标签: ios objective-c nsuserdefaults uilocalnotification settings.bundle