views:

228

answers:

2

I want to use push notification in my app.I have created an unique app id and created push development certificate.also created provisioning profile using that unique app id.I put the code for registering the device in application terminate method so that when my app closed it's enabled push notification and when it launches it disables the push notification.BTW currently i am using ApplicationDidFnishLaunching method and registering for push notification.The app is registered for push notification i think because it asks to allow push notification on alertview.But i've never found device token.The app is not invoking the method.BTW i have written this Method in ApplicationDelegate.

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSLog(@"devToken=%@",deviceToken);
[self alertNotice:@"" withMSG:[NSString stringWithFormat:@"devToken=%@",deviceToken] cancleButtonTitle:NSLocalizedString(@"OK",@"") otherButtonTitle:@""];
}

even i set a breakpoint in this method but it's not invoking. i have iPhone 3GS jailbroken. Anybody knows why i'm not getting devicetoken.

+1  A: 

When you call registerForRemoteNotificationTypes: an asynchronous registration process begins as your app contacts Apple's servers. Your own code proceeds to execute, which means the app will be closed. Most probably, the registration doesn't succeed, but even if it does the process is no longer alive, which means that application:didRegisterForRemoteNotificationsWithDeviceToken: can't be invoked.

Instead of trying to disable notifications every time the app starts, you should simply ignore incoming notifications in application:didReceiveRemoteNotification: You don't have to do anything special when the app closes. It will still be registered to receive notifications, and when the app is not running, the notifications will not be ignored.

Felixyz
Currently I'm trying it in applicationDidFinishLaunching Method but still unable to get device token.
Rahul Vyas
- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*) error{ NSLog(@"Failed to register with error: %@", error);}Copy and paste here if you need more help.
Felixyz
it's jailbroken iPhone issue
Rahul Vyas
A: 

From what I understand, Apple ignores token requests from jailbroken iPhones. I hate to say it, but I think this might be your issue.

Sangraal