我需要从NSData中获得vendorIdentifier,而不需要转换为NSString,清除字节。如何使用NSUUID将getUUIDBytes:转换为NSData
发布于 2015-10-16 21:07:16
使用它作为vendorIdentifier作为Data (Swift 4):
var uuidBytes = UIDevice.current.identifierForVendor!.uuid
let uuidData = NSData(bytes: &uuidBytes, length: 16) as Data记住,要防止UIDevice.current.identifierForVendor像文档所说的那样为零。
原文(Swift 2版本):
var uuidBytes: [UInt8] = [UInt8](count: 16, repeatedValue: 0)
UIDevice.currentDevice().identifierForVendor!.getUUIDBytes(&uuidBytes)
let uuidData = NSData(bytes: &uuidBytes, length: 16)发布于 2017-02-28 23:03:13
Swift 3版本:
let vendorId = UIDevice.current.identifierForVendor!
let uuidBytes = Mirror(reflecting: vendorId.uuid).children.map { $0.1 as! UInt8 }
let data = Data(bytes: uuidBytes)https://stackoverflow.com/questions/19170622
复制相似问题