I notice some devices doesn't generate device token for push notification. I have been using the following code to generate device token and implemented the
didRegisterForRemoteNotificationsWithDeviceToken method
var types: UIUserNotificationType = UIUserNotificationType.Badge |
UIUserNotificationType.Alert |
UIUserNotificationType.Sound
var settings: UIUserNotificationSettings = UIUserNotificationSettings( forTypes: types, categories: nil )
application.registerUserNotificationSettings( settings )
application.registerForRemoteNotifications()
I get device token for some devices.However i thought device token was not generated for some devices due to lack of internet connnection.To be sure, i turned off the internet connection and made sure that was my problem but it successfully generates token?
In my knowledge my app requests the device token with the apple server...
Why is this happening.And how is device token generated?
Do i really dont need internet connection to generate device token
Interent connection is must to register device for remotenotification
var types: UIUserNotificationType = UIUserNotificationType.Badge |
UIUserNotificationType.Alert |
UIUserNotificationType.Sound
var settings: UIUserNotificationSettings = UIUserNotificationSettings( forTypes: types, categories: nil )
application.registerUserNotificationSettings( settings )
application.registerForRemoteNotifications()
above code only work when you have internet
What you can do when is when u got device token in this function didRegisterForRemoteNotificationsWithDeviceToken
store it in NSUserDefault , Now next time check if you have internet connection than do the above method if not get device token from NSUserDefault. To check internetConnection you can use Reachability class got it from here https://github.com/ashleymills/Reachability.swift
If your application has previously registered, calling registerForRemoteNotificationTypes: results in the operating system passing the device token to the delegate immediately without incurring additional overhead.
Otherwise Change WIFI
Hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With