【发布时间】:2017-05-18 21:04:09
【问题描述】:
我正在尝试在应用程序完全关闭(终止)的情况下获得预定的 UILocalNotification,因为方法 didReceiveLocalNotification: 没有被调用,我正在尝试使用以下代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UILocalNotification *localNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
NSLog(@"LOCAL NOTIFICATION - %@",localNotification);
if (localNotification) {
//HANDLE THE NOTIFICATION
}
return YES;
}
这就是我创建UILocalNotification 的方式:
UILocalNotification * notificationRH = [UILocalNotification new];
notificationRH.fireDate = date;
notificationRH.repeatInterval = repetition;
notificationRH.alertBody = body;
notificationRH.alertAction = title;
notificationRH.hasAction = title ? 1 : 0;
notificationRH.timeZone = [NSTimeZone defaultTimeZone];
notificationRH.soundName = sounds ? UILocalNotificationDefaultSoundName : nil;
notificationRH.userInfo = @{@"test": title};
但问题是方法上的launchOptions 总是返回(null),并且我无法在应用程序关闭时触发通知。有人可以帮我吗?
非常感谢!!
【问题讨论】:
-
我没有看到你真正调度本地通知。 制造是不够的;你必须把它交给系统。
-
对不起,这是因为这只是创建,经理课程安排通知,它正在工作,如果应用程序在后台或终止,我无法处理它。否则我只是使用 didReceiveLocalNotification,那样工作正常......
-
我建议“经理类”以某种方式做错了。如果操作正确,您将在应用委托中收到本地通知。
-
证明正在安排通知:显示应用未运行时出现的警报的屏幕截图。
标签: ios objective-c uilocalnotification