0

模拟器和本地通知是否存在错误,或者我做错了什么。

// on button click fire off notification for 30 seconds from now
-(IBAction)scheduleNotification{
    UILocalNotification *localNotif = [[UILocalNotification alloc] init];

    NSDate *item = [NSDate dateWithTimeIntervalSinceNow:30]; 

    if (localNotif == nil)
        return;     
    localNotif.fireDate = item;
    localNotif.timeZone = [NSTimeZone defaultTimeZone];
    localNotif.alertBody =  NSLocalizedString(@"Test Notification", nil);
    localNotif.alertAction = NSLocalizedString(@"View Details", nil);
    localNotif.soundName = UILocalNotificationDefaultSoundName;
    localNotif.applicationIconBadgeNumber = 0;
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
    [localNotif release];
}   



- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {
    // Handle the notificaton when the app is running
    NSLog(@"Recieved Notification %@",notif);
}

didReceiveLocalNotification记录了 2 个通知,但模拟器从未真正显示通知。

Recieved Notification <UIConcreteLocalNotification: 0x5943450>{fire date = 2010-08-25 09:36:25 -0400, time zone = America/New_York (EDT) offset -14400 (Daylight), repeat interval = 0, next fire date = 2010-08-25 09:36:25 -0400}

Recieved Notification <UIConcreteLocalNotification: 0x5c53e00>{fire date = 2010-08-25 09:36:25 -0400, time zone = America/New_York (EDT) offset -14400 (Daylight), repeat interval = 0, next fire date = (null)}
4

1 回答 1

2

如果您在应用程序运行时收到本地/推送通知,您将不会看到任何警报。除非你在应用程序中显示你自己的警报:didReceiveLocalNotification:,当然。

于 2010-10-08T07:34:25.127 回答