Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unique Identifier for both mobile safari and in app in iOS

Tags:

ios

iphone

I'm looking to uniquely identify an iPhone so our server can respond with some custom html. I want to be able to identify the phone in Safari and in an embedded browser in the app. Since each application is sandboxed, cookies won't work.

Thanks

like image 494
Arvin Am Avatar asked Feb 08 '12 16:02

Arvin Am


People also ask

What is a unique device identifier iPhone?

A unique device identifier (UDID) is a 40-character string assigned to certain Apple devices including the iPhone, iPad, and iPod Touch. Each UDID character is a numeral or a letter of the alphabet. Using the UDID, third parties, particularly app vendors, can track subscriber behavior.

What is an identifier in an app?

A unique identifier is a serial number, or string of characters, specific to a user's mobile device.

How do I identify a device in iOS Swift?

Basic Swift Code for iOS AppsEvery iOS Device has UDID which is a sequence of 40 letters and numbers that is guaranteed to be specific to your device. Device name is generally a name which will find in the device Setting→ General→ About. iOS Model describes whether the iOS device which user is using is an iPhone/iPad.

How can you identify a uniquely device?

Use UUID UUID. randomUUID() method generates an unique identifier for a specific installation. You have just to store that value and your user will be identified at the next launch of your application.


1 Answers

This is not directly possible, but with the cooperation of the web site it is possible as Nick Lockwood has stated, and here's a greatly expanded version of the method he describes:

Your app should do this:

  1. Launch mobile safari, using [[UIApplication sharedApplication] openURL:url];
  2. The URL should be a special one, eg. http://yourwebsite.com/give-ios-app-the-cookie
  3. On your website, when that url is launched, issue a redirect to your-app-url-scheme:cookievalue=<somevalue> (eg. angrybirds:cookievalue=hh4523523sapdfa )
  4. when your app delegate receives - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation process the url to get the cookie value

Note that you should not do this automatically when the application starts - the user will see the transfer to Mobile Safari and back, which is not a good user experience and Apple will reject your app (Apple also consider this to be "uploading user's personal data to server without their prior consent").

It would be better to do it in response to the user, paying attention to the user experience - eg. wait for the user to hit a "login" button, then do it, and if the user is not logged into your website, http://yourwebsite.com/give-ios-app-the-cookie should show the user the login screen within safari. If the user is logged in you could briefly show a "Automatically logging you in..." screen for a second or two in Safari before redirecting the user back.

like image 138
JosephH Avatar answered Sep 21 '22 10:09

JosephH