Skip to content

Commit

Permalink
added global unique identifier for tracking between different apps
Browse files Browse the repository at this point in the history
  • Loading branch information
gekitz committed Aug 22, 2011
1 parent e406c2b commit f217e75
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
17 changes: 17 additions & 0 deletions Classes/UIDevice+IdentifierAddition.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,23 @@

@interface UIDevice (IdentifierAddition)

/*
* @method uniqueDeviceIdentifier
* @description use this method when you need a unique identifier in one app.
* It generates a hash from the MAC-address in combination with the bundle identifier
* of your app.
*/

- (NSString *) uniqueDeviceIdentifier;

/*
* @method uniqueGlobalDeviceIdentifier
* @description use this method when you need a unique global identifier to track a device
* with multiple apps. as example a advertising network will use this method to track the device
* from different apps.
* It generates a hash from the MAC-address only.
*/

- (NSString *) uniqueGlobalDeviceIdentifier;

@end
14 changes: 14 additions & 0 deletions Classes/UIDevice+IdentifierAddition.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ - (NSString *) macaddress;

@implementation UIDevice (IdentifierAddition)

////////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark Private Methods

// Return the local MAC addy
// Courtesy of FreeBSD hackers email list
Expand Down Expand Up @@ -71,6 +74,10 @@ - (NSString *) macaddress{
return outstring;
}

////////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark Public Methods

- (NSString *) uniqueDeviceIdentifier{
NSString *macaddress = [[UIDevice currentDevice] macaddress];
NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
Expand All @@ -81,4 +88,11 @@ - (NSString *) uniqueDeviceIdentifier{
return uniqueIdentifier;
}

- (NSString *) uniqueGlobalDeviceIdentifier{
NSString *macaddress = [[UIDevice currentDevice] macaddress];
NSString *uniqueIdentifier = [macaddress stringFromMD5];

return uniqueIdentifier;
}

@end
3 changes: 2 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ Apple stopped supporting a unique identifier for iOS. This source code solves th

What you need to do:
- copy NSString+MD5Addition and UIDevice+IdentifierAddition to your project.
- use [[UIDevice currentDevice] uniqueDeviceIdentifier] to retrieve the unique identifier.
- use [[UIDevice currentDevice] uniqueDeviceIdentifier] to retrieve the unique identifier
or use [[UIDevice currentDevice] uniqueGlobalDeviceIdentifier] to retrieve a global unique identifier (used for tracking between different apps).
- have fun and follow twitter.com/gekitz ;)

//Thanks to Erica Sadun for her UIDevice+Hardware Addition (used for the mac address retrieval).
15 changes: 13 additions & 2 deletions UIDeviceAddition/UIDeviceAdditionViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,23 @@ - (void)didReceiveMemoryWarning
- (void)viewDidLoad{
[super viewDidLoad];

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 200, 300, 100)];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 100, 300, 100)];
label.numberOfLines = 0;
label.text = [[UIDevice currentDevice] uniqueDeviceIdentifier];
label.textAlignment = UITextAlignmentCenter;
label.text = [NSString stringWithFormat:@"Unique Device Identifier:\n%@",
[[UIDevice currentDevice] uniqueDeviceIdentifier]];

[self.view addSubview:label];
[label release];

label = [[UILabel alloc] initWithFrame:CGRectMake(10, 210, 300, 100)];
label.numberOfLines = 0;
label.textAlignment = UITextAlignmentCenter;
label.text = [NSString stringWithFormat:@"Unique GLOBAL Device Identifier:\n%@",
[[UIDevice currentDevice] uniqueGlobalDeviceIdentifier]];

[self.view addSubview:label];
[label release];
}


Expand Down

0 comments on commit f217e75

Please sign in to comment.