开发者

Problem With PushNotification if you select No at the first time

As i said in the title of this thread, I have a problem with Push notification of my application. There is 2 cases : When the app asks you if you want push notification and you push OK, it's working great.

This function :

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken

is called when registerForRemoteNotificationTypes is called :

- (void)applicationDidFinishLaunching:(UIApplication *)application {
    // Add registration for remote notifications
    [[UIApplication sh开发者_运维技巧aredApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
    ...
}

But when you select NO at the beginning, and then you change your settings to accept push notification, nothing append and this function didRegisterForRemoteNotificationsWithDeviceToken is never called.

Please help me, i'm getting crazy!


I see you register for remote notifications in:

- (void)applicationDidFinishLaunching:(UIApplication *)application

If your application is running on a iOS device with support for multitasking that might not be the right place.

The above method is called when you initially launch your app from cold. This is when you are prompted to accept or decline Push Notifications - and in your case decline.

When you later exit the application to change the settings in the device wide control panel the application is not quit - it is merely resigning as the foreground application. When you have enabled Push Notifications in the control panel and return to your application - the application is not launched again but moves from being backgrounded to the foreground.

Your application delegate will at this point receive an:

- (void) applicationDidBecomeActive:(UIApplication *)application

try registering for Push Notifications there instead using:

- (void)registerForRemoteNotificationTypes:(UIRemoteNotificationType)types

You could also prevent backgrounding by setting the “Application does not run in background” property in the application’s Info.plist file (UIApplicationExitsOnSuspend).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜