iOS 8 [UIApplication sharedApplication] .scheduledLocalNotifications为空 [英] iOS 8 [UIApplication sharedApplication].scheduledLocalNotifications empty
问题描述
我正在尝试将我的应用更新到iOS 8.在一个功能中,我通过这种方式安排本地通知(我已经检查过该通知并且通知的所有其他部分都是正确的):
i'm trying to update my app to iOS 8. In a function i schedule a local notification (i've already checked that firedate and all other parts of the notification are right) in this way:
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
然后我使用此代码打印预定的本地通知:
then i use this code to print the scheduled local notification:
NSLog(@"notifications %@", [UIApplication sharedApplication].scheduledLocalNotifications );
但数组
[UIApplication sharedApplication].scheduledLocalNotifications
即使通知未被解雇也为空。
然后,为了检查本地通知是否真正安排,我试图使用代码
is empty even if the notification is not fired. Then , to check if the local notification is really scheduled, i tried to use the code
NSLog(@"notification appdelegate %@", application.scheduledLocalNotifications );
函数中的
in the function
- (void)applicationWillResignActive:(UIApplication *)application
of Appdelegate.m
在这种情况下,计划的本地通知数组不为空,NSLog函数打印正确的通知。这只发生在真实设备上,在模拟器中我的应用程序工作正常。问题不是检查用户安排本地通知的权限,因为我已经面对它了。有人能帮帮我吗?一些想法?
of Appdelegate.m
in this case, the array of the scheduled local notifications is not empty and the NSLog function print the correct notification. This happens only on real devices, in the simulator my app works fine. And the problem is not to check the permission of the user to schedule local notifications, cause i've already faced it. Could someone help me? some ideas?
推荐答案
这不是iOS 8问题,但是
This is not iOS 8 issue, but
[UIApplication sharedApplication].scheduledLocalNotifications
问题。最相关的答案我发现这里
issue. Most relevant answer which i found here
现在有类似的问题。我的猜测是iOS没有
立即安排通知,但只在
当前运行循环结束时。我在同一个运行
循环中多次设置
scheduledLocalNotifications属性时遇到了这些问题,并且更改似乎没有相应更新。我想我会
我自己保留一份本地通知数据的副本,只设置
scheduledLocalNotifications并且从不读它。
Having similar issues right now. My guess here is that iOS does not schedule the notifications immediately but only at the end of the current run loop. I am running into these problems when setting the scheduledLocalNotifications property several times in the same run loop and changes don't seem to be updated accordingly. I think I will just keep a copy of the local notifications array myself and only set scheduledLocalNotifications and never read it.
这篇关于iOS 8 [UIApplication sharedApplication] .scheduledLocalNotifications为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!