Подтвердить что ты не робот

Как получить UDID устройства программно в iOS7?

Как получить UDID устройства программно в iOS7. [[UIDevice currentDevice] uniqueIdentifier] Я использовал этот код Это устаревший iOS7. как получить UDID устройства. Строка UDID, изменяющаяся при удалении приложения и переустановке, означает, что UDID становится другим.

4b9b3361

Ответ 1

Он работает на 100% для всех версий

другой лучший вариант, рекомендуемый при использовании Apple Справочник класса ASIdentifierManager

ios7-app-backward-compatible-with-ios5-regarding-unique-identifier

эта ссылка сообщит вам, как обрабатывать и использовать пользовательскую инфраструктуру

uidevice-uniqueidentifier-property-is-deprecated-what-now

iOS 9

NSUUID *uuid = [[NSUUID alloc]initWithUUIDString:@"20B0DDE7-6087-4607-842A-E97C72E4D522"];
NSLog(@"%@",uuid);
NSLog(@"%@",[uuid UUIDString]);

или

он поддерживает только ios 6.0 и выше

для использования [[[UIDevice currentDevice] identifierForVendor] UUIDString];

NSUUID *deviceId;
#if TARGET_IPHONE_SIMULATOR
deviceId = [NSUUID initWithUUIDString:@"UUID-STRING-VALUE"];
#else
deviceId = [UIDevice currentDevice].identifierForVendor;
#endif

ios 5 для использования как

 if ([[UIDevice currentDevice] respondsToSelector:@selector(identifierForVendor)]) {
    // This is will run if it is iOS6
    return [[[UIDevice currentDevice] identifierForVendor] UUIDString];
} else {
   // This is will run before iOS6 and you can use openUDID or other 
   // method to generate an identifier
}

Ответ 2

UDID больше не доступен в iOS 6+ из-за соображений безопасности/конфиденциальности. Вместо этого используйте идентификатор ForVendor или advertIdentifier.

Пройдите эту ссылку.

   NSString* uniqueIdentifier = [[[UIDevice currentDevice] identifierForVendor] UUIDString]; // IOS 6+
   NSLog(@"UDID:: %@", uniqueIdentifier);

UPDATE для iOS 8 +

+ (NSString *)deviceUUID
{
    if([[NSUserDefaults standardUserDefaults] objectForKey:[[NSBundle mainBundle] bundleIdentifier]])
        return [[NSUserDefaults standardUserDefaults] objectForKey:[[NSBundle mainBundle] bundleIdentifier]];

    @autoreleasepool {

        CFUUIDRef uuidReference = CFUUIDCreate(nil);
        CFStringRef stringReference = CFUUIDCreateString(nil, uuidReference);
        NSString *uuidString = (__bridge NSString *)(stringReference);
        [[NSUserDefaults standardUserDefaults] setObject:uuidString forKey:[[NSBundle mainBundle] bundleIdentifier]];
        [[NSUserDefaults standardUserDefaults] synchronize];
        CFRelease(uuidReference);
        CFRelease(stringReference);
        return uuidString;
    }
}

Ответ 3

В Swift вы можете получить UUID устройства следующим образом

let uuid = UIDevice.currentDevice().identifierForVendor.UUIDString
println(uuid)

Ответ 4

Использовать идентификатор ForVendor или рекламный идентификатор.

identifierForVendor:

An alphanumeric string that uniquely identifies a device to the app’s vendor. (read-only)

The value of this property is the same for apps that come from the same vendor running on the same device. A different value is returned for apps on the same device that come from different vendors, and for apps on different devices regardless of vendor.

advertisingIdentifier:

An alphanumeric string unique to each device, used only for serving advertisements. (read-only)

Unlike the identifierForVendor property of UIDevice, the same value is returned to all vendors. This identifier may change—for example, if the user erases the device—so you should not cache it.

Также см. документацию Apple для идентификатора ForVendor и advertIdentifier.

Ответ 5

В iOS 7 Apple теперь всегда возвращает фиксированное значение при запросе MAC, чтобы конкретно препятствовать MAC в качестве базы для схемы ID. Итак, теперь вы действительно должны использовать - [UIDevice identifierForVendor] или создать UUID для каждой установки.

Отметьте этот SO Вопрос.

Ответ 6

У вас есть 2 решения:

  • Вы можете использовать идентификаторForVendor после этого, чтобы сохранить их в связке ключей и использовать позже. Поскольку значение keychain не будет изменено при переустановке приложения.
  • Вы можете попробовать OpenUDID

Ответ 7

Для получения UDID: (Если вы используете этот магазин Might be App, ребята не позволят его → В соответствии с моей заботой)

- (NSString *)udid
{
void *gestalt = dlopen("/usr/lib/libMobileGestalt.dylib", RTLD_GLOBAL | RTLD_LAZY);
CFStringRef (*MGCopyAnswer)(CFStringRef) = (CFStringRef (*)(CFStringRef))(dlsym(gestalt, "MGCopyAnswer"));
return CFBridgingRelease(MGCopyAnswer(CFSTR("UniqueDeviceID")));
}

 **Entitlements:**
 <key>com.apple.private.MobileGestalt.AllowedProtectedKeys</key>
   <array>
<string>UniqueDeviceID</string>
</array>

Для получения UUID:

    self.uuidTxtFldRef.text = [[[UIDevice currentDevice] identifierForVendor] UUIDString];

Ответ 8

Swift 2.2+ правильный способ получить UUID:

if let UUID = UIDevice.currentDevice().identifierForVendor {
  print("UUID: \(UUID.UUIDString)")
}

Ответ 9

Для получения UUID в Swift3.0

пусть UUIDValue = UIDevice.current.identifierForVendor!.uuidString

Ответ 10

В Swift 3.0:

UIDevice.current.identifierForVendor!.uuidString

старая версия

UIDevice.currentDevice().identifierForVendor

вам нужна строка:

UIDevice.currentDevice().identifierForVendor!.UUIDString