首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >推送通知在iOS 9中不起作用

推送通知在iOS 9中不起作用
EN

Stack Overflow用户
提问于 2015-09-22 13:30:59
回答 5查看 12.9K关注 0票数 14

我已经将我的设备升级到iOS 9,Xcode环境升级到7.0测试版。推送通知在iOS 9中不起作用?

这是我的代码:

代码语言:javascript
复制
  float ver = [[[UIDevice currentDevice] systemVersion] floatValue];

    if(ver >= 8 && ver<9)
    {
        if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)])
        {
            [[UIApplication sharedApplication] registerForRemoteNotifications];
            UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert) categories:nil];
            [[UIApplication sharedApplication] registerUserNotificationSettings:settings];

        }
    }else if (ver >=9){

        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];

        [[UIApplication sharedApplication] registerForRemoteNotifications];


    }
    else{
        //iOS6 and iOS7 specific code
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeAlert];
    }

Push通知在用Xcode 6.4构建的iOS 8到8.3上运行良好。

EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2016-07-21 15:37:36

在项目中添加code并创建证书和Ad配置文件-

*Just enable this from your X-code*

有关更多细节- iOS 9推送通知

票数 5
EN

Stack Overflow用户

发布于 2015-10-07 03:13:21

我也遇到了同样的问题。我通过创建一个Ad配置文件来解决这个问题。我注意到当我使用开发配置文件时,没有发生推送。我注意到的另一件事是,每次新安装时,设备令牌都会被更改,这有点奇怪,因为我们必须更新每个新实例的服务器。

为了获得更好的理解,您可以阅读本文:iOS 9推送通知

票数 -1
EN

Stack Overflow用户

发布于 2015-11-06 12:13:04

用didFinishLaunchingWithOptions编写这段代码

代码语言:javascript
复制
 UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
                                                UIUserNotificationTypeBadge |
                                                UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
                                                                         categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];

并将此方法添加到AppDelegate中,因为我已用于解析推送通知服务。

代码语言:javascript
复制
 - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
  // Store the deviceToken in the current installation and save it to Parse.
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation setDeviceTokenFromData:deviceToken];
currentInstallation.channels = @[ @"global" ];
[currentInstallation saveInBackground];
}
票数 -2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32718273

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档