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

Push notification 推送通知在iOS 9中不起作用,push-notification,apple-push-notifications,ios9,xcode7,Push Notification,Apple Push Notifications,Ios9,Xcode7,我已将设备升级到iOS 9,将Xcode环境升级到7.0 贝塔。推送通知在iOS 9中不起作用 这是我的密码: float ver = [[[UIDevice currentDevice] systemVersion] floatValue]; if(ver >= 8 && ver<9) { if ([[UIApplication sharedApplication] respondsToSelector:@selector(re

我已将设备升级到iOS 9,将Xcode环境升级到7.0 贝塔。推送通知在iOS 9中不起作用

这是我的密码:

  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];
    }
float-ver=[[UIDevice-currentDevice]systemVersion]floatValue];
如果(版本>=8&&V=9){
[[UIApplication sharedApplication]registerUserNotificationSettings:[UIUserNotificationSettings设置类型:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge)类别:nil];
[[UIApplication sharedApplication]注册表项的删除];
}
否则{
//iOS6和iOS7特定代码
[[UIApplication sharedApplication]RegisterForremoteNotificationTypeBadge:UIRemoteNotificationTypeAlert];
}

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

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

您可以阅读本文以更好地理解:

在didFinishLaunchingWithOptions中编写此代码

 UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
                                                UIUserNotificationTypeBadge |
                                                UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
                                                                         categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];
并将此方法添加到AppDelegate,就像我用于解析推送通知服务一样

 - (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];
}

请尝试此代码,因为它适用于我的IOS 9应用程序

在AppDelegate DidFinishLaunchWithOption中编写代码

if([[UIApplication sharedApplication] respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
{
    [[UIApplication sharedApplication] registerUserNotificationSettings:  [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound) categories:nil]];

    [[UIApplication sharedApplication] registerForRemoteNotifications];
}
else
{
   #if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_8_0
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIUserNotificationTypeAlert | UIUserNotificationTypeBadge |    UIUserNotificationTypeSound)]; #endif
}
if([[UIApplication sharedApplication]respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
{
[[UIApplication sharedApplication]registerUserNotificationSettings:[UIUserNotificationSettings设置类型:(UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound)类别:无];
[[UIApplication sharedApplication]注册表项的删除];
}
其他的
{
#如果需要IPHONE操作系统版本最低版本<\uU IPHONE 8\u 0
[[UIApplication sharedApplication]注册表项更改通知类型:(UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound)];#endif
}
确保在服务器上仔细检查了以下项目的推送通知

  • 通过从发起人处选择证书和私钥生成的PEM文件
  • 已启用Apple服务并正确指向沙盒/Live
  • 在下面的函数中接收推送通知令牌,并且不会返回任何错误,这些错误会被发送到向设备令牌发送APNS推送通知的服务器(LAMP服务)
  • 通过推送发送到令牌,检查服务器中的Apple APNS响应代码
  • 在设置中启用推送通知,就像您在“|”符号代码中做了任何错误一样,您可能会看到Apple常规通知设置中未显示的声音、徽章选项

    -(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
        {
            NSString *devicetokenString = [[[[deviceToken description] stringByReplacingOccurrencesOfString: @"<" withString: @""] stringByReplacingOccurrencesOfString: @">" withString: @""] stringByReplacingOccurrencesOfString: @" " withString: @""]; 
    
            DLog(@"Did Register for Remote Notifications with Device Token DATA (%@) \n STRING token (%@)", deviceToken,devicetokenString);
    
            //If Same token received again dont take any action else save in NSUserdefaults or system and send to server to register against this device to send push notification on the token specified here.
        }
    
    -(void)application:(UIApplication *)application    didFailToRegisterForRemoteNotificationsWithError:(NSError *)error 
        {
            DLog(@"Did Fail to Register for Remote Notifications");
            DLog(@"%s:%@, %@",__PRETTY_FUNCTION__,error, error.localizedDescription);
        }
    
    -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
        {
            DLog(@"Did Receive for Remote Notifications with UserInfo:%@", userInfo);
        }
    
    -(void)应用程序:(UIApplication*)应用程序DIDregisterforRemotionTificationswithDeviceToken:(NSData*)deviceToken
    {
    NSString*DeviceTokennstring=[[[[deviceToken description]StringByReplacingOccurrencessOfString:@”“with String:@”“]stringByReplacingOccurrencesOfString:@”“with String:@”“];
    DLog(@“未使用设备令牌数据(%@)\n字符串令牌(%@)”注册远程通知,deviceToken,DeviceTokennstring);
    //如果再次收到相同的令牌,请不要采取任何其他操作保存在NSUserdefaults或system中,并发送到服务器以注册此设备,以发送此处指定令牌的推送通知。
    }
    -(无效)应用程序:(UIApplication*)应用程序未能注册远程通知,错误为:(N错误*)错误
    {
    DLog(@“未注册远程通知”);
    DLog(@“%s:%@,%@”,“函数”,错误,错误。本地化描述);
    }
    -(无效)应用程序:(UIApplication*)应用程序DidReceiveMemotentification:(NSDictionary*)用户信息
    {
    DLog(@“确实收到了用户信息为%@”的远程通知,用户信息);
    }
    

  • 如果有任何帮助发布您的更新代码,希望我们能很好地解释这一点,以便我们能够帮助您。

    如果您使用Diawi安装应用程序,则推送通知在IOS 9中不起作用


    在项目中添加
    代码并创建证书和特别配置文件后,您可以通过Xcode..

    安装应用程序-

    *只需从您的X-code*启用此功能


    有关更多详细信息-

    我遇到了相同的问题。请告诉我您是否找到了解决方案有人找到了解决方案吗?我遇到了相同的问题。我也遇到了相同的问题。我遇到了相同的问题,推送通知对我有效,即使在iOS 9和xcode 7上,上周我升级到El Capitan和xcode 7.1 and iOS 9.1,然后它们停止工作,我只测试了我的开发环境,但将测试其他环境。如果有人有任何想法,请尽快为此需要解决方案。我已尝试使用Ray的教程重新生成证书,该教程一直有效,但这一次我确实知道设备令牌在新安装时不断变化。这很简单不是问题。我每次登录时都会发送设备\u令牌。你尝试过使用临时配置文件吗?对我来说,开发和分发证书似乎都在工作。是的。我已经尝试过了。正如我上面提到的,你知道通知在使用相同配置文件的iOS 8上工作,但在iOS 9上不工作。@chandresh:不,我不是通过Diawi安装的。我正在安装iOS 9使用Diawi和推送通知的应用程序运行良好。在项目从swift 2升级到3后,我遇到了这种情况。令人恼火的是-(void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)不管怎样,deviceToken仍然被调用-除非选中此选项,否则您不会收到通知。是吗