获取UUID并做保存

static func getUUIDString() ->String{

        guard let uuidDefault =UserDefaults.standard.string(forKey:"yunuuid")else{

            let uuidRef = CFUUIDCreate(kCFAllocatorDefault)

            let strRef = CFUUIDCreateString(kCFAllocatorDefault, uuidRef)

            let uuidString = (strRef!asString).replacingOccurrences(of:"-", with:"")

            let uuidDefault =UserDefaults.standard

            uuidDefault.set(uuidString, forKey:"yunuuid")

            uuidDefault.synchronize()

            returnuuidString

        }

        return uuidDefault

    }

你可能感兴趣的:(获取UUID并做保存)