Xamarin.Forms - iOS - 如果用户拒绝通知权限,然后在设置中手动更改,我如何获得 devicetoken?

Xamarin.Forms - iOS - If user declines notification permission and then changes manually in settings, how do I get the devicetoken?

安装我们的应用程序后,我们会请求用户允许向他们发送通知。如果他们接受一切正常,我们就会得到设备令牌等。 我的问题是当用户最初拒绝权限请求时,因此不会调用 RegisteredForRemoteNotifications,我们也不会获得设备令牌。这是可以理解的,因为他拒绝了。 但是如果用户然后手动打开设备设置中的通知,什么时候会生成设备令牌?我一直无法再次请求权限,它不会显示请求对话框并且授予的权限自动设置为 false。

我知道如何检查系统通知权限是否被授予,但我需要设置devicetoken。谁能解释一下这是如何工作的?

来自document

In iOS and tvOS, you initiate APNs registration for your app by calling the registerForRemoteNotifications method of the UIApplication object. Call this method at launch time as part of your normal startup sequence.

您从 RegisteredForRemoteNotifications 方法获取令牌,此方法将在启动时调用。

还有一点您需要知道的是,当用户在设置中手动更改权限时,您的应用将由iOS系统手动重启

所以在用户更改设置后,应用程序将重新启动,然后获取设备令牌。