Ios 在后台调度的UILocalNotification不';t火

Ios 在后台调度的UILocalNotification不';t火,ios,iphone,objective-c,cocoa-touch,uilocalnotification,Ios,Iphone,Objective C,Cocoa Touch,Uilocalnotification,我有一个应用程序在后台运行,使用位置服务(通过重要的位置更新)。每当更新一个重要位置时,-(void)locationManager:(CLLocationManager*)manager didUpdateLocations:(NSArray*)位置就会被调用,然后我调用[[UIApplication sharedApplication]beginBackgroundTaskWithExpirationHandler:…来启动我的后台任务。接下来,我尝试触发一个本地通知: UILocalNot

我有一个应用程序在后台运行,使用位置服务(通过重要的位置更新)。每当更新一个重要位置时,
-(void)locationManager:(CLLocationManager*)manager didUpdateLocations:(NSArray*)位置
就会被调用,然后我调用
[[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];

你是否验证了你的后台任务正在完成?你具体在哪里安排本地通知,它是否处于某种完成块中?是的,你可以从后台发送它们。我怀疑你所指的代码有其他问题。可能你的应用程序不在后台。你检查过应用程序代理是否<代码>应用程序:didReceiveLocalNotification:被调用?@PeterMoti没有完成块。我在调用beginBackgroundTaskWithExpirationHandler后立即在didUpdateLocations方法中安排本地通知。我是否做错了什么?您是否验证了您的后台提取实际上正在工作?另外,我还想知道orough,您是在设备上运行,而不是在模拟器上运行吗?我已经验证了我的后台提取工作正常,但我刚刚意识到我没有调用
[[UIApplication sharedApplication]endBackgroundTask:bgTask]
当我完成任务时。这能解决我的问题吗?从Apple docs:
根据为时区指定的值解释启动日期。如果指定的值为零或是过去的日期,通知将立即发送。
是的,此代码适用于我的项目。我使用它发布本地通知。您我可以试试。