如果您第一次选择“否”,则 PushNotification 会出现问题

发布于 2024-09-12 21:12:43 字数 737 浏览 2 评论 0原文

正如我在该主题的标题中所说,我的应用程序的推送通知存在问题。 有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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暗藏城府 2024-09-19 21:12:43

我看到您在以下位置注册远程通知:

- (void)applicationDidFinishLaunching:(UIApplication *)application

如果您的应用程序在支持多任务的 iOS 设备上运行,那么这可能不是正确的位置。

当您最初从冷状态启动应用程序时,将调用上述方法。这是当系统提示您接受或拒绝推送通知时 - 根据您的情况,请拒绝。

当您稍后退出应用程序以更改设备范围控制面板中的设置时,应用程序不会退出 - 它只是退出前台应用程序。当您在控制面板中启用推送通知并返回到应用程序时,应用程序不会再次启动,而是从后台移至前台。

您的应用程序委托此时将收到:

- (void) applicationDidBecomeActive:(UIApplication *)application

尝试在那里注册推送通知,而不是使用:

- (void)registerForRemoteNotificationTypes:(UIRemoteNotificationType)types

您还可以通过在应用程序的 Info.plist 文件 (UIApplicationExitsOnSuspend) 中设置“应用程序不在后台运行”属性来防止后台运行。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文