简体   繁体   中英

iOS Push notification Not working

I have to implement push notification service to my application, So i had created App ID with push notification enabled in production. there very first time when install the application in my device the push notification allow and don't allow pop-up comes and if it click all . it is not generating the push notification. next next time when i launched it won't ask for any pop up and i'm not able to generate device token, Please help me in this.

Thanks, Nikhil.CH

First of all, Once you have responded to Push Notifications Permissions Alert details gets saved. To reset that and experience the alert once again follow these steps:

  1. Delete your app from the device.

  2. Turn the device off completely and turn it back on.

  3. Go to Settings > General > Date & Time and set the date ahead a day or more.

  4. Turn the device off completely again and turn it back on.

Now, here is step by step process on registering to push notification on iOS app:

Step 1: Ask iOS Push Notification settings on device for the app:

if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) {
    [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIRemoteNotificationTypeSound|UIRemoteNotificationTypeAlert) categories:nil]];
} else {
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeSound];
}

Step 2: Register for notification on the delegate call back from above method call

- (void)application:(UIApplication *)iApplication didRegisterUserNotificationSettings:(UIUserNotificationSettings *)iNotificationSettings {
    [iApplication registerForRemoteNotifications];
}

Step 3: Implement following methods to receive and save the token called from above method

- (void)application:(UIApplication *)iApplication didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)iDeviceToken
- (void)application:(UIApplication *)iApplication didFailToRegisterForRemoteNotificationsWithError:(NSError *)iError

If you are not getting push token then error method didFailToRegisterForRemoteNotificationsWithError must give you some useful information.

First you need to be sure that you are getting the token or an error after displaying the "allow" popup. Methods to register notification had a breaking change in iOS8, and if you use old one it will fail silently.
Here a snippet:

 if ([application respondsToSelector:@selector(registerUserNotificationSettings:)])
{
        // iOS 8
        [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
}
else{
//.. the old one
}


Most of time that something fails can be due to wrong prov profiles and certificates matching, or because you are testing behind a firewall or VPN.
To test them I use PUSHER a wonderful software.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM