0

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

asked Sep 29, 2015 at 11:09
4
  • Follow this code.tutsplus.com/tutorials/… Commented Sep 29, 2015 at 11:11
  • I followed as a the above tutorial , but still not able to get the device token , but it was asking for the push notification allow confirmation , the very first time, Commented Sep 29, 2015 at 11:15
  • -(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { NSLog(@"Failed to get token, error: %@",error); } Use this code and let me know what is the error Commented Sep 29, 2015 at 11:17
  • @baydi I'm "didFailToRegisterNotificationWithError" also Not triggered Commented Sep 29, 2015 at 13:38

2 Answers 2

1

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.

answered Sep 29, 2015 at 11:34
Sign up to request clarification or add additional context in comments.

Comments

0

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.

answered Sep 29, 2015 at 11:17

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.