[英]Is the device token changes if Uninstall/reinstall App for same device
我收到同一应用的多个通知。
如果它改变了如何删除旧的形式从我们的服务器。
这是我在iOS 9设备中的观察
1.DB APPId和设备令牌中有两个字段。如果我取消安装该应用程序并将其再次安装在同一设备中,则设备令牌会更改。
2.我在同一台设备上测试了另一个应用程序即使同一台设备,设备令牌也不同
我从同一个设备收到3条通知,即使我从数据库中删除了第一个设备令牌…。 我仍然不明白为什么还要发出多个通知。
可能是什么原因?
Device token
在以下情况下发生更改。
因此,我的建议是使用新令牌更新服务器。
每次在didRegisterForRemoteNotificationsWithDeviceToken
启动应用程序时,您都必须调用api,如果更改,它将更新设备令牌。
在您的数据库中,再创建两个字段作为device token
和APPId
因此,相对于APPId
更新device token
。
从设备钥匙串中获取APPId
或唯一设备ID,并使用device token
将其发送到服务器,以便在服务器上针对APPId
更新device token
。
在以下情况下, 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!
}
为注销会话创建新的Web服务,并在注销时调用此服务,并且此服务告诉后端开发人员从数据库中删除设备令牌。
@Krishna:设备令牌与您首次安装并卸载该应用程序时相同,然后再次在同一设备上安装了该应用程序。
如果您第二次使用新设备,则设备令牌将有所不同。
注意:仅通知后端开发人员执行以下操作:
它的工作正常。
iOS9及更高版本 ,每次重新安装应用程序时,设备令牌可能都会更改。 因此,最好的方法是在每次启动时存储(更新或插入到DB)设备令牌。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.