尝试执行时发生当机:

static func getDeviceUUID() -> String {
        guard let uuid = UIDevice.current.identifierForVendor?.uuidString else {
            assertionFailure("Nil while unwrapping UIDevice.current.identifierForVendor?.uuidString")
            return ""}
            return uuid
    }

错误提示:Thread 9: Fatal error: Nil while unwrapping UIDevice.current.identifierForVendor?.uuidString
但是,当我尝试在控制台中注销时,它说:
 po UIDevice.current.identifierForVendor?.uuidString
▿ Optional<String>
  - some : "39DEFA50-D6A1-4788-BCCC-5E2A28A04C57"

因此,它实际上具有价值。为什么会发生崩溃?

最佳答案

一切正常

func getDeviceUUID() -> String {
        guard let uuid = UIDevice.current.identifierForVendor?.uuidString else {
            assertionFailure("Nil while unwrapping UIDevice.current.identifierForVendor?.uuidString")
            return ""}
        return uuid
    }

print(getDeviceUUID()) //50E6548C-0BB4-4979-8F5F-DFAD422BEB26

关于ios - 尝试获取UIDevice.current.identifierForVendor?.uuidString时崩溃,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48863351/

10-12 16:05