我目前正在安排本地通知,如果用户当天尚未打开应用程序,则每天下午6点出现一次.如果用户已经加载了应用程序,那么我想取消当天的通知,并在明天下午6点安排新的通知.但是,当我尝试迭代计划通知列表(这不是我在应用程序中的唯一本地通知)时,通知会正确显示,[[UIApplication sharedApplication] scheduledLocalNotifications]数组始终为空.以下是给我带来麻烦的代码段:
// See if we need to create a local notification to tell the user that they can receive a daily reward
NSArray *notifications = [[UIApplication sharedApplication] scheduledLocalNotifications]; // <- This is always empty
// Iterate over all the pending notifications
for( int iter = 0; iter < [notifications count]; iter++ )
{
UILocalNotification* localNotification = [notifications objectAtIndex:iter];
if( [[localNotification.userInfo objectForKey:@"source"] isEqualToString:@"dailyReminder"] )
[[UIApplication sharedApplication] cancelLocalNotification:localNotification];
}
NSCalendar* calendar = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease];
[calendar setTimeZone:[NSTimeZone localTimeZone]];
NSDateComponents …Run Code Online (Sandbox Code Playgroud) iphone objective-c ios localnotification uilocalnotification