Swift获取UUID方法

1.利用三方库的支持三方demo点这里

2.将demo中SSKeychain.h SSKeychain.m文件拖入工程,桥接配置自己百度

3.在工程中建一个.swift文件供全局调用方法

private var UUID : NSString?
public func getUUID()->String{


let UUIDDate = SSKeychain.passwordData(forService: "com.magic.bang", account: "com.magic.bang")


if UUIDDate != nil{
    
    UUID = NSString(data: UUIDDate!, encoding: String.Encoding.utf8.rawValue)
}


if(UUID == nil){
    
    UUID = UIDevice.current.identifierForVendor!.uuidString as NSString
    
    SSKeychain.setPassword(UUID! as String, forService: "com.magic.bang", account: "com.magic.bang")
    
}

return UUID! as String

}

4.在TARGETS中Capabilities中将Keychain Sharing打开就可以了

你可能感兴趣的:(Swift获取UUID方法)