Search code examples
xamarin.formsxamarin.iosnotificationsapple-push-notificationsdevicetoken

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


After installing our app we ask the user for permission to send them notifications. If they accept all works well and we get a devicetoken etc. My question is when the user initially declines the permission request, so RegisteredForRemoteNotifications won't be called and we won't get a devicetoken. Which is understandable because he declined. BUT if the user then manually turns on the notifications in the device settings, when will there be a devicetoken generated? I haven't been able to request the permission again, it won't show the request dialog and permission granted is automatically set to false.

I know how to check if the system notification permissions are granted, but I need the devicetoken to be set. Can anyone explain how this would work?


Solution

  • From the 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.

    You get the token from RegisteredForRemoteNotifications method and this method will be called at launch time.

    Another point you need to know is that when a user change permission manually in settings, your app will manually restart by iOS system.

    So after user changed the setting, the app will relaunch and then get the device token.