Reputation: 4301
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;
}
Upvotes: 1
Views: 3938
Reputation: 64477
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.
Upvotes: 5
Reputation: 89559
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.
Upvotes: 1