Push-уведомления не работают в iOS 9

Я обновил свои устройства до iOS 9 и моей среды Xcode до 7.0 бета. Push-уведомления не работают в 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];
    }

Push-уведомления работают отлично на iOS 8 до 8.3, созданных с помощью Xcode 6.4.

Ответы

Ответ 1

После добавления code в проект и создания сертификата и профиля Ad-Hoc -

*Just enable this from your X-code*

введите описание изображения здесь

для более подробной информации - iOS 9 Push Notification Tutoriyal

Ответ 2

Я столкнулся с той же проблемой. Я решил это, создав Ad-Hoc Profile. Я заметил, что push не происходит, когда я использую профиль разработки. И еще одна вещь, которую я заметил, - это токен устройства, который изменяется для каждой новой установки, которая является довольно странной, поскольку мы должны обновлять сервер для каждого нового экземпляра.

Вы можете прочитать эту статью для лучшего понимания: iOS 9 Push Notifications

Ответ 3

напишите этот код в файле didFinishLaunchingWithOptions

 UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
                                                UIUserNotificationTypeBadge |
                                                UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
                                                                         categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];

и добавьте этот метод в AppDelegate, как я использовал для службы разметки push-сообщений

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

Ответ 4

Пожалуйста, попробуйте использовать этот код для моего приложения 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
}

Убедитесь, что следующие элементы хорошо проверены для уведомления Push на сервере

  • Файл PEM, созданный при выборе ключа Cert и Private от создателя
  • Служба Apple включена и правильно указана на песочницу /Live.
  • Push-токен Push получен в нижней функции и не возвращается ошибка, которая хорошо отправляется на сервер (служба LAMP), которая отправляет уведомление APNS Push на токен устройства.
  • Проверьте код ответа Apple APNS на сервере с Push-отправкой на токен.
  • Включено Push-уведомление в настройках, как если бы вы делали какие-либо ошибки в '|' код символа, вы можете увидеть звук, параметры значка, которые не показаны в настройках Apple General Notification

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

Надеюсь, это будет хорошо объяснено, если какая-либо помощь сделает ваш обновленный код, чтобы мы могли вам помочь.

Ответ 5

Если вы используете Diawi для установки приложения, чем push-уведомление, не работающее в IOS 9..

Вы устанавливаете приложение, хотя Xcode..