本地通知

//本地通知,只有程序处于非运行状态,才会出发本地通知

    

    //1.创建本地通知的对象

    UILocalNotification *notification = [[UILocalNotification alloc] init];

    

    //2.设置通知触发的时间

    notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];

    

    //3.设置弹出提示的内容

    notification.alertBody = @"起床了";

    

    //4.设置按钮的标题

    notification.alertTitle = @"提醒";

//    notification.alertAction = @"提醒";

    

    

    //注册本地通知,注册之后,通知才会生效

    [[UIApplication sharedApplication] scheduleLocalNotification:notification];

    

    [UIApplication sharedApplication].applicationIconBadgeNumber = 3;


 //iOS8中,本地通知需要添加以下代码才能正确运行-- 得到用户的允许推送通知

    UIUserNotificationType type=UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound;

    UIUserNotificationSettings *setting=[UIUserNotificationSettings settingsForTypes:type categories:nil];

    [[UIApplication sharedApplication]registerUserNotificationSettings:setting];

    





你可能感兴趣的:(本地推送)