uilocalnotification不是从应用程序发射,而是从模拟器发射

时间:2014-10-07 18:50:20

标签: cocoa-touch uilocalnotification

这是我的UILocalNotification代码:

UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = aNewDate;
localNotification.alertBody = alertBody;
localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.applicationIconBadgeNumber = 1;
localNotification.repeatInterval = NSDayCalendarUnit;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

它从模拟器正确激发,但不是从我的iphone激发。有什么建议吗?

供参考,我在设置中检查了通知,我的应用程序没有出现在那里

1 个答案:

答案 0 :(得分:1)

请参阅:https://developer.apple.com/library/ios/documentation/uikit/reference/UIApplication_Class/index.html#//apple_ref/doc/uid/TP40006728-CH3-SW86

iOS 8代码:(如果定位iOS7,您必须确保不要调用这些方法......)

scheduleLocalNotification:有一个注释:

  

讨论:在安排任何本地通知之前,您必须致电   让系统知道的registerUserNotificationSettings:方法   您计划向用户显示哪些类型的警报(如果有)。

所以...

    UIUserNotificationType  types = UIUserNotificationTypeAlert | UIUserNotificationTypeBadge;

    UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
    [[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];