? ? ? ?iOS上有兩種消息通知,一種是本地消息(Local Notification),一種是遠(yuǎn)程消息(Push Notification,也叫Remote Notification),設(shè)計(jì)這兩種通知的目的都是為了提醒用戶,現(xiàn)在有些什么新鮮的事情發(fā)生了,吸引用戶重新打開應(yīng)用。本地推送也可以通過服務(wù)器控制,比如說如果有新消息了,推送消息,但是,前提是程序必須是打開的,而遠(yuǎn)程推送,是通過蘋果APNS服務(wù)器,推送給手機(jī),手機(jī)在推送給具體的哪個(gè)程序,一般遠(yuǎn)程推送用到的比較多。
在iOS8之后,以前的本地推送寫法可能會(huì)出錯(cuò),接收不到推送的信息,
如果出現(xiàn)以下信息:
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下沒有注冊,所以需要額外添加對(duì)IOS8的注冊方法,API中有下面這個(gè)方法:
// Registering UIUserNotificationSettings more than once results in previous settings being overwritten.
-?(void)registerUserNotificationSettings:(UIUserNotificationSettings*)notificationSettings?NS_AVAILABLE_IOS(8_0);
第一步:創(chuàng)建本地推送

第二步:接收本地推送

第三步:解除本地推送


過程中可能會(huì)出現(xiàn)如下狀況:
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
可能是因?yàn)槟銢]有注冊,或者設(shè)置中沒有開啟推送功能