I have searched the web for the answer and have found quite a few solutions but have to admit i do not really understand, as i am pretty new, how to apply the answer, one example is: UIDevice uniqueIdentifier Deprecated - What To Do Now?
I would really appreciate if someone could show me an example how to apply the solution to the problem in the code below as the following line is deprecated (uniqueIdentifier), the code line is from Cocos2d CLScoreServerRequest.m but comes up in a few others as well:
device = [[UIDevice currentDevice] uniqueIdentifier];
The function looks like:
-(BOOL) requestScores:(tQueryType)type
limit:(int)limit
offset:(int)offset
flags:(tQueryFlags)flags
category:(NSString*)category
{
// create the request
[receivedData setLength:0];
// it's not a call for rank
reqRankOnly = NO;
NSString *device = #"";
if( flags & kQueryFlagByDevice )
device = [[UIDevice currentDevice] uniqueIdentifier];
// arguments:
// query: type of query
// limit: how many scores are being requested. Default is 25. Maximun is 100
// offset: offset of the scores
// flags: bring only country scores, world scores, etc.
// category: string user defined string used to filter
NSString *url= [NSString stringWithFormat:#"%#?gamename=%#&querytype=%d&offset=%d&limit=%d&flags=%d&category=%#&device=%#",
SCORE_SERVER_REQUEST_URL,
gameName,
type,
offset,
limit,
flags,
[category stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding],
device
];
// NSLog(#"%#", url);
NSURLRequest *request=[NSURLRequest requestWithURL:[NSURL URLWithString:url]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:10.0];
// create the connection with the request
// and start loading the data
self.connection=[NSURLConnection connectionWithRequest:request delegate:self];
if (! connection_)
return NO;
return YES;
}
Here's the quick and simple solution:
Change your project's (or target's) deployment target to iOS 4.x or lower. In that case the compiler will still issue a warning but it will be just a warning. Only if your deployment target it iOS 5.0 or newer will the compiler generate an error about the deprecated method.
As for the warnings within the Cocos2D source code, ignore those warnings until the next Cocos2D official release fixes that issue.
you could do:
CFUUIDRef uuidRef = CFUUIDCreate(kCFAllocatorDefault);
if(uuidRef)
{
device = (NSString *) CFUUIDCreateString(kCFAllocatorDefault, uuid);
CFRelease(uuidRef);
} else {
// it's almost 100% likely you won't end up here but
// you should still do something with device (like throw an alert or NSLog)
}
And I just noticed this answer can also be found in this related question.
B.T.W., this UUID will not persist (or be the same) if the app is uninstalled and reinstalled on a device. If you want something like that, you incorporate the code found at:
https://github.com/gekitz/UIDevice-with-UniqueIdentifier-for-iOS-5
Except in this case, there's apparently a tough license agreement.
Related
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
I want unique identifier string for iPhone devices instead of UDID and MAC.
1. Get UDID and MAC are deprecated by apple.
2. We can use UUID but it will get change after reinstalling app or delete app.
I want any unique value of device which is remain same after app reinstall OR delete OR upgrade iOS version.
What you can do is get a unique identifier using [[UIDevice currentDevice] identifierForVendor]or any other unique identifier generator. After that, you should store that value on keychain using KeychainItemWrapper and use. Once you store a value on the keychain it'll not remove even after you delete and reinstall the app.
Here is a guide for keychain access - Link
Try
[[UIDevice currentDevice] identifierForVendor];
It is from iOS 6.
As #danypata said, use the identifierForVendor as described in this answer.
Or alternatively you might be able to use the advertising NSUDID as described here.
However these can come back as nil or be changed over time. The user can opt out of advertiser tracking, so I don't recommend using it to track users for your own purposes.
I guess it depends on why you are tracking their device in the first place. My attitude is that I don't need to track users habits FOREVER. I only need to track general user trends and some DAU info. So I make up my own UDID - which will change on each install of the app. In my next version I will use the identifierForVendor and if it's NIL I will make up my own.
This is how I make my own:
// this makes a device id like: UUID = 89CD872F-C9AF-4518-9E6C-A01D35AF091C
// except that I'm going to attach some other attributes to it like the OS version, model type, etc.
// the UUID that is stored in user defaults will be like the one above.. but the device id that gets returned
// from this function and sent to [my online system] will have the extra info at the end of the string.
- (void) createUUID {
// for collecting some data.. let's add some info about the device to the uuid
NSString *thisDeviceID;
NSString *systemVersion = [[UIDevice currentDevice]systemVersion];
NSString *model = [[UIDevice currentDevice]model];
NSString *retinaTag;
if (retina) {
retinaTag = #"Retina";
}
else {
retinaTag = #"";
}
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
id uuid = [defaults objectForKey:#"uniqueID"];
if (uuid)
thisDeviceID = (NSString *)uuid;
else {
CFStringRef cfUuid = CFUUIDCreateString(NULL, CFUUIDCreate(NULL));
thisDeviceID = (__bridge NSString *)cfUuid;
CFRelease(cfUuid);
[defaults setObject:thisDeviceID forKey:#"uniqueID"];
}
//NSLog(#"UUID = %#", thisDeviceID);
MYthisDeviceID = [NSString stringWithFormat:#"%#-%#-%#-%#",thisDeviceID,systemVersion,retinaTag,model];
//NSLog(#"UUID with info = %#", MYthisDeviceID);
}
Then the single string that gets sent to my server has both a UDID in it and specs about the device and os. Until the user completely deletes and reloads the app the stats show usage on that device. To not get double udids if they update to a new os you can crop to just the udid portion.
I don't use the mac address at all because it was my understanding that apple didn't want us to. Although I can't find any documentation that says it at the moment.
UPDATE for iOS7:
I now use this code which works under io6 and io7:
NSString *globalDeviceID;
- (void) createUUID
{
NSString *thisDeviceID;
NSString *systemVersion = [[UIDevice currentDevice]systemVersion];
NSString *model = [[UIDevice currentDevice]model];
NSString *retinaTag;
if (retina) {
retinaTag = #"Retina";
}
else {
retinaTag = #"";
}
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
id uuid = [defaults objectForKey:#"deviceID"];
if (uuid)
thisDeviceID = (NSString *)uuid;
else {
if ([[UIDevice currentDevice] respondsToSelector:#selector(identifierForVendor)]) {
thisDeviceID = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
}
else
{
CFStringRef cfUuid = CFUUIDCreateString(NULL, CFUUIDCreate(NULL));
thisDeviceID = (__bridge NSString *)cfUuid;
CFRelease(cfUuid);
}
[defaults setObject:thisDeviceID forKey:#"deviceID"];
}
NSLog(#"UUID = %#", thisDeviceID);
globalDeviceID = [NSString stringWithFormat:#"%#-%#-%#-%#",thisDeviceID,systemVersion,retinaTag,model];
NSLog(#"UUID with info = %#", globalDeviceID);
}
Or simply use the following and store to NSUserDefaults
[NSProcessInfo processInfo].globallyUniqueString
Global ID for the process. The ID includes the host name, process ID, and a time stamp, which ensures that the ID is unique for the network.
I'd suggest having a look at OpenUDID.
I believe underneath it uses the MAC address, so if you are correct in saying that accessing the MAC address is deprecated, then it probably won't be of much use, however, I think it would be unreasonable of Apple to remove access; the MAC address has other applications that just identifying the device for the purposes of UDID
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.
I just added In-App Purchasing to my iOS app and a few of my users are crashing out with
-[__NSCFString objectForKey:]: unrecognized selector sent to instance 0xf0a6f10
Obtained from BugSense, the memory location refers to the last line of this excerpt from Apple's VerificationController.m
- (BOOL)isTransactionAndItsReceiptValid:(SKPaymentTransaction *)transaction
{
if (!(transaction && transaction.transactionReceipt && [transaction.transactionReceipt length] > 0))
{
// Transaction is not valid.
return NO;
}
// Pull the purchase-info out of the transaction receipt, decode it, and save it for later so
// it can be cross checked with the verifyReceipt.
NSDictionary *receiptDict = [self dictionaryFromPlistData:transaction.transactionReceipt];
NSString *transactionPurchaseInfo = [receiptDict objectForKey:#"purchase-info"];
...
receiptDict is generated by this code (also included in VerificationController.m)
- (NSDictionary *)dictionaryFromPlistData:(NSData *)data
{
NSError *error;
NSDictionary *dictionaryParsed = [NSPropertyListSerialization propertyListWithData:data
options:NSPropertyListImmutable
format:nil
error:&error];
if (!dictionaryParsed)
{
if (error)
{
#warning Handle the error here.
}
return nil;
}
return dictionaryParsed;
}
which should return an NSDictionary or nil.
ARC is turned on. This problem seems to only occur with iOS 5.0.1 users. While I did make necessary changes to VerificationController.m, this part has been untouched. I can't seem to replicate the problem on my iPad running iOS 5.1.1, but users have said that it is persistent even after reinstalling the app. If anyone can see something simple that I'm not doing right, I'd appreciate it.
EDIT
Follow up question. What does it mean when
- (BOOL)isTransactionAndItsReceiptValid:(SKPaymentTransaction *)transaction
transaction.transactionReceipt
only provides an NSString and is it safe to ignore?
looks like to me
propertyListWithData:data options:NSPropertyListImmutableformat:nil error:&error];
return a string not a dictionary but it doesnt seems logic. are you sure the problem come from this?
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.