How to create a unique device identifier for iPhone / iPad using Objective-c

I wanted to know that How to create a unique device identifier for iPhone / iPad using Objective-c

so as soon as the application is installed on the device, we must track this device identifier

  • I was looking to get IMEI for iPhone / iPad, but it is not allowed in objective-c.

  • Then I searched to generate the iPhone / iPad UDID, but it generates for different IDs every time I run it on the simulator.

+6
source share
8 answers

, UDID ; UDID - . Apple , , IMEI, MAC-, UDID ..

UUID - . . , , UUID. UUID Keychain . , . .


- IOS 10.3 :

, Apple Keychain iOS 10. 3+. , , , . Apple, , , , .

, Keychain, , WORKAROUND . , Keychain Access Group, , , keychain .


UPDATE - IOS 10.3.3 (STABLE): , IOS 10.3.3 . , . Keychain.

+13

UUID ( ).

https://developer.apple.com/reference/uikit/uidevice/1620059-identifierforvendor

https://developer.apple.com/library/content/releasenotes/General/WhatsNewIniOS/Articles/iOS7.html#//apple_ref/doc/uid/TP40013162-SW1

UUID:

//Objective-C

NSString * string =  [[[UIDevice currentDevice] identifierForVendor] UUIDString];

//

let deviceID = UIDevice.currentDevice().identifierForVendor?.UUIDString 

//Swift 3

let deviceID = UIDevice.current.identifierForVendor?.uuidString
+7

, UDID iOS. KeychainItemWrapper Class URL KeychainItemWrap

NSString *uuid;
KeychainItemWrapper *keychain = [[KeychainItemWrapper alloc] initWithIdentifier:@"AC_APP_UUID" accessGroup:nil];
NSString *keychainUUID = [keychain objectForKey:(__bridge id)(kSecAttrAccount)];
NSString *appVersion = [NSString stringWithFormat:@"%@",@"1.0"];
[keychain setObject:appVersion forKey:(__bridge id)(kSecAttrDescription)];
if (keychainUUID==nil||[keychainUUID isKindOfClass:[NSNull class]]||keychainUUID.length==0) {
    uuid = [[NSUUID UUID] UUIDString];
    [keychain setObject:uuid forKey:(__bridge id)(kSecAttrAccount)];
}else{
    uuid = [keychain objectForKey:(__bridge id)(kSecAttrAccount)];
}
+5

, ,
, - .

0

, 2017 , Apple DeviceCheck.

https://developer.apple.com/documentation/devicecheck#overview

DeviceCheck, , . , , .

0

IMEI , Apple .

UDID . keychainwrapper UDID, :

   UIDevice *device = [[UIDevice alloc]init]; 
   NSString *idForVend = [NSString stringWithFormat:@"%@", [device identifierForVendor]]; 
   NSLog(@"Identifier For Vendor : %@",idForVend);

, : https://stackoverflow.com/questions/16459879/how-to-store-a-string-in-keychain-ios, iOS? , DeviceID.

-1
#import <AdSupport/AdSupport.h>

NSString* sClientID = [[[ASIdentifierManager sharedManager]advertisingIdentifier] UUIDString];

UUID, :

  • (* )
  • Apple .
-2

:

DeviceToken. DeviceToken - uniq .

:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)])
    {
        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];

        [[UIApplication sharedApplication] registerForRemoteNotifications];
    }
    else
    {
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
         (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
    }
    return yes;

}


- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{

   NSString *AppDeviceToken=[[NSString alloc] initWithFormat:@"%@",deviceToken];
    //NSLog(@"My token is: %@", self.AppDeviceToken);

   AppDeviceToken = [self.AppDeviceToken stringByReplacingOccurrencesOfString:@" " withString:@""];
   AppDeviceToken = [self.AppDeviceToken stringByReplacingOccurrencesOfString:@"<" withString:@""];
   AppDeviceToken = [self.AppDeviceToken stringByReplacingOccurrencesOfString:@">" withString:@""];

    NSLog(@"%@ Device Token is : %@",[[UIDevice currentDevice] name],AppDeviceToken);
}
- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
    NSLog(@"Failed to get token, error: %@", error);
}

- uniq .

-5

Source: https://habr.com/ru/post/1663093/


All Articles