如果您第一次选择“否”,则 PushNotification 会出现问题
正如我在该主题的标题中所说,我的应用程序的推送通知存在问题。 有2种情况: 当应用程序询问您是否需要推送通知并按下“确定”时,它运行良好。
此函数:
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken
在调用 registerForRemoteNotificationTypes 时调用:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Add registration for remote notifications
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
...
}
但是当您在开始时选择“否”,然后更改设置以接受推送通知时,不会添加任何内容,并且永远不会调用此函数 didRegisterForRemoteNotificationsWithDeviceToken。
请帮助我,我快疯了!
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 sharedApplication] 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我看到您在以下位置注册远程通知:
如果您的应用程序在支持多任务的 iOS 设备上运行,那么这可能不是正确的位置。
当您最初从冷状态启动应用程序时,将调用上述方法。这是当系统提示您接受或拒绝推送通知时 - 根据您的情况,请拒绝。
当您稍后退出应用程序以更改设备范围控制面板中的设置时,应用程序不会退出 - 它只是退出前台应用程序。当您在控制面板中启用推送通知并返回到应用程序时,应用程序不会再次启动,而是从后台移至前台。
您的应用程序委托此时将收到:
尝试在那里注册推送通知,而不是使用:
您还可以通过在应用程序的 Info.plist 文件 (UIApplicationExitsOnSuspend) 中设置“应用程序不在后台运行”属性来防止后台运行。
I see you register for remote notifications in:
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:
try registering for Push Notifications there instead using:
You could also prevent backgrounding by setting the “Application does not run in background” property in the application’s Info.plist file (UIApplicationExitsOnSuspend).