Coder Social home page Coder Social logo

Comments (2)

ylechelle avatar ylechelle commented on August 16, 2024

Are you using the latest version? The identifier is indeed 36 chars, see the code below:

+ (NSString*) _generateFreshOpenUDID {

    NSString* _openUDID = nil;

    // August 2011: One day, this may no longer be allowed in iOS. When that is, just comment this line out.
    // March 25th 2012: this day has come, let's remove this "outlawed" call... 
#if TARGET_OS_IPHONE    
//    if([UIDevice instancesRespondToSelector:@selector(uniqueIdentifier)]){
//        _openUDID = [[UIDevice currentDevice] uniqueIdentifier];
//    }
#endif
    // Next we generate a UUID.
    // UUIDs (Universally Unique Identifiers), also known as GUIDs (Globally Unique Identifiers) or IIDs 
    // (Interface Identifiers), are 128-bit values guaranteed to be unique. A UUID is made unique over 
    // both space and time by combining a value unique to the computer on which it was generated—usually the
    // Ethernet hardware address—and a value representing the number of 100-nanosecond intervals since 
    // October 15, 1582 at 00:00:00.
    // We then hash this UUID with md5 to get 32 bytes, and then add 4 extra random bytes
    // Collision is possible of course, but unlikely and suitable for most industry needs (e.g. aggregate tracking)
    //
    if (_openUDID==nil) {
        CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault);
        CFStringRef cfstring = CFUUIDCreateString(kCFAllocatorDefault, uuid);
        const char *cStr = CFStringGetCStringPtr(cfstring,CFStringGetFastestEncoding(cfstring));
        unsigned char result[16];
        CC_MD5( cStr, strlen(cStr), result );
        CFRelease(uuid);

        _openUDID = [NSString stringWithFormat:
                @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%08x",
                result[0], result[1], result[2], result[3], 
                result[4], result[5], result[6], result[7],
                result[8], result[9], result[10], result[11],
                result[12], result[13], result[14], result[15],
                arc4random() % 4294967295];  
    }

    // Call to other developers in the Open Source community:
    //
    // feel free to suggest better or alternative "UDID" generation code above.
    // NOTE that the goal is NOT to find a better hash method, but rather, find a decentralized (i.e. not web-based)
    // 160 bits / 20 bytes random string generator with the fewest possible collisions.
    // 

    return _openUDID;
}

from openudid.

shalupandey avatar shalupandey commented on August 16, 2024

No..i am using the code before this change is been done ( commented the //
_openUDID = [[UIDevice currentDevice] uniqueIdentifier]; // } ).

But the point is there must be other apps also which will be using the
older code and hence generating 40 char id. And when my app tries to read
it, 40 char id id being returned. Because code is trying to read the value
stored by other apps and if not found then only generate..am i correct?

Please suggest if my understanding is wrong..

Thanks a lot...
On Jun 20, 2012 4:40 PM, "Yann Lechelle" <
[email protected]>
wrote:

Are you using the latest version? The identifier is indeed 36 chars, see
the code below:

+ (NSString*) _generateFreshOpenUDID {

   NSString* _openUDID = nil;

   // August 2011: One day, this may no longer be allowed in iOS. When
that is, just comment this line out.
   // March 25th 2012: this day has come, let's remove this "outlawed"
call...
#if TARGET_OS_IPHONE
//    if([UIDevice instancesRespondToSelector:@selector
(uniqueIdentifier)]){
//        _openUDID = [[UIDevice currentDevice] uniqueIdentifier];
//    }
#endif
   // Next we generate a UUID.
   // UUIDs (Universally Unique Identifiers), also known as GUIDs
(Globally Unique Identifiers) or IIDs
   // (Interface Identifiers), are 128-bit values guaranteed to be unique.
A UUID is made unique over
   // both space and time by combining a value unique to the computer on
which it was generated—usually the
   // Ethernet hardware address—and a value representing the number of
100-nanosecond intervals since
   // October 15, 1582 at 00:00:00.
   // We then hash this UUID with md5 to get 32 bytes, and then add 4
extra random bytes
   // Collision is possible of course, but unlikely and suitable for most
industry needs (e.g. aggregate tracking)
   //
   if (_openUDID==nil) {
       CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault);
       CFStringRef cfstring = CFUUIDCreateString(kCFAllocatorDefault,
uuid);
       const char *cStr =
CFStringGetCStringPtr(cfstring,CFStringGetFastestEncoding(cfstring));
       unsigned char result[16];
       CC_MD5( cStr, strlen(cStr), result );
       CFRelease(uuid);

       _openUDID = [NSString stringWithFormat:

 @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%08x",
               result[0], result[1], result[2], result[3],
               result[4], result[5], result[6], result[7],
               result[8], result[9], result[10], result[11],
               result[12], result[13], result[14], result[15],
               arc4random() % 4294967295];
   }

   // Call to other developers in the Open Source community:
   //
   // feel free to suggest better or alternative "UDID" generation code
above.
   // NOTE that the goal is NOT to find a better hash method, but rather,
find a decentralized (i.e. not web-based)
   // 160 bits / 20 bytes random string generator with the fewest possible
collisions.
   //

   return _openUDID;
}

Reply to this email directly or view it on GitHub:
#35 (comment)

from openudid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.