本地消息提醒

-(void)LocalNotification{

if([[[UIDevicecurrentDevice]systemVersion]floatValue] >= 8.0) {

if([[UIApplicationsharedApplication]currentUserNotificationSettings].types!=UIUserNotificationTypeNone)

{

[selfaddLocalNotification];

}else{

[[UIApplicationsharedApplication]registerUserNotificationSettings:[UIUserNotificationSettingssettingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSoundcategories:nil]];

}

}

}

-(void) applicationFinishedRestoringState{

}

-(void)addLocalNotification{

//定义本地通知对象

notification=[[UILocalNotificationalloc]init];

//设置通知属性

notification.alertBody=@"已越界";//通知主体

notification.alertAction=@"打开应用";//待机界面的滑动动作提示

notification.alertLaunchImage=@"Default";//通过点击通知打开应用时的启动图片,这里使用程序启动图片

notification.soundName=UILocalNotificationDefaultSoundName;//收到通知时播放的声音,默认消息声音

//设置用户信息

notification.userInfo=@{@"id":@1,@"user":@"Kenshin Cui"};//绑定到通知上的其他附加信息

//调用通知

[[UIApplicationsharedApplication]scheduleLocalNotification:notification];

}

#pragma mark移除本地通知,在不需要此通知时记得移除

-(void)removeNotification{

[[UIApplicationsharedApplication]cancelAllLocalNotifications];

}

#pragma mark调用过用户注册通知方法之后执行(也就是调用完registerUserNotificationSettings:方法之后执行)

-(void)application:(UIApplication*)application didRegisterUserNotificationSettings:(UIUserNotificationSettings*)notificationSettings{

if(notificationSettings.types!=UIUserNotificationTypeNone) {

[selfaddLocalNotification];

}

}

你可能感兴趣的:(本地消息提醒)