IOS8 PUSH解决方法
registerForRemoteNotificationTypes:?is?not?supported?in?iOS?8.0?and?later???
IOS8?PUSH解決方法
昨天晚上整理PUSH的東西,準備些一個教程,全部弄好之后,發(fā)現(xiàn)沒有達到預期的效果,本以為是服務(wù)器代碼的問題(因為本人對PHP代碼一點都不懂),所以在網(wǎng)上四處搜索,后來看xcode?log才發(fā)現(xiàn),原來是IOS8系統(tǒng)更新了的問題,提示?registerForRemoteNotificationTypes:?is?not?supported?in?iOS?8.0?and?later.
使用IOS8?xcode6的同學,在使用推送(push)的時候應該已經(jīng)出現(xiàn)這個問題了。那么讓我們來看看具體的解決方法。
iOS?8?has?changed?notification?registration?in?a?non-backwards?compatible?way.?While?you?need?to?support?iOS?7?and?8?(and?while?apps?built?with?the?8?SDK?aren't?accepted),?you?can?check?for?the?selectors?you?need?and?conditionally?call?them?correctly?for?the?running?version.
Here's?a?category?on?UIApplication?that?will?hide?this?logic?behind?a?clean?interface?for?you?that?will?work?in?both?Xcode?5?and?Xcode?6.
//?IOS8?新系統(tǒng)需要使用新的代碼咯
if?([[[UIDevice?currentDevice]?systemVersion]?floatValue]?>=?8.0)
{
????[[UIApplication?sharedApplication]?registerUserNotificationSettings:[UIUserNotificationSettings?
?????settingsForTypes:(UIUserNotificationTypeSound?|?UIUserNotificationTypeAlert?|?UIUserNotificationTypeBadge)??????
categories:nil]];
????[[UIApplication?sharedApplication]?registerForRemoteNotifications];
}
else
{
//這里還是原來的代碼
????[[UIApplication?sharedApplication]?registerForRemoteNotificationTypes:
?????(UIUserNotificationTypeBadge?|?UIUserNotificationTypeSound?|?UIUserNotificationTypeAlert)];
}
原本在IOS7當中?判斷PUSH是否打開的方法是:
UIRemoteNotificationType?types?=?[[UIApplication?sharedApplication]?enabledRemoteNotificationTypes];
return?(types?&?UIRemoteNotificationTypeAlert);
如果將這段代碼使用在?IOS當中,雖然不會出現(xiàn)crash的現(xiàn)象,但是基本沒什么作用。
在IOS8中,我們使用如下的新代碼來取代以上的代碼
{
UIRemoteNotificationType?types;
if?([[[UIDevice?currentDevice]?systemVersion]?floatValue]?>=?8.0)
???{
?types?=?[[UIApplication?sharedApplication]?currentUserNotificationSettings].types;
????}
else
???{
?types?=?[[UIApplication?sharedApplication]?enabledRemoteNotificationTypes];
????}
return?(types?&?UIRemoteNotificationTypeAlert);
}
轉(zhuǎn)載于:https://www.cnblogs.com/zyingn/p/XcodePush.html
總結(jié)
以上是生活随笔為你收集整理的IOS8 PUSH解决方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2016-2017 ACM-ICPC P
- 下一篇: shell脚本监控系统负载、CPU和内存