tags:

views:

1435

answers:

6

I have been simply trying to get deviceToken from my iPhone application using Apple Push Notification Service. I don't have any implementation on server side for the time being. I have created APP Id, got SSL certificate, Provision Profile with APN and calling

- (void)applicationDidFinishLaunching:(UIApplication *)application {
//view init and add sub view to window
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound];
}

method. When I execute the application it pop ups action box to allow Push Notification (means my request for APN registration is working) but my callback is not executed. Neither didRegisterForRemoteNotificationsWithDeviceToken nor didFailToRegisterForRemoteNotificationsWithError is called? can anybody help me to resolve the issue? Following are my callbacs for reference.

    - (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {

            UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"APNClient" message:@"Entered into Error Method" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [myAlert show];
            [myAlert release];
            NSLog(@"Error in registration. Error: %@", err);

        }
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
    UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"APNClient" message:@"Got the deviceToken..!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [myAlert show];
    [myAlert release];        
}
+1  A: 

The app should be using:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

not

- (void)applicationDidFinishLaunching:(UIApplication *)application
zaph
zaph,Thanks for your answer. But Apple document clearly says that - applicationdidFinishLaunchingWithOptions will be used when you are working with message reception. I am yet trying to get deviceToken first.
cooliPhoneGuy
The Apple dpcumentations states: It is recommended that you implement this method instead of applicationDidFinishLaunching:.
zaph
A: 

The callbacks seem fine, as you say you should get a callback shortly after making the registration call (from anywhere).

This seems like a dumb question, but just to be sure - you delegate methods are in the application delegate class?

If so, I just can't see why your methods would not be called. I see the NSLog statements there, but have you tried actually setting a breakpoint on entry? And you are testing on the device, not the simulator, right?

Kendall Helmstetter Gelner
A: 

Thanks for your answers. Finally, I found the solution. Code and everything else is correct except you must have Good iPhone Device :)

cooliPhoneGuy
A: 

Shailesh, can you explain the problem with your device?

I'm having the same problem as you, and it actually worked fine until my phone crashed.

A: 

What you mena : Good iPhone Device

What is that?

DevOI
A: 

I think he said "Good iphone device" is not jailbroken's iphone ! I'm a chinese program , if you are some question , you can contract me [email protected] , my msn : [email protected] . thank !

nick xu