iOS8 本地通知使用方法

版权所有,禁止匿名转载;禁止商业使用。

在运行脚本时,发现程序在5S虚拟机上一切正常,但是使用iPhone6 Plus虚拟机时报错,根据信息可知是添加本地通知时报错。信息如下:


2015-02-06 17:41:49.369 Demo[6744:1604149] Setting a reminder for 2015-02-06 09:42:00 +0000
2015-02-06 17:41:49.384 Demo[6744:1604149] Attempting to schedule a local notification
{fire date = Friday, February 6, 2015 at 5:42:00 PM China Standard Time, time zone = (null), repeat interval = 0, repeat count = UILocalNotificationInfiniteRepeatCount, next fire date = Friday, February 6, 2015 at 5:42:00 PM China Standard Time, user info = (null)} with an alert but haven’t received permission from the user to display alerts
2015-02-06 17:41:51.263 Demo[6744:1604608] Terminating since there is no system app.


参考: cocoachina讨论


/*
报错信息可能如下:
1 Attempting to schedule a local notification
2 with an alert but haven't received permission from the user to display alerts
3 with a sound but haven't received permission from the user to play sounds
*/
//ios8中,在APP启动后增加如下代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//设置window
  //ios8  注册本地通知
  if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]) {
    UIUserNotificationSettings *noteSetting =[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound
                                           categories:nil];
    [[UIApplication sharedApplication] registerUserNotificationSettings:noteSetting];
  }
}


0 0