Receiving duplicate push notification

Hey,

I have a workflow in my app that explain about the app features, during the workflow a ask fro the user permission for push notification, if the user authorize for push notification I call to this code:


func regusterToPushNotification() {


let userNotificationTypes: UIUserNotificationType = [.Badge, .Alert, .Sound]

let setting = UIUserNotificationSettings(forTypes: userNotificationTypes, categories: nil)

UIApplication.sharedApplication().registerUserNotificationSettings(setting)


UIApplication.sharedApplication().registerForRemoteNotifications()

}


Now, for each app launch, I check (From the NSUserDefault) if the user authorize push notification and the answer is true I call to the method:


UIApplication.sharedApplication().registerForRemoteNotifications()


In order to get push notification token and send him to the se.


Now, the above code is in my app store version.


Lately I noticed the I get every push notification duplicate when the device is unlocked and the app is in the background.


Probably the problem is that I don't call for each launch to the method:

UIApplication.sharedApplication().registerUserNotificationSettings(setting)

I have tried to get the same version as the app Store version and call every launch to my method:

regusterToPushNotification()

Instead only:

UIApplication.sharedApplication().registerForRemoteNotifications()

And just after reinstall the app the bug is desaper.

Now if I upload a new version with the above fix the bug will continue to happen for the user that update the version and fix just for the new users.


I have tried to reset the settings by calls to the methods on the migration code from the old version to the new version:

let userNotificationTypes: UIUserNotificationType = []

let setting = UIUserNotificationSettings(forTypes: userNotificationTypes, categories: nil)

UIApplication.sharedApplication().registerUserNotificationSettings(setting)


I also tried to unregister from push notification on the migration code.


But the bug is still reproducing.

Any idea how to solve this bug for all the users that already install my app.

Thanks

Had a similiar issue: https://forums.developer.apple.com/thread/28115

Maybe its the same issue.

Same problem here!

Receiving duplicate push notification
 
 
Q