我的应用程序能够成功注册推送通知,但我想将弹出警报移动到应用程序的其他区域
如果我将AppDelegate.m中的相同代码实现到我的应用程序的另一个屏幕Other.m,它永远不会注册:
-(void)buttonTapped { // Register for Push Notifications UIRemoteNotificationType notifyTypes = (UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge); [[UIApplication sharedApplication] registerForRemoteNotificationTypes:notifyTypes]; } #pragma mark - APNS Functions -(void)application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken { NSLog(@"didRegisterForRemoteNotifications - 1"); } -(void)application:application didFailToRegisterForRemoteNotificationsWithError:error { NSLog(@"didFailToRegisterForRemoteNotifications"); }
如果我在AppDelegate.m中启用didRegisterForRemoteNotificationsWithDeviceToken,则从我的Other.m调用该方法的AppDelegate.m实例,但这不是我想要的方法.
任何想法或建议将不胜感激.
解决方法
当然是.
您可以在任何地方注册使用
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
但didRegisterForRemoteNotificationsWithDeviceToken:deviceToken仅在AppDelegate中可用