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);



第一步:创建本地推送


第二步:接收本地推送


第三步:解除本地推送


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

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

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 一、简介 目前说的是基于ios10之前,所以有些类是过期的. 推送分为本地推送和远程推送2种。可以在应用没有打开甚...
    JingYa_Lu阅读 943评论 0 0
  • 1. 推送通知简介 1.1: 这里说的推送通知跟NSNotification有所区别 NSNotification...
    iYeso阅读 1,069评论 0 0
  • iOS中通知机制又叫消息机制,其包括两类:一类是本地通知;另一类是推送通知,也叫远程通知。两种通知在iOS中...
    七里汀阅读 2,129评论 3 2
  • iOS本地推送 第一步:创建本地推送 // 创建一个本地推送 UILocalNotifica...
    学无止境666阅读 1,201评论 2 5
  • 1 刘同当年在他的新书《你的孤独,虽败犹荣》里说:读大学的价值也许在于能认识未来几十年最重要的朋友,能分辨哪些人自...
    阿雅克肖Aay阅读 178评论 0 1