Skip to content

Commit

Permalink
using GUUID instead of Bundle Id
Browse files Browse the repository at this point in the history
  • Loading branch information
anupamtulsyan committed Mar 28, 2012
1 parent a29fc75 commit 9786dcd
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions OpenUDID.m
Expand Up @@ -49,11 +49,12 @@ this software and associated documentation files (the "Software"), to deal in
static NSString * kOpenUDIDSessionCache = nil;
static NSString * const kOpenUDIDKey = @"OpenUDID";
static NSString * const kOpenUDIDSlotKey = @"OpenUDID_slot";
static NSString * const kOpenUDIDBIDKey = @"OpenUDID_bundleid";
static NSString * const kOpenUDIDGIDKey = @"OpenUDID_guuid";
static NSString * const kOpenUDIDTSKey = @"OpenUDID_createdTS";
static NSString * const kOpenUDIDOOTSKey = @"OpenUDID_optOutTS";
static NSString * const kOpenUDIDDomain = @"org.OpenUDID";
static NSString * const kOpenUDIDSlotPBPrefix = @"org.OpenUDID.slot.";
static NSString * const kAppGUUID = @"app_guuid";
static int const kOpenUDIDRedundancySlots = 100;

@interface OpenUDID (Private)
Expand Down Expand Up @@ -162,8 +163,16 @@ + (NSString*) valueWithError:(NSError **)error {
}


NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *bundleid = [[NSBundle mainBundle] bundleIdentifier];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString * guuid = (NSString *) [defaults objectForKey:kAppGUUID];

This comment has been minimized.

Copy link
@ylechelle

ylechelle Mar 30, 2012

Owner

Did you mean kOpenUDIDGIDKey instead of kAppGUUID???

if(guuid == nil)
{
//generate a new uuid and store it in user defaults
CFUUIDRef uuid = CFUUIDCreate(NULL);
guuid = (NSString *) CFUUIDCreateString(NULL, uuid);
CFRelease(uuid);
}

NSString* openUDID = nil;
NSString* myRedundancySlotPBid = nil;
NSDate* optedOutDate = nil;
Expand Down Expand Up @@ -211,8 +220,8 @@ + (NSString*) valueWithError:(NSError **)error {
[frequencyDict setObject:[NSNumber numberWithInt:++count] forKey:oudid];
}
// if we have a match with the bundleid, then let's look if the external UIPasteboard representation marks this app as OptedOut
NSString* bid = [dict objectForKey:kOpenUDIDBIDKey];
if (bid!=nil && [bid isEqualToString:bundleid]) {
NSString* gid = [dict objectForKey:kOpenUDIDGIDKey];
if (gid!=nil && [gid isEqualToString:guuid]) {
myRedundancySlotPBid = slotPBid;
optedOutDate = [dict objectForKey:kOpenUDIDOOTSKey];
optedOut = optedOutDate!=nil;
Expand Down Expand Up @@ -245,7 +254,7 @@ + (NSString*) valueWithError:(NSError **)error {
if (localDict==nil) {
localDict = [NSMutableDictionary dictionaryWithCapacity:4];
[localDict setObject:openUDID forKey:kOpenUDIDKey];
[localDict setObject:bundleid forKey:kOpenUDIDBIDKey];
[localDict setObject:guuid forKey:kOpenUDIDGIDKey];
[localDict setObject:[NSDate date] forKey:kOpenUDIDTSKey];
if (optedOut) [localDict setObject:optedOutDate forKey:kOpenUDIDTSKey];
saveLocalDictToDefaults = YES;
Expand Down Expand Up @@ -295,7 +304,7 @@ + (NSString*) valueWithError:(NSError **)error {
if (optedOut) {
if (error!=nil) *error = [NSError errorWithDomain:kOpenUDIDDomain
code:kOpenUDIDErrorOptedOut
userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Application %@ is opted-out from OpenUDID as of %@",bundleid,optedOutDate],@"description", nil]];
userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"Application with GUUID %@ is opted-out from OpenUDID as of %@",guuid,optedOutDate],@"description", nil]];

kOpenUDIDSessionCache = [[NSString stringWithFormat:@"%040x",0] retain];
return kOpenUDIDSessionCache;
Expand Down

0 comments on commit 9786dcd

Please sign in to comment.