Skip to content
This repository
Browse code

Important backwards compatible change for iOS 6 support

This commit will break the code, on purpose. Please read the important
note around the #error and fix it accordingly for iOS 6 if you can, if
not, comment it out!
  • Loading branch information...
commit 4b566c139b22f83d0186083e4141878864458238 1 parent a3840eb
Yann Lechelle authored August 28, 2012

Showing 1 changed file with 42 additions and 7 deletions. Show diff stats Hide diff stats

  1. 49  OpenUDID.m
49  OpenUDID.m
@@ -3,7 +3,7 @@
3 3
 //  openudid
4 4
 //
5 5
 //  initiated by Yann Lechelle (cofounder @Appsfire) on 8/28/11.
6  
-//  Copyright 2011 OpenUDID.org
  6
+//  Copyright 2011, 2012 OpenUDID.org
7 7
 //
8 8
 //  Initiators/root branches
9 9
 //      iOS code: https://github.com/ylechelle/OpenUDID
@@ -42,6 +42,8 @@
42 42
     // https://img.skitch.com/20120717-g3ag5h9a6ehkgpmpjiuen3qpwp.png
43 43
 #endif
44 44
 
  45
+#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
  46
+
45 47
 #import "OpenUDID.h"
46 48
 #import <CommonCrypto/CommonDigest.h> // Need to import for CC_MD5 access
47 49
 #if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
@@ -56,6 +58,7 @@
56 58
 //#define OpenUDIDLog(fmt, ...) NSLog((@"[Line %d] " fmt), __LINE__, ##__VA_ARGS__);
57 59
 
58 60
 static NSString * kOpenUDIDSessionCache = nil;
  61
+static NSString * const kOpenUDIDDescription = @"OpenUDID_with_iOS6_Support";
59 62
 static NSString * const kOpenUDIDKey = @"OpenUDID";
60 63
 static NSString * const kOpenUDIDSlotKey = @"OpenUDID_slot";
61 64
 static NSString * const kOpenUDIDAppUIDKey = @"OpenUDID_appUID";
@@ -115,14 +118,45 @@ + (NSString*) _generateFreshOpenUDID {
115 118
     NSString* _openUDID = nil;
116 119
     
117 120
     // August 2011: One day, this may no longer be allowed in iOS. When that is, just comment this line out.
118  
-    // March 25th 2012: this day has come, let's remove this "outlawed" call... 
  121
+    // March 25th 2012: this day has come, let's remove this "outlawed" call...
  122
+    // August 2012: well, perhaps much ado about nothing; in any case WWDC2012 gave us something to work with; read below
119 123
 #if TARGET_OS_IPHONE	
120 124
 //    if([UIDevice instancesRespondToSelector:@selector(uniqueIdentifier)]){
121 125
 //        _openUDID = [[UIDevice currentDevice] uniqueIdentifier];
122 126
 //    }
123 127
 #endif
  128
+    
  129
+    //
  130
+    // !!!!! IMPORTANT README !!!!!
  131
+    //
  132
+    // August 2012: iOS 6 introduces new APIs that help us deal with the now deprecated [UIDevice uniqueIdentifier]
  133
+    // Since iOS 6 is still pre-release and under NDA, the following piece of code is meant to produce an error at
  134
+    // compile time. Accredited developers integrating OpenUDID are expected to review the iOS 6 release notes and
  135
+    // documentation, and replace the underscore ______ in the last part of the selector below with the right
  136
+    // selector syntax as described here (make sure to use the right one! last word starts with the letter "A"):
  137
+    // https://developer.apple.com/library/prerelease/ios/#documentation/UIKit/Reference/UIDevice_Class/Reference/UIDevice.html
  138
+    //
  139
+    // The semantic compiler warnings are still normal if you are compiling for iOS 5 only since Xcode will not
  140
+    // know about the two instance methods used on that line; the code running on iOS will work well at run-time.
  141
+    // Either way, it's time that you junped on the iOS 6 bandwagon and start testing your code on iOS 6 ;-)
  142
+    //
  143
+    // WHAT IS THE SIGNIFICANCE OF THIS CHANGE?
  144
+    //
  145
+    // Essentially, this means that OpenUDID will keep on behaving the same way as before for existing users or
  146
+    // new users in iOS 5 and before. For new users on iOS 6 and after, the new official public APIs will take over.
  147
+    // OpenUDID will therefore be obsoleted when iOS reaches significant adoption, anticipated around mid-2013.
  148
+
  149
+
  150
+#if TARGET_OS_IPHONE
  151
+    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6.0")) {
  152
+        _openUDID = [[[UIDevice currentDevice] identifierForA_______] UUIDString];
  153
+# error                                                         ^ read comments above, fix accordingly, and remove this #error line
  154
+    }
  155
+#endif
  156
+    
  157
+    
124 158
     // Next we generate a UUID.
125  
-    // UUIDs (Universally Unique Identifiers), also known as GUIDs (Globally Unique Identifiers) or IIDs 
  159
+    // UUIDs (Universally Unique Identifiers), also known as GUIDs (Globally Unique Identifiers) or IIDs
126 160
     // (Interface Identifiers), are 128-bit values guaranteed to be unique. A UUID is made unique over 
127 161
     // both space and time by combining a value unique to the computer on which it was generated—usually the
128 162
     // Ethernet hardware address—and a value representing the number of 100-nanosecond intervals since 
@@ -181,13 +215,14 @@ + (NSString*) valueWithError:(NSError **)error {
181 215
     
182 216
     // The AppUID will uniquely identify this app within the pastebins
183 217
     //
184  
-    NSString * appUID = (NSString *) [defaults objectForKey:kOpenUDIDAppUIDKey];
  218
+    NSString * appUID = [defaults objectForKey:kOpenUDIDAppUIDKey];
185 219
     if(appUID == nil)
186 220
     {
187 221
       // generate a new uuid and store it in user defaults
188  
-      CFUUIDRef uuid = CFUUIDCreate(NULL);
189  
-      appUID = (NSString *) CFUUIDCreateString(NULL, uuid);
190  
-      CFRelease(uuid);
  222
+        CFUUIDRef uuid = CFUUIDCreate(NULL);
  223
+        appUID = (NSString *) CFUUIDCreateString(NULL, uuid);
  224
+        CFRelease(uuid);
  225
+        [appUID autorelease];
191 226
     }
192 227
   
193 228
     NSString* openUDID = nil;

0 notes on commit 4b566c1

Please sign in to comment.
Something went wrong with that request. Please try again.