gpt4 book ai didi

ios - 执行优先级非常低的代码

转载 作者:行者123 更新时间:2023-11-29 02:46:48 24 4
gpt4 key购买 nike

我知道两种在后台执行某些操作的方法。

1:

[self performSelectorInBackground:<#(SEL)#> withObject:<#(id)#>]

2:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
...
});

这两种方法都帮不了我。我正在向 Game Center 报告玩家的游戏得分,当我这样做时,在 iPod 4G 等旧设备上的游戏玩法明显滞后。但其实并不着急。是否可以使此代码以低 CPU 利用率执行?我在游戏结束后这样做,但用户可以立即重新开始游戏,他会看到大约 2 秒的小延迟。

成绩报告代码:

- (void) reportScore:(int64_t)score forLeaderboardID:(NSString*)category newBestTime:(BOOL)newBestTime {
GKScore *scoreReporter = [[GKScore alloc] initWithCategory:category];
scoreReporter.value = score;
scoreReporter.context = 0;
[scoreReporter reportScoreWithCompletionHandler:^(NSError *error) {
//nothing here
}];
}

最佳答案

使用低优先级队列:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
...
});

关于ios - 执行优先级非常低的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25016705/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com