首次获取必定是nil,写在此处是为了容错 deviceId = [MFSSafariCookieDeviceId cookieDId]; if (!deviceId.length) { //走到这步说明UserDefaults的plist被人为删除,获取客户端内缓存数据 deviceId = cacheDeviceId; if (!deviceId.length) { //客户端内缓存数据也被清理,获取iCloud数据 deviceId = [[NSUbiquitousKeyValueStore defaultStore] objectForKey: kMFSIdentifierUserDeviceIdKey]; if (!deviceId.length) { //iCloud未登陆或者被清空,获取IDFA if ([[ASIdentifierManager sharedManager] isAdvertisingTrackingEnabled]) { deviceId = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString]; } if (!deviceId.length) { //IDFA被用户手动重置,取IDFV deviceId = [[UIDevice currentDevice] identifierForVendor].UUIDString; if (!deviceId.length) { //什么都取不到,获取token deviceId = @"devicePushToken值"; if (!deviceId.length) { deviceId = [[NSUUID UUID] UUIDString]; } } } } } } } if (deviceId.length) { [MFSKeyChain setObject:deviceId forKey:keyChain_Key]; [cacheManager() setObject:deviceId forKey:kMFSIdentifierCacheDeviceIdKey duration:-9]; [userDefaults() setObject:deviceId forKey:kMFSIdenti