Save Usage History On Server Without Login Information .

Posted in: Blog

An iOS App was developed which is based on a questionnaire (with some multimedia content) for users who are feeling physical pain or discomfort. The app was intended to be used for quick relief of unwanted feeling, and didn’t require any Login/Sign up.

Problem:

After the completion of questionnaire, users can optionally maintain a usage history of application. The implementation challenge here was to save this usage history on server without any user Login information.

Available Solutions:

After some discussions on available solutions with Client, our team decided to consider each device as a single user, and history data can be saved against each Device ID. Apple has already provided a set of APIs to use Device ID. The long time used method uniqueIdentifier was no more available, as it was deprecated in iOS 5 and above. So the alternative method is identifierForVendor that provides a unique ID for each vendor running on a specific device.

identifierForVendor provided a unique ID that was used to maintain usage history on server, but ID value was not retained if the user uninstall and then re-install the application. Upon re-installation, it provides another (new) ID that was different from previous ID. Hence, providing multiple IDs for a single device.

Implemented Solution:

When the application gets the unique ID with identifierForVendor first time, it saves it at some permanent place where it can be retrieved from, even if application is re-installed later. So application could re-use the previously installed unique ID, instead of creating a new one on each installation. Apple provides this place called as Keychain Services, which provides secure storage of passwords, keys, certificates, and notes for users. So application saves unique ID in Keychain Services only at first time. When a user re-installs the application, it uses unique ID already saved in Keychain Services. This solved the problem of getting multiple IDs for a single device, and was used for maintaining usage history on server.

We implemented Keychain Services by using a 3rd party library UICKeyChainStore, which makes Keychain Services easy to use. We used the following code to save the device ID in Keychain:

UICKeyChainStore *store = [UICKeyChainStore keyChainStoreWithService:@"com.yourCompany.appName"];
NSString *deviceId = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
store setString:deviceId forKey:@"UniqueIdentiferForApp"];
[store synchronize];

 

Leave a Reply

Your email address will not be published. Required fields are marked *