Push notifications are not working in iOS 9

前端 未结 5 613
死守一世寂寞
死守一世寂寞 2020-12-31 06:36

I have upgraded my devices to iOS 9 and my Xcode environment to 7.0 beta. Push notifications are not working in iOS 9?

Here is my code:

  float ver =         


        
5条回答
  •  无人及你
    2020-12-31 07:03

    Please try this code as its working for my IOS 9 application

    Write a Code in 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
    }
    

    Make sure the following items are well checked for the Push notification on the server

    1. PEM File generated with selecting the Cert & Private key from the originator
    2. Apple service enabled and pointing to Sandbox/Live correctly
    3. Push notification token is received in below function and not any Error is returned which is well send to the server (LAMP service) that is sending the APNS Push notification to device Token.
    4. Check the Apple APNS response code in the server with the Push send to the token.
    5. Enabled Push notification in the settings as if you do any goof up in the '|' symbol code you may see the sound, badge options not shown in Apple General Notification settings

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

    Hope this is well explained if any help do post your updated code so we can help you.

提交回复
热议问题