Alternative to iPhone device ID (UDID) [duplicate] - iphone

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
UIDevice uniqueIdentifier Deprecated - What To Do Now?
Even if Apple was not at Barcelone's MWC (mobile world congress), there was the certitude that getting the deviceID will be deprecated in further iOS SDK.
I do not understand why Apple want to restrict this, but that's not the topic.
I must prepare my application to an alternative because my users are identified and known for a better use of my app (don't need to log, or create an account, for example). And I'm sure I'm not alone in that case.
So anybody know an alternative from getting the deviceID ? Is there other unique identifier, like MAC address, for example ? How do you prepare your app ?

UPDATE
What about using CFUUID to generate a UUID. You can than store it in KEYCHAIN on the very first launch..
you can get it like this...
NSString *uuid = nil;
CFUUIDRef theUUID = CFUUIDCreate(kCFAllocatorDefault);
if (theUUID) {
uuid = NSMakeCollectable(CFUUIDCreateString(kCFAllocatorDefault, theUUID));
[uuid autorelease];
CFRelease(theUUID);
}
and also by deprecating the uniqueIdentifier method, Apple is suggesting that you don't identify per device but instead per app install. may be tomorrow they might decide to reject your app for doing this .. :/
hoping this helps.

try this
- (NSString *)getDeviceID
{
NSString *uuid = [self gettingString:#"uniqueAppId"];
if(uuid==nil || [uuid isEqualToString:#""])
{
CFUUIDRef theUUID = CFUUIDCreate(kCFAllocatorDefault);
if (theUUID)
{
uuid = NSMakeCollectable(CFUUIDCreateString(kCFAllocatorDefault, theUUID));
[self savingString:#"uniqueAppId" data:uuid];
[uuid autorelease];
CFRelease(theUUID);
}
}
return uuid;
// this is depreciated
// UIDevice *device = [UIDevice currentDevice];
// return [device uniqueIdentifier];
}

Please implement the new logic to get Secure UDID.it is provided by Third Party
Learn about free solution:
This really works fine and is easy to implememt without making it a fuss to replace the deprecated method.

Related

How to generate unique identifier which should work in all iOS versions?

I want to get the unique identifier which should support all iOS versions..Can any one help me on this issue. As you know that apple is deprecated the UDID method, So there is possibility to generate Unique id using wifi-mac address.But apple is going to remove the wifi mac address in iOS7 version.So my requirement is to generate a new unique code which should work in all iOS versions.Thanks in advance..
Note: Don't change the UDID once user restart the device or reinstall the application.
I was updating my application that was working based only on Unique Identifier which supported iOS 4.3 and above. So,
1) I was unable to use [UIDevice currentDevice].uniqueIdentifier; as it was no longer available
2) I could not use [UIDevice currentDevice].identifierForVendor.UUIDString because it was Available in iOS 6.0 and later only and was unable to use for lower iOS versions.
3) The mac address was not an option as it wasn't allowed in iOS-7
4) OpenUDID was deprecated some time ago and also had issues with iOS-6.
5) Advertisement identifiers were also not available for iOS-5 and below
Finally this was what i did
a) Added SFHFKeychainUtils to the project
b) Generated CFUUID key String
CFUUIDRef cfuuid = CFUUIDCreate(kCFAllocatorDefault);
udidString = (NSString*)CFBridgingRelease(CFUUIDCreateString(kCFAllocatorDefault, cfuuid));
c) Saved it to Key Chain Utils or else it will generate a new Unique Each Time
Final Code
+ (NSString *)GetDeviceID {
NSString *udidString;
udidString = [self objectForKey:#"deviceID"];
if(!udidString)
{
CFUUIDRef cfuuid = CFUUIDCreate(kCFAllocatorDefault);
udidString = (NSString*)CFBridgingRelease(CFUUIDCreateString(kCFAllocatorDefault, cfuuid));
CFRelease(cfuuid);
[self setObject:udidString forKey:#"deviceID"];
}
return udidString;
}
+(void) setObject:(NSString*) object forKey:(NSString*) key
{
NSString *objectString = object;
NSError *error = nil;
[SFHFKeychainUtils storeUsername:key
andPassword:objectString
forServiceName:#"LIB"
updateExisting:YES
error:&error];
if(error)
NSLog(#"%#", [error localizedDescription]);
}
+(NSString*) objectForKey:(NSString*) key
{
NSError *error = nil;
NSString *object = [SFHFKeychainUtils getPasswordForUsername:key
andServiceName:#"LIB"
error:&error];
if(error)
NSLog(#"%#", [error localizedDescription]);
return object;
}
For further Details
Now Device Identifier change to UUID.You can get UUID With the help of following code:
- (NSString *)getUUID
{
NSString *UUID = [[NSUserDefaults standardUserDefaults] objectForKey:#"uniqueID"];
if (!UUID) {
CFUUIDRef theUUID = CFUUIDCreate(NULL);
CFStringRef string = CFUUIDCreateString(NULL, theUUID);
CFRelease(theUUID);
UUID = [(__bridge NSString*)string stringByReplacingOccurrencesOfString:#"-"withString:#""];
[[NSUserDefaults standardUserDefaults] setValue:UUID forKey:#"uniqueID"];
}
return UUID;
}
It's Work in all iOS version.
I don't have access to the code right now (can post in a few hours if you still need it) but what I've done is create a static method 'deviceIdentifier' in a helper class.
the method does a basic check for the current iOS version, returns UDID if below 6.0 and uniqueIdentifier otherwise
Let me know if you'd like the code for that and I'll post it when I can..it's only 10-15 lines or so if I remember right but makes a big difference as then you can just call '[myHelper deviceIdentifier]' wherever you need a device ID and not have to worry about which iOS version they are using

Are their any alternative for UDID? [duplicate]

This question already has answers here:
UIDevice uniqueIdentifier deprecated - What to do now?
(32 answers)
Closed 9 years ago.
As UDID has been deprecated are their any alternative ways for UDID?
You can use the following thing as a unique Identifier for your app user's :
I use the method below to create a UUID and save it to the user preferences the first time the app is started:
- (NSString *)getUUID
{
NSString *UUID = [[NSUserDefaults standardUserDefaults] objectForKey:#"uniqueID"];
if (!UUID)
{
CFUUIDRef theUUID = CFUUIDCreate(NULL);
CFStringRef string = CFUUIDCreateString(NULL, theUUID);
CFRelease(theUUID);
UUID = [(__bridge NSString*)string stringByReplacingOccurrencesOfString:#"-"withString:#""];
[[NSUserDefaults standardUserDefaults] setValue:UUID forKey:#"uniqueID"];
}
return UUID;
}
Hope that helps !
Apple stopped supporting a unique identifier for iOS. This source code solves the problem. It generates a unique identifier based on the mac address of the device in combination with the bundle identifier.
Please download the demo http://bit.ly/10SXhrO

Retrieve iOS device identifier

Is there any way to get the iOS device identifier in iOS SDK?
I would like to access the identifier which is presented by the Xcode in Organizer - Devices section, something like: 21xb1fxef5x2052xec31x3xd3x48ex5e437xe593
It looks like you still can access UDID under iOS 6, but it is deprecated since iOS 5.0 and you shouldn't use it (anyway you'll get warning about that)
[UIDevice currentDevice].uniqueIdentifier
If you need unique identifier you should rather use :
[UIDevice currentDevice].identifierForVendor
or if it is connected with some kind of advertisement then:
// from AdSupport.framework
[ASIdentifierManager sharedManager].advertisingIdentifier
However those two new properties are available only under iOS >= 6.0, also advertisingIdentifier is not really unique (I'm getting many duplicates from that).
I suppose that you can do something like that if you wan't to support also iOS < 6:
UIDevice *device = [UIDevice currentDevice];
NSString *ident = nil;
if ([device respondsToSelector:SEL(identifierForVendor)]) {
ident = [device.identifierForVendor UUIDString];
} else {
ident = device.uniqueIdentifier;
}
but I'm not sure how apple will respond to that during review.
You can also use some 3rd party solution like openUDID or secureUDID. Open and secure UDIDs are deprecated - use identifier for vendor/advertising.
Update
One more possibility is to use MAC address as a base for unique hash, for example you can use code from ODIN1 - source is here
As of iOS7 MAC address is no longer available. (one can read it but it'll be always same dummy address 02:00:00:00:00:00).
From the Apple Documentation:
An alphanumeric string unique to each device based on various hardware
details. (read-only) (Deprecated in iOS 5.0. Use the
identifierForVendor property of this class or the
advertisingIdentifier property of the ASIdentifierManager class
instead, as appropriate, or use the UUID method of the NSUUID class to
create a UUID and write it to the user defaults database.)
NSString* identifier = nil;
if( [UIDevice instancesRespondToSelector:#selector(identifierForVendor)] ) {
// iOS 6+
identifier = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
} else {
// before iOS 6, so just generate an identifier and store it
identifier = [[NSUserDefaults standardUserDefaults] objectForKey:#"identiferForVendor"];
if( !identifier ) {
CFUUIDRef uuid = CFUUIDCreate(NULL);
identifier = (__bridge_transfer NSString*)CFUUIDCreateString(NULL, uuid);
CFRelease(uuid);
[[NSUserDefaults standardUserDefaults] setObject:identifier forKey:#"identifierForVendor"];
}
}
you can find unique device identifier as
[[UIDevice currentDevice] uniqueIdentifier]
+ (NSString *)uuid
{
NSString *uuidString = nil;
CFUUIDRef uuid = CFUUIDCreate(NULL);
if (uuid) {
uuidString = (NSString *)CFUUIDCreateString(NULL, uuid);
CFRelease(uuid);
}
return [uuidString autorelease];
}
It works 100%, even on simulators too...
Yes there is.
[[UIDevice currentDevice] uniqueIdentifier]
EDIT:
However this is deprecated in iOS 5. This identifier should no longer be used in iOS 5. Read this SO post for more details.

Send a unique Identifier from IOS Device to a webservice [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Unique identifier for an iPhone app
We are building an IOS application that was intended to use the device's serial number as a unique identifier to identify if a device is licenced or not. But according to this the unique identifier is deprecated in iOS 5.
Is there any other identifier we could use to uniquely identify devices?
This is what I do, which is also Apple's suggestion
Do not use the uniqueIdentifier property. To create a unique identifier specific to your app, you can call the CFUUIDCreate function to create a UUID, and write it to the defaults database using the NSUserDefaults class.
- (NSString *)getUUID {
NSString *string = [[NSUserDefaults standardUserDefaults] objectForKey:#"deviceUUID"];
if (string == nil) {
CFUUIDRef uuid;
CFStringRef uuidStr;
uuid = CFUUIDCreate(NULL);
uuidStr = CFUUIDCreateString(NULL, uuid);
string = [NSString stringWithFormat:#"%#", uuidStr];
[[NSUserDefaults standardUserDefaults] setObject:string forKey:#"deviceUUID"];
[[NSUserDefaults standardUserDefaults] synchronize];
CFRelease(uuidStr);
CFRelease(uuid);
}
return string;
}
We tend to solve this with the cookies approach popularized on the web, where the same rule applies. Basically, your app should check for the existence of your cookie; if it's not there, ask the server for one and persist it locally. Then with every request, send along the identifier. It is the server's job to generate a sufficiently distinct identifier for each new device.
In this way, you can still track individual users, just not by knowing more about them than you need to.
I use this:
//create a 30 digits random alphanumeric string
NSString *symbols = #"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
NSMutableString *randStr = [NSMutableString stringWithCapacity: 30];
for (int i=0; i<30; i++)
[randStr appendFormat: #"%C", [symbols characterAtIndex: rand()%[symbols length]]];
NSLog(#"Pseudo UUID = %#", randStr);
The probability of getting duplicates is extra-minor.
You can use UDID to send server. its a Unique id for each device.like below and send this to the server.
NSString *udid=[[UIDevice currentDevice]uniqueIdentifier];

using a unique identifier of iPhone or iOS device

I am making an order booking app. I need to send a unique key from the iPhone/iOS device to the server.
Can I use GUID of iPhone? i.e [UIDevice uniqueIdentifier] Is it legal? Legal means will apple accept that?
What is the best property to use to uniquely identify an iPhone or iOS device?
If not then what would be the other way to uniquely identifying device.
Actually i need booking reference no. generated by app. must be unique.
Apple has announced that in May 2013 will start to reject application that use the UDID to track the user behavior
this is an alternative to the UDID:
You can create a category of UIApplication , UIDevice or as you prefere like this (ARC example)
#interface UIApplication (utilities)
- (NSString*)getUUID;
#end
#implementation UIApplication (utilities)
- (NSString*)getUUID {
NSUserDefaults *standardUserDefault = [NSUserDefaults standardUserDefaults];
static NSString *uuid = nil;
// try to get the NSUserDefault identifier if exist
if (uuid == nil) {
uuid = [standardUserDefault objectForKey:#"UniversalUniqueIdentifier"];
}
// if there is not NSUserDefault identifier generate one and store it
if (uuid == nil) {
uuid = UUID ();
[standardUserDefault setObject:uuid forKey:#"UniversalUniqueIdentifier"];
[standardUserDefault synchronize];
}
return uuid;
}
#end
UUID () is this function
NSString* UUID () {
CFUUIDRef uuidRef = CFUUIDCreate(NULL);
CFStringRef uuidStringRef = CFUUIDCreateString(NULL, uuidRef);
CFRelease(uuidRef);
return (__bridge NSString *)uuidStringRef;
}
this generate an unique identifier stored into the NSUserDefault to be reused whenever the application need it - This identifier will unique related to the application installs not to the device, but can be used for example to take trace about the number devices subscribed the APN service etc...
After that you can use it in this way:
NSString *uuid = [[UIApplication sharedApplication] getUUID];
There is no GUID that I am aware of, do you mean [UIDevice uniqueIdentifier]? You may use that, but it’s getting deprecated in iOS 5, so that you’d better come up with some other means of identificating your devices.
Create a UUID: A string containing a UUID. The standard format for UUIDs represented in ASCII is a string punctuated by hyphens, for example 68753A44-4D6F-1226-9C60-0050E4C00067.
+ (NSString *)newUUID
{
CFUUIDRef theUUID = CFUUIDCreate(NULL);
CFStringRef string = CFUUIDCreateString(NULL, theUUID);
CFRelease(theUUID);
return (NSString *)string;
}
I won't refer to what is under NDA, but give a try to this solution, as the author advertises "It generates a unique identifier based on the mac address of the device in combination with the bundle identifier." However be warned that jailbroken devices can change their mac address AFAIK.
With iOS 6 came identifierForVendor, it can be used across multiple apps from the same vendor and although it identifies a device you can use it in combination with iCloud's key-value store for example to identify the user across devices.
Ole Begemann explains it all nicely on his blog: http://oleb.net/blog/2012/09/udid-apis-in-ios-6/