Getting Device Id or MAC Address in iOS

Getting Device ID or Mac Address in iOS

[[UIDevice currentDevice] uniqueIdentifier] is guaranteed to be unique to each device.

How to get unique id in iOS device?

You can no longer get a unique ID per device. identifierForVendor is the best you're going to get. Apple has systematically disabled identifying a specific device so that users' IDs can't be passed around by marketers.

To get the identifier ID as a string, you can use

let deviceId = UIDevice.current.identifierForVendor?.uuidString

UPDATE

If you want a universal ID then you have the option to use advertisingIdentifier. However, if the user has limited ad tracking in their device settings then this value will simply return all zeroes.

import AdSupport

let identifierManager = ASIdentifierManager.shared()
if identifierManager.isAdvertisingTrackingEnabled {
let deviceId = identifierManager.advertisingIdentifier.uuidString
}

N.B. Apple recommends that this code only be used by companies building advertisement frameworks, rather than the app developers themselves. If you use this within your code for non-ad-related purposes then prepare to have your app rejected.

Best way to uniquely identify iOS device?

Starting iOS 7 deducing MAC address isn't possible. You can, however, use below:

[[[UIDevice currentDevice] identifierForVendor] UUIDString]

Per Apple Documentation:

The value changes when the user deletes all of that vendor’s apps from
the device and subsequently reinstalls one or more of them. The value
can also when installing test builds using Xcode or when installing an
app on a device using ad-hoc distribution. Therefore, if your app
stores the value of this property anywhere, you should gracefully
handle situations where the identifier changes.

Returned mac-address is the same for different devices

Sorry guys, I was not attentive enough.
When I was talking about the devices, I should mention that one of them was actually a simulator (with iOS 7), and the other was a device with iOS 7.
So now I've found in the Apple documentation, that:

In iOS 7 and later, if you ask for the MAC address of an iOS device, the system returns the value 02:00:00:00:00:00. If you need to identify the device, use the identifierForVendor property of UIDevice instead. (Apps that need an identifier for their own advertising purposes should consider using the advertisingIdentifier property of ASIdentifierManager instead.)

So, identifierForVendor is exactly what I wanted. It's a pity though, that now in the code a developer should sort out different iOS versions support even for that thing.

How to get a unique device ID in Swift?

You can use this (Swift 3):

UIDevice.current.identifierForVendor!.uuidString

For older versions:

UIDevice.currentDevice().identifierForVendor

or if you want a string:

UIDevice.currentDevice().identifierForVendor!.UUIDString


There is no longer a way to uniquely identify a device after the user uninstalled the app(s). The documentation says:

The value in this property remains the same while the app (or another app from the same vendor) is installed on the iOS device. The value changes when the user deletes all of that vendor’s apps from the device and subsequently reinstalls one or more of them.


You may also want to read this article by Mattt Thompson for more details:

http://nshipster.com/uuid-udid-unique-identifier/

Update for Swift 4.1, you will need to use:

UIDevice.current.identifierForVendor?.uuidString

How to get MAC address programmatically in my iOS app

Mac address is unavailable from ios 7 and up.

Apple Said

In iOS 7 and later, if you ask for the MAC address of an iOS device,
the system returns the value 02:00:00:00:00:00. If you need to
identify the device, use the identifierForVendor property of UIDevice
instead. (Apps that need an identifier for their own advertising
purposes should consider using the advertisingIdentifier property of
ASIdentifierManager instead.)

Check bottom of the page into Apple Document.

So better solution for that.
Following code returns unique address.

#import "UIDevice+Identifier.h"

- (NSString *) identifierForVendor1
{
if ([[UIDevice currentDevice] respondsToSelector:@selector(identifierForVendor)]) {
return [[[UIDevice currentDevice] identifierForVendor] UUIDString];
}
return @"";
}

Calling Method

NSString *like_UDID=[NSString stringWithFormat:@"%@",
[[UIDevice currentDevice] identifierForVendor1]];

NSLog(@"%@",like_UDID);

Also another solution visit HERE

Edited

UIDevice+Identifier.h

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

@interface UIDevice (IdentifierAddition)
- (NSString *) identifierForVendor1;
@end

UIDevice+Identifier.m

#import "UIDevice+Identifier.h"

@implementation UIDevice (IdentifierAddition)
- (NSString *) identifierForVendor1
{
if ([[UIDevice currentDevice] respondsToSelector:@selector(identifierForVendor)]) {
return [[[UIDevice currentDevice] identifierForVendor] UUIDString];
}
return @"";
}

@end

Calling above Function.

ViewController.m

#import "ViewController.h"
#import "UIDevice+Identifier.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

NSString *like_UDID=[NSString stringWithFormat:@"%@",
[[UIDevice currentDevice] identifierForVendor1]];

NSLog(@"%@",like_UDID);
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end

Can I get an unique and permanent device identifier on a Flutter app (iOS)?

Finally I've decided to use the "identifierForVendor" because it seems the more appropriate for the app context.

Getting two different device IDs from same iphone

one easiest way is to solve this issue by storing the identifierForVendor in keychain. even if you uninstall app ,value for the key remains same and its unchanged. many third party libraries available to perform this . one of them https://github.com/jrendel/SwiftKeychainWrapper.

func getGlobalUniqueIdentifierFromKeyChain()->String{

let retrievedString: String? = KeychainWrapper.standard.string(forKey: "DeviceId")

if retrievedString == nil{
if let deviceKey = UIDevice.current.identifierForVendor?.uuidString{
let _ = KeychainWrapper.standard.set(deviceKey, forKey: "DeviceId")
}
}

if let globalID = KeychainWrapper.standard.string(forKey: "DeviceId"){
return globalID
}else{
return UIDevice.current.identifierForVendor?.uuidString ?? ""
}
}


Related Topics



Leave a reply



Submit