IOS unregisterForRemoteNotifications 在飞行模式下不起作用 [英] IOS unregisterForRemoteNotifications does not work in airplane mode

查看:53
本文介绍了IOS unregisterForRemoteNotifications 在飞行模式下不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中的一项功能是在用户从应用程序注销时从远程推送通知中注销用户.当设备处于飞行(离线)模式时用户注销时,我是否可以从推送通知中取消注册应用程序?

One of the feature in my app is to unregister user from the remote pushnotification when user logs-out from the app. Is there way I can unregister the app from push notification when user logs out while the device is in airplane(offline) mode?

我尝试了此代码,但当我重新上线时仍然收到通知,[[UIApplication sharedApplication] unregisterForRemoteNotifications];

I tried this code but I still receive notifications when I come back online, [[UIApplication sharedApplication] unregisterForRemoteNotifications];

当设备处于飞行模式时,有人可以帮助如何从通知中心删除应用程序吗?

Could some one help how to remove app from notification center when the device is in airplane mode?

推荐答案

Apple 控制远程推送通知.如果您处于离线状态,您在逻辑上无法禁用它.当 Apple 第一次在网上看到你并且推送没有被禁用时,它会向你发送推送.没有办法阻止 iDevice 显示苹果发送给用户的推送,因为它不在应用程序的手中.

Apple controls remote push notifications. If you are offline you logically cannot disable it. When Apple first sees you online and pushes are not disabled, it will send you pushes. There is no way to stop the iDevice from showing the pushes that apple sends to the user, as it is not in the hands of the app.

所以只有一种可能性:您必须在设备再次上线后立即禁用推送.这仍然是一个运气问题,苹果首先获得什么消息,你在线还是你禁用推送.还有一个问题,Apple 想要在设备离线时发送到设备的通知会发生什么.它会在在线时重新发送它们还是在首先禁用时丢弃它们?我不知道.你需要做研究.

So there is only one possibility: You have to disable the pushes IMMEDIATELY after the device went online again. And still it is a question of luck, what message Apple obtains first, that you are online or that you disable push. And also there is the question, what will happen to the notifications that Apple wanted to send to the device while it was offline. Will it resend them anyway when online or discard them when disabling first? I don't know. You'll need to do the research.

因此,您唯一的机会是您的应用是否在用户上网时处于后台.您需要防止您的应用程序被暂停 (这里是 如何实现这一点)以便能够响应系统通知.您需要的通知是在线状态更改的通知,我只知道它存在.此资源可能会有所帮助.因此,当设备上线时,它会通知您的应用程序在后台等待(未暂停).然后您可以立即取消注册 frm 远程推送来做出反应.

So the only chance you have is if your app is in the background while the user goes online. You'll need to prevent your app from getting suspended (here's how to achieve that) in order to be able to respond to system notifications. The notification that you need is that of change of online status, I only know it exists. This resource may be helpful. When the device goes online it therefore will notify your app which waits in the background (not suspended). Then you can react by unregistering frm remote pushes immediately.

这是您在这个方向上可能取得的最好成绩.希望这会有所帮助.

That's the best you possibly could achieve in that direction. Hope this helps.

这篇关于IOS unregisterForRemoteNotifications 在飞行模式下不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆