【发布时间】:2015-06-23 12:34:20
【问题描述】:
当我的应用程序进入后台时,applicationDidEnterBackground 会被自动调用,并且在此方法中我们会触发本地通知。但是didReceiveLocalNotification:方法没有被调用
- (void)applicationDidEnterBackground:(UIApplication *)application {
UIApplication *app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
bgTask = UIBackgroundTaskInvalid;
}];
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.fireDate = [NSDate date];
localNotification.alertBody = textString;
localNotification.alertAction = @"View";
localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.applicationIconBadgeNumber = 1;
[[UIApplication sharedApplication] presentLocalNotificationNow:localNotification];
}
【问题讨论】:
-
UILocalNotification *launchNote = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey]; if (launchNote){ 必须工作
-
请以实物为准。
标签: ios objective-c iphone ios7 uilocalnotification