NSUserDefaults Save Data copied while App transfer in new Device

Dear Team,

For our application we are using NSUserDefaults to save and retrieve the user basic information in device storage. While transferring the application from one iPhone to another iPhone whole NSUserDefaults save data copied to other devices, due to this in another/new device user is able to use application without new/fresh registration.

We required new/fresh registration when application is transfer from one iPhone to another iPhone. Please help in below quires.

  1. How to stop NSUserDefaults data coping from one device to another devices
  2. Is there is any other way to save data which will not copy to other device while app transfer using iPhone default feature.
  3. We are saving unique device identifier in Keychain. Is there any other best way to save unique device identifier in device which can remain same while app uninstall and in case of app upgrade.

Thanks in advance.

The last time I experimented with this, data in NSUserDefaults gets transferred but not data in the keychain. If that's the case, then can't you just check that the device identifier in the keychain is present or not, and if not then you require the fresh registration.

There are a number of different scenarios in play here:

  • The user restoring a backup to the same device.

  • The user restoring a backup to a different device.

  • The user transferring their ‘world’ from one device to another using Quick Start.

  • The user removing and then re-installing your app.

What behaviour are you looking for in each case?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Thanks for quick response.

We have below scenarios.

The user restoring a backup to a different device. The user transferring their ‘world’ from one device to another using Quick Start.

Please let me know how to resolve this

The user restoring a backup to a different device. The user transferring their ‘world’ from one device to another using Quick Start.

You can detect both of these using a this-device-only keychain item. For more background on this, see the kSecAttrAccessible docs.

IMPORTANT The keychain is intended to be used to store small chunks of data. I’m assuming that “user basic information” is small enough to qualify, so less than a KiB. I you need to store larger data, put it in a file and store the encryption key for that file in the keychain.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Thanks for quick reply.

We are updating the exiting Keychain using below code. Please let us know is this approach is correct or any other way is there?

Can you please give more lights on below points

  1. Can we stop coping the application from one phone to another phone.
  2. How can we test the same without uploading app on App Store


`// code spinnets `
 [[[KeychainItemWrapper_utils alloc] initWithIdentifier:@"AC_APP_UUID" accessGroup:nil] resetKeychainItem];
   [[[KeychainItemWrapper_utils alloc] initWithIdentifier:@"KEY_APP_UUID" accessGroup:nil] resetKeychainItem];
   NSString *uuid;
   KeychainItemWrapper_utils *keychain = [[KeychainItemWrapper_utils alloc] initWithIdentifier:keyName accessGroup:nil];
//   [keychain setObject:(id)kSecAttrAccessibleWhenUnlockedThisDeviceOnly forKey:(id)kSecAttrAccessible];
//
   
   NSDictionary *updatedAttr = @{ (id)kSecAttrAccessible : (id)kSecAttrAccessibleWhenUnlockedThisDeviceOnly };
    NSDictionary *query = @{
                (id)kSecClass : (id)kSecClassIdentity,
                (id)kSecAttrAccessible : (id)kSecAttrAccessibleWhenUnlockedThisDeviceOnly
                };
    OSStatus ret = SecItemUpdate((__bridge CFDictionaryRef)query,
                   (__bridge CFDictionaryRef)updatedAttr);
   switch (ret)
    {
     case   errSecSuccess:
      NSLog(@"success");
      break;
     case errSecItemNotFound:
      NSLog(@"no items to update");
      break;
     default:
     {
      NSError *error = [NSError errorWithDomain:NSOSStatusErrorDomain code:ret userInfo:nil];
      NSLog(@"couldn't update items, error=%@", error);
     }
      break;
    }
  

  1. Can we stop [copying] the application from one phone to another phone.

I don’t undertand what you mean by this. How can a user copy the app from one phone to another? What’s the user-level process they would take?

On macOS you can do that using AirDrop and so on, but on iOS you can only install an app from the App Store [1] [2].

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] Well, that’s enterprise distribution as well but it seems like you’re focused on standard users and thus App Store deployment.

[2] Oh, there’s also TestFlight but that behaves much like the App Store.

NSUserDefaults Save Data copied while App transfer in new Device
 
 
Q