How to get Device UDID in programmatically in iOS7

2019-01-13 05:00发布

How to get device UDID in programatically in iOS7.[[UIDevice currentDevice] uniqueIdentifier] I was used this code This is deprecated iOS7. how to get the device UDID. The UDID String changing when I delete the app and the reinstall means the UDID was getting different one.

标签: iphone udid
10条回答
唯我独甜
2楼-- · 2019-01-13 05:08

In iOS 7, Apple now always returns a fixed value when querying the MAC to specifically thwart the MAC as base for an ID scheme. So you now really should use -[UIDevice identifierForVendor] or create a per-install UUID.

Check this SO Question.

查看更多
贼婆χ
3楼-- · 2019-01-13 05:11

For getting UDID: (If you're using this Might be App store guys won't allow it --> As per my concern)

- (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>

For Getting UUID:

    self.uuidTxtFldRef.text = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
查看更多
干净又极端
4楼-- · 2019-01-13 05:14

For getting UUID in Swift 3.0:

let UUIDValue = UIDevice.current.identifierForVendor!.uuidString
查看更多
放我归山
5楼-- · 2019-01-13 05:15

It's work 100% to all the version

other best option recommend by apple use ASIdentifierManager Class Reference

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

this link tell you how to handle and use custom framework

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

iOS 9

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

or

it support only ios 6.0 and above

code to use [[[UIDevice currentDevice] identifierForVendor] UUIDString];

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

ios 5 to use like

 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
}
查看更多
Anthone
6楼-- · 2019-01-13 05:15

Use identifierForVendor or advertisingIdentifier.

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.

Also, see Apple's documentation for the identifierForVendor and advertisingIdentifier.

查看更多
聊天终结者
7楼-- · 2019-01-13 05:22

Have 2 solutions:

  • You can use identifierForVendor after that store them to keychain and use later. Because value of keychain will not changed when re-install app.
  • You can try OpenUDID
查看更多
登录 后发表回答