Does an iOS device's uuid ever change, with software updates or anything related?
Asked
Active
Viewed 4,154 times
4 Answers
0
You can create your own 'UUID' which will persist for as long as your app is on the device.
+ (NSString *)localUuid {
NSString *ident = [[NSUserDefaults standardUserDefaults] objectForKey:@"unique identifier stored for app"];
if (!ident) {
CFUUIDRef uuidRef = CFUUIDCreate(NULL);
CFStringRef uuidStringRef = CFUUIDCreateString(NULL, uuidRef);
CFRelease(uuidRef);
ident = [NSString stringWithString:(NSString *)uuidStringRef];
CFRelease(uuidStringRef);
[[NSUserDefaults standardUserDefaults] setObject:ident forKey:@"unique identifier stored for app"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
return ident;
}
but this does not give you a unique id that you can use across applications for obvious reasons. Another alternative is using the MAC address
#import <sys/types.h>
#import <sys/socket.h>
#import <sys/sysctl.h>
#import <sys/time.h>
#import <netinet/in.h>
#import <net/if_dl.h>
#import <netdb.h>
#import <errno.h>
#import <arpa/inet.h>
#import <unistd.hv
#import <ifaddrs.h>
#if !defined(IFT_ETHER)
#define IFT_ETHER 0x6
#endif
@implementation MACIdentify
- (NSString*)MACAddress {
NSMutableString* result = [NSMutableString string];
BOOL success;
struct ifaddrs* addrs;
const struct ifaddrs* cursor;
const struct sockaddr_dl* dlAddr;
const uint8_t * base;
int i;
success = (getifaddrs(&addrs) == 0);
if(success)
{
cursor = addrs;
while(cursor != NULL)
{
if((cursor->ifa_addr->sa_family == AF_LINK) && (((const struct sockaddr_dl *) cursor->ifa_addr)->sdl_type == IFT_ETHER))
{
dlAddr = (const struct sockaddr_dl *) cursor->ifa_addr;
base = (const uint8_t *) &dlAddr->sdl_data[dlAddr->sdl_nlen];
for(i=0; isdl_alen; i++)
{
if(i != 0)
{
[result appendString:@":"];
}
[result appendFormat:@"%02x", base[i]];
}
}
cursor = cursor->ifa_next;
}
freeifaddrs(addrs);
}
return result;
}
@end

Scott Sherwood
- 3,108
- 25
- 30
-
2That's not what he was asking. – Abizern Dec 31 '11 at 16:20
-
Plus, as noted by @HaggleLad in a comment to [my answer to another question](http://stackoverflow.com/a/6993440/400056), for privacy reasons it's not a good idea to use the MAC as-is. It should be obfuscated, for example by hashing it with MD5 or SHA1. – DarkDust Dec 31 '11 at 16:48
-1
The UDID never changes on iOS devices running Apple's stock OS.
On devices running a rooted/modified OS, the value returned by any API could be anything a clever modifier wants it to be.

hotpaw2
- 70,107
- 14
- 90
- 153