6

I want to be collecting both the installation event (on the new app) and the account creation event (on all the old apps).

To ensure uniqueness and prevent fraud (that is each installation should correspond to a unique device, and should remain the same event if the app is un-installed and re-installed again on the same device) we can use hardware identifiers that can survive uninstall.

On android phone IMEI can be used as unique identifier, but this solution is not repeatable on iOS as Apple does not give access to any hardware or unique identifier for privacy reason.

I tried the approaches proposed in the following links:

  1. link1

  2. link2

  3. link3

    From link 1 & 3 I tried:

    let deviceID = UIDevice.current.identifierForVendor!.uuidString

But this does not provide a unique ID that will remain the same once the app is un-installed and re-installed again.

Please is there a better approach for me to handle this issue in swift. Thank you!

Community
  • 1
  • 1
Foutse
  • 125
  • 1
  • 10

3 Answers3

3

You can use Device Check API introduced in iOS 11, if you want to identify user's device even if user reinstalls your app.

Your server can use the generated token on the apple device. for more details please refer the following documentation

https://developer.apple.com/documentation/devicecheck/dcdevice/2902276-generatetoken

Abhishek
  • 3,304
  • 4
  • 30
  • 44
1

After UUID deprication there is no way 100% accomplish that , you can store an identifier in keychain but starting from iOS 10.3 , when you delete the app , all associated keychain items will be deleted

Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87
0

Currently there is no way(Before iOS 5 it was) to get static UDID or any device related ID. I also gone through this problem and I did followings to achieve.

  1. Create own random number

    - (NSMutableString*)getSecureGeneratedNumber
    {
        uint8_t randomBytes[16];
        int randomNumber = SecRandomCopyBytes(kSecRandomDefault, 16, randomBytes);
        NSMutableString *uuidStringReplacement;
        if(randomNumber == 0) {
            uuidStringReplacement = [[NSMutableString alloc] initWithCapacity:16*2];
            for(NSInteger index = 0; index < 16; index++)
            {
                [uuidStringReplacement appendFormat: @"%02x", randomBytes[index]];
            }
            NSLog(@"uuidStringReplacement is %@", uuidStringReplacement);
        } else {
            return 0;
            NSLog(@"SecRandomCopyBytes failed for some reason");
        }
        return uuidStringReplacement;
    }
    
  2. Save this random number in User Default or Keychain

    [[NSUserDefaults standardUserDefaults] setObject:randomNumber forKey:@"randomNum"];
    [[NSUserDefaults standardUserDefaults]synchronize];
    
rmaddy
  • 314,917
  • 42
  • 532
  • 579
Aleem
  • 3,173
  • 5
  • 33
  • 71
  • Thank you for your answer, please can I get the swift version of this code? – Foutse Apr 05 '18 at 17:46
  • This code won't do what you're asking for. User defaults are cleared when the app is uninstalled. In recent versions of iOS (9+ or 10+, I can't remember which), the keychain is also cleared. – Rob Napier Apr 05 '18 at 17:54
  • I'm using this code and its working perfectly fine. As I mentioned Keychain or User Default you can use keychain if you want to keep data after uninstallation of app and its Keychain introduces around iOS8 and its bit old now, now a days most of apps minimum version support ios9 or 10 – Aleem Apr 06 '18 at 06:10