我在网上搜索了答案并找到了不少解决方案,但不得不承认我并不理解,因为我很新,如何应用答案,一个例子是:UIDevice uniqueIdentifier Deprecated - What To Do Now? < / p>
我真的很感激,如果有人可以向我展示如何在下面的代码中将解决方案应用于该问题的示例,因为以下行已弃用(uniqueIdentifier),代码行来自Cocos2d CLScoreServerRequest.m但是出现在其他人也很少:
device = [[UIDevice currentDevice] uniqueIdentifier];
该功能如下:
-(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;
}
答案 0 :(得分:5)
以下是快速简单的解决方案:
将项目(或目标)的部署目标更改为iOS 4.x或更低版本。在这种情况下,编译器仍会发出警告,但它只是一个警告。只有当您的部署针对iOS 5.0或更高版本时,编译器才会生成有关已弃用方法的错误。
至于Cocos2D源代码中的警告,请忽略这些警告,直到下一个Cocos2D官方发布版修复该问题为止。
答案 1 :(得分:1)
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)
}
我刚刚注意到这个答案也可以找到in this related question。
B.T.W。,如果在设备上卸载并重新安装该应用程序,则此UUID将不会保留(或相同)。如果你想要这样的东西,你可以在下面找到代码:
https://github.com/gekitz/UIDevice-with-UniqueIdentifier-for-iOS-5
除非在这种情况下,显然存在严格的许可协议。