我有一个使用位置服务(通过重要位置更新)在后台运行的应用程序。每当更新重要位置时,都会调用 - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
然后调用 [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:.. .
开始我的后台任务。接下来,我尝试触发本地通知:
UILocalNotification *notif = [[UILocalNotification alloc] init];
[notif setAlertAction:@"Test"];
[[UIApplication sharedApplication] presentLocalNotificationNow:notif];
但是,不会向用户显示任何通知。是不是后台不能发送本地通知?感谢您的帮助。
谢谢,
最佳答案
您需要开火日期:
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.alertBody = text;
notification.fireDate = [[NSDate alloc] initWithTimeIntervalSinceNow:0];
notification.timeZone = [NSTimeZone defaultTimeZone];
notification.repeatInterval = 0;
[[UIApplication sharedApplication] presentLocalNotificationNow:notification];
关于ios - 在后台安排的 UILocalNotification 不会触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20037737/