本文转载至 http://bbs.csdn.net/topics/390889517

IOS8 PUSH解决方法

昨天晚上整理PUSH的东西,准备些一个教程,全部弄好之后,发现没有达到预期的效果,本以为是服务器代码的问题(因为本人对PHP代码一点都不懂),所以在网上四处搜索,后来看xcode log才发现,原来是IOS8系统更新了的问题,提示 registerForRemoteNotificationTypes: is not supported in iOS 8.0 and later.

使用IOS8 xcode6的同学,在使用推送(push)的时候应该已经出现这个问题了。那么让我们来看看具体的解决方法。

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 新系统需要使用新的代码咯
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当中,虽然不会出现crash的现象,但是基本没什么作用。
在IOS8中,我们使用如下的新代码来取代以上的代码

{
UIRemoteNotificationType types;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
   {
 types = [[UIApplication sharedApplication] currentUserNotificationSettings].types;
    }
else
   {
 types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
    }

return (types & UIRemoteNotificationTypeAlert);
}

每当苹果更新一个新的版本的时候,最痛苦的莫过于我们这群屌丝啊
加油码农!
本文转自  http://www.999dh.net/home.php?mod=space&uid=1&do=blog&quickforward=1&id=419  转载请注明!!

registerForRemoteNotificationTypes: is not supported in iOS 8.0 and later的更多相关文章

  1. registerForRemoteNotificationTypes: is not supported in iOS 8.0 and

    注册模式: if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) { [[UIApplication sharedA ...

  2. iOS iOS8中 问题"registerForRemoteNotificationTypes: is not supported in iOS 8.0 and later" 解决方式

    问题重述: iOS 8中改变了通知注冊的方式,假设App须要同一时候支持iOS 7 和 8 的话,须要首先检查selector. 解决方式:在Xcode 6中 - (BOOL)application: ...

  3. embedded dylibs/frameworks are only supported on iOS 8.0 and later 错误解决

    ld: warning: embedded dylibs/frameworks only run on iOS 8 or later ld: embedded dylibs/frameworks ar ...

  4. iOS开发Embedded dylibs/frameworks are only supported on iOS 8.0 and later for architecture armv7的解决方法

    全局搜索IPHONEOS_DEPLOYMENT_TARGE改为更小的版本

  5. iOS 10.0 更新点(开发者视角)

    html, body {overflow-x: initial !important;}html { font-size: 14px; } body { margin: 0px; padding: 0 ...

  6. HierarchyViewer for iOS 2.0 BETA Introduction

    We know HierarchyViewer is an useful tool in Android SDK. The developer and tester, who haven't the ...

  7. iOS 7.0获取iphone UDID 【转】

    iOS 7.0 iOS 7中苹果再一次无情的封杀mac地址,使用之前的方法获取到的mac地址全部都变成了02:00:00:00:00:00.有问题总的解决啊,于是四处查资料,终于有了思路是否可以使用K ...

  8. iOS 5.0 后UIViewController新增:willMoveToParentViewController和didMoveToParentViewCon[转]

    在iOS 5.0以前,我们在一个UIViewController中这样组织相关的UIView   在以前,一个UIViewController的View可能有很多小的子view.这些子view很多时候 ...

  9. iOS 5.0 后UIViewController新增:willMoveToParentViewController和didMoveToParentViewCon

    在iOS 5.0以前,我们在一个UIViewController中这样组织相关的UIView   在以前,一个UIViewController的View可能有很多小的子view.这些子view很多时候 ...

随机推荐

  1. 开源 project

    移动:http://www.csdn.net/article/2014-04-22/2819435-facebook-mobile-open-source-projects/1

  2. C#精髓第四讲 GridView 72般绝技

    原文发布时间为:2008-08-03 -- 来源于本人的百度文章 [由搬家工具导入] 原文地址:http://blog.csdn.net/21aspnet/archive/2007/03/25/154 ...

  3. 回顾scroll

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. select函数与stdio混用的不良后果 (转)

    出自:http://www.cppblog.com/mysileng/archive/2013/01/15/197284.html 今天在看UNP6.5节,学习到了select与stdio混用的后果. ...

  5. dedecms--二次开发之前后台登录分开

    最近在写dedecms系统下会员功能二次开发,然后发现在本地测试的时候每次登录后台,管理员帐号都会在前台页面也显示登录了,但是如果真的是在前台页面用管理员账号登录的话那是登陆不了的,所以我觉得这样的效 ...

  6. LeetCode OJ——Remove Duplicates from Sorted List

    http://oj.leetcode.com/problems/remove-duplicates-from-sorted-list/ 链表的去重,要考虑链表的本质. #include <ios ...

  7. Toast问题记录:This Toast was not created with Toast.makeText()

    最近使用自己封装的Toast时,遇到一个问题 java.lang.RuntimeException: This Toast was not created with Toast.makeText() ...

  8. 牛客网 Wannafly挑战赛9 A.找一找-数据处理

    好几天没好好学习了(咸鱼晒干了) 把稍微没那么咸鱼的几天前的一场牛客网的比赛稍微看了一下,菜的要死,这一场大数的比较多,都死了. A.找一找 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C ...

  9. bitShark对Android版本的支持

    bitShark对Android版本的支持   bitShark是一款轻量级的Android数据抓包软件.使用该软件,可以随时随地抓取网络中的各种数据包,并进行各项分析.我们推出的bitShark手机 ...

  10. 第三章 poj 1064——关于带精度的二分法

    /* 题意:给定n个实数l[i],给定一个k 问:求最大的ans,使得sum l[i]/ans i=1 to n >=k,且ans最大*/ #include <iostream> # ...