2

i am not getting into the method

didRegisterForRemoteNotificationsWithDeviceToken

Actually i want to get device token and i have tried to follow this question Get Device Token in iOS 8 but still facing the same problem .Help me to come out of this problem

Community
  • 1
  • 1
  • 1
    describe your problems???what problem you are facing? – Bhavin Bhadani Aug 31 '15 at 08:41
  • 2
    What is the error in [didFailToRegisterForRemoteNotificationsWithError](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/index.html#//apple_ref/occ/intfm/UIApplicationDelegate/application:didFailToRegisterForRemoteNotificationsWithError:)? – dasdom Aug 31 '15 at 08:41
  • Are you running on the simulator or a real device? – Paulw11 Aug 31 '15 at 08:48
  • i am running on real device.i am also not getting in to didFailToRegisterForRemoteNotificationsWithError method too.but if i run the app in simulator then it will go to didFailToRegister method.. – Mehmood Hassan Aug 31 '15 at 08:55

3 Answers3

4

Try this.

In your method.

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

use this code

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
    {
        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];

        [[UIApplication sharedApplication] registerForRemoteNotifications];
    }
    else
    {
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeNewsstandContentAvailability| UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
    }

And then Put log or breakpoints that your

didRegisterForRemoteNotificationsWithDeviceToken

get called or not.

And if your app is properly registered for remote-notification settings and yet you are not getting device token then

check

didFailToRegisterForRemoteNotificationsWithError

method that will tell you which error you have.

NOTE : device-token will return only when you run on device. OS Simulator doesn't support push notifications

And then also if you are not able to get this method called, then check out this tutorial

http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1

And follow the steps for creating provisioning profile and certificates. I tried with my existing certificate. After you run your app with valid profile as explained in this tutorial series, you will able to get that method called.

Wolverine
  • 4,264
  • 1
  • 27
  • 49
  • I have used this code and i have placed breakpoint on both methods didFail and didRegister but unfortunately app not stoping at break points and not log device token . – Mehmood Hassan Aug 31 '15 at 09:02
  • Delete the app from device. And run again by clearing window+shift+k. and check is there any alert prompt like "app name would like to use remote notifications..." ? – Wolverine Aug 31 '15 at 09:08
  • click ok. and then retry it. that method should call now. – Wolverine Aug 31 '15 at 09:17
  • That is the problem that even after this prompt when i run app again it is not entering in to these both methods – Mehmood Hassan Aug 31 '15 at 09:27
  • I will update the answer. you need to create the proper development provisioning profile for that. – Wolverine Aug 31 '15 at 10:27
0

There are different way to get device token in iOS 8.

if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) {

        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
        [[UIApplication sharedApplication] registerForRemoteNotifications];
    }
    else{
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound];
    }
Maksud Ali
  • 121
  • 4
0

The problem was that there is some kind of restriction in my company network so when i used a wifi device which was not on company network my code worked fine.

  • Great if that works for you..but till i know. if is there any restriction from network side then your URL may not get called or a problem will come related to something which is related to network connection. if your method is not getting called for getting device token that it can be other problems. Anyways good luck.. – Wolverine Sep 01 '15 at 07:22
  • Thank u dear for your support. – Mehmood Hassan Sep 01 '15 at 08:00