本文转载至 http://blog.csdn.net/pjk1129/article/details/39548523
 
 

- (void)registerForRemoteNotificationTypes:(UIRemoteNotificationType)types NS_DEPRECATED_IOS(3_0, 8_0, "Please use registerForRemoteNotifications and registerUserNotificationSettings: instead")

昨天晚上整理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  转载请注明!!

iOS8 PUSH解决方法的更多相关文章

  1. UITableViewCell点击不能push解决方法

    一般情况下不能push是因为当前控制器没有导航控制器,造成不能push的情况. 解决方法如下: - (void)tableView:(UITableView *)tableView didSelect ...

  2. git rebase与 git合并(error: failed to push some refs to)解决方法

    1.遇到的问题 本地有一个git仓库,在github上新建了一个空的仓库,但是更新了REWADME.md的信息,即在github上多了一个提交. 关联远程仓库,操作顺序如下: git remote a ...

  3. jenkins在windows服务器上执行含git push命令的脚本权限不足的解决方法

    错误摘要 默认情况下执行脚本是没问题的,但是脚本中含有git push命令就无法执行了 用jenkins部署hexo博客时候遇到的,执行hexo d -g一直阻塞至Build was aborted, ...

  4. 〖Linux〗git push orgin master不能解析域名的解决方法

    错误信息: $ git push origin master ssh: Could not resolve hostname bitbucket.org: Name or service not kn ...

  5. push到github报错解决方法

    在push代码到远程仓库时,报了如下的错误: $ git push -u origin master To https://github.com/11pdg/group-buy.git ! [reje ...

  6. 页面跳转问题,多次 push 到新的页面的问题的解决方法

    今日在做一个扫一扫的功能,突然发现多次点击了扫一扫的图片后,造成多次触发轻拍手势,就多次push到新的页面,本想在轻拍手势内对push的进行拦截,但是又觉得如果有好多的地方都要实现对该问题的解决岂不是 ...

  7. [git push] rejecteded 问题的解决方法

    错误信息: hint: Updates were rejected because a pushed branch tip is behind its remote hint: counterpart ...

  8. Missing Push Notification Entitlement解决方法

    原委 最近提交APP到Apple Store审核,结果很快就收到Apple很"贴心"的邮件.原文如下: Dear developer, We have discovered one ...

  9. git push的时候.gitignore不起作用的解决方法

    问题的原因 这是因为在你添加.gitignore之前已经进行过push操作,有些文件已经纳入版本管理了. 解决方法 我们就应该先把本地缓存删除,然后再进行git的push,这样就不会出现忽略的文件了. ...

随机推荐

  1. hdu 1558 线段相交+并查集路径压缩

    Segment set Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  2. Linux System Programming 学习笔记(二) 文件I/O

    1.每个Linux进程都有一个最大打开文件数,默认情况下,最大值是1024 文件描述符不仅可以引用普通文件,也可以引用套接字socket,目录,管道(everything is a file) 默认情 ...

  3. 【MFC】Button控件和Picture Control的鼠标事件执行顺序

    1.Button控件鼠标事件执行顺序 (1) WM_LBUTTONDOWN (2) WM_LBUTTONUP (3) OnBnClickedButton1(); 2.Picture Control的鼠 ...

  4. ES6 的Object.assign(target, source_1, ···)方法与对象的扩展运算符

    一.基本概念 Object.assign方法用来将源对象(source)的所有可枚举属性,复制到目标对象(target).它至少需要两个对象作为参数,第一个参数是目标对象,后面的参数都是源对象. Ob ...

  5. 洛谷——P3252 [JLOI2012]树

    P3252 [JLOI2012]树 题目描述 在这个问题中,给定一个值S和一棵树.在树的每个节点有一个正整数,问有多少条路径的节点总和达到S.路径中节点的深度必须是升序的.假设节点1是根节点,根的深度 ...

  6. CentOS6.7源码安装MySQL5.6

    1.源码安装MySQL5.6 # CentOS6操作系统安装完成后,默认会在/etc目录下存在一个my.cnf, # 强制卸载了mysql-libs之后,my.cnf就会消失 rpm -qa | gr ...

  7. HDU 2460 Network 傻逼Tarjan

    Network Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  8. 笔记-迎难而上之Java基础进阶4

    内部类创建多线程 //匿名内部类创建多线程 public class InnerClassThread{ public static void main(String[] args){ //回忆一下之 ...

  9. Java集合——概述

    Java集合——概述 摘要:本文主要介绍了几种集合类型以及有关的一些知识点. 集合类图 类图 类图说明 所有集合类都位于java.util包下.Java的集合类主要由两个接口派生而出:Collecti ...

  10. react/redux组件库、模板、学习教程

    开源的有蚂蚁金服的: 1.https://pro.ant.design/index-cn 2.https://pro.ant.design/docs/getting-started-cn 3.http ...