uniqueIdentifier 已弃用,来自 Cocos2d 的示例

发布于 2024-12-18 01:29:50 字数 2009 浏览 2 评论 0原文

我在网上搜索了答案,并找到了很多解决方案,但不得不承认我不太明白,因为我很新,如何应用答案,一个例子是: UIDevice uniqueIdentifier 已弃用 - 现在该怎么办?

如果有人可以向我展示一个示例,我将非常感激要将解决方案应用于下面代码中的问题,因为不推荐使用以下行(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;
}

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;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冰雪之触 2024-12-25 01:29:50

下面是快速简单的解决方案:

将项目(或目标)的部署目标更改为 iOS 4.x 或更低版本。在这种情况下,编译器仍然会发出警告,但它只是一个警告。仅当您的部署目标是 iOS 5.0 或更高版本时,编译器才会生成有关已弃用方法的错误。

至于Cocos2D源代码中的警告,请忽略这些警告,直到下一个Cocos2D官方版本修复该问题。

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.

深海蓝天 2024-12-25 01:29:50

你可以这样做:

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)
}

我刚刚注意到这个答案也可以找到

顺便说一句,如果在设备上卸载并重新安装应用程序,此 UUID 将不会持续存在(或相同)。如果您想要类似的东西,请合并在以下位置找到的代码:

https: //github.com/gekitz/UIDevice-with-UniqueIdentifier-for-iOS-5

除了本例之外,显然存在严格的许可协议。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文