Im getting multiple notifications for same app..
if It changes how to delete the old one form our server..
Here is my observation in iOS 9 device
1.There are two fields in DB APPId and Device token If I unstalled the app and installed it again in the same device the device token changes..
2.I tested another app in the same device The Device Token is different even the same device
Im getting 3 notifications to the same device Even If I deleted the first device token one from my DB…. I didn’t understand still whiz the reason for multiple notifications..
What might be the possible reasons ?
The Device token
is change in the following conditions.
So my suggestion is to update the server with the new token.
When every time app is launch in didRegisterForRemoteNotificationsWithDeviceToken
you have to call api which update the device token if changes.
In your DB create two more fields as device token
and APPId
so, update device token
with respect to APPId
.
Get APPId
or unique device id from device keychain and send it to your server with device token
so, at server update device token
with respect to APPId
.
keychain
value will never change in the above following conditions.
For getting Keychain value follow Keychain
// MARK: - Push Notification Delegate Methods.
func application(_ application: UIApplication,didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
//send this device token to server
let token = String(data: deviceToken.base64EncodedData(), encoding: .utf8)?.trimmingCharacters(in: CharacterSet.whitespaces).trimmingCharacters(in: CharacterSet(charactersIn: "<>"))
//Save device to UserDefaults
let defaults = UserDefaults.standard
defaults.set(token, forKey: "DeviceToken")
defaults.synchronize()
print("token is ---\(token)")
print("AppId ----\(getUniqueDeviceIdentifierAsString)")
//Send token value and AppId to server
}
var getUniqueDeviceIdentifierAsString : String {
let appname = Bundle.main.infoDictionary![kCFBundleNameKey as String] as! String
var strApplicationUUID: String? = KeychainWrapper.standard.string(forKey: appname)
if strApplicationUUID == nil {
strApplicationUUID = UIDevice.current.identifierForVendor?.uuidString
_ = KeychainWrapper.standard.set(strApplicationUUID!, forKey: appname)
}
return strApplicationUUID!
}
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