iOS本地推送

       iOS上有两种消息通知,一种是本地消息(Local Notification),一种是远程消息(Push Notification,也叫Remote Notification),设计这两种通知的目的都是为了提醒用户,现在有些什么新鲜的事情发生了,吸引用户重新打开应用。本地推送也可以通过服务器控制,比如说如果有新消息了,推送消息,但是,前提是程序必须是打开的,而远程推送,是通过苹果APNS服务器,推送给手机,手机在推送给具体的哪个程序,一般远程推送用到的比较多。


在iOS8之后,以前的本地推送写法可能会出错,接收不到推送的信息,

如果出现以下信息:

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下没有注册,所以需要额外添加对IOS8的注册方法,API中有下面这个方法:

// Registering UIUserNotificationSettings more than once results in previous settings being overwritten.

- (void)registerUserNotificationSettings:(UIUserNotificationSettings*)notificationSettings NS_AVAILABLE_IOS(8_0);



第一步:创建本地推送


iOS本地推送_第1张图片

第二步:接收本地推送


iOS本地推送_第2张图片

第三步:解除本地推送


iOS本地推送_第3张图片
iOS本地推送_第4张图片

过程中可能会出现如下状况:

Attempting to schedule a local notification……with a sound but haven't received permission from the user to play sounds

Attempting to schedule a local notification……with an alert but haven't received permission from the user to display alerts

可能是因为你没有注册,或者设置中没有开启推送功能

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