我正在使用 Xamarin Forms,并且需要 iOS 设备的设备 ID。 当应用程序被删除并重新安装时,情况会发生变化。 我需要设备的恒定设备 ID。
我已获悉我可以在 Xamarin 表单 iOS 中使用 DeviceCheck.DCDevice。 这会通过 Apple 生成一个用于识别设备的 token 。 有谁可以提供我可以遵循的代码示例来实现此目的吗? 使用 DCDevice.GenerateToken... C# iOS
最佳答案
Use DeviceCheck.DCDevice in Xamarin forms iOS.
if (DCDevice.CurrentDevice.Supported)
{
DCDeviceGenerateTokenCompletionHandler handler = (NSData token, NSError error) =>
{
// Upload token to App server
};
DCDevice.CurrentDevice.GenerateToken(handler);
}
要在 Xamarin.iOS 中使用 DeviceCheck.DCDevice
,据我了解,DeviceCheck
不会提供像 IdentifierForVendor
或 UUId
不会改变并始终代表该设备。请注意,DeviceCheck
仅在 iOS 11 以上版本可用。
您的应用使用 DeviceCheck API 生成标识设备的临时 token 。您的关联服务器将此 token 与您从 Apple 收到的身份验证 key 相结合,并使用结果请求访问每个设备位。
我认为使用 DeviceCheck.DCDevice
识别设备的方法取决于您的应用程序
业务逻辑。
您可以阅读这篇文章(devicecheck-tutorial)以更好地了解DeviceCheck到底在做什么,进而实现您的要求。
这里还有一个 swift 示例,您可以引用:DeviceCheckSample
苹果文档:devicecheck
I am using Xamarin Forms and I need a Device Id from the iOS device. I need a constant Device Id for the device.
还有其他几个选项供您选择:
将您的设备 ID 存储在
钥匙串(keychain)
中,它可能会在应用删除/重新安装后持续存在。如果您的应用程序有广告,您可以使用Advertising Identifier识别设备并将此数据发送到服务器以检查设备 ID。
关于ios - 如何使用 DeviceCheck.DCDevice Xamarin Forms C# 生成 token 代码 iOS DeviceId,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54212000/