gpt4 book ai didi

ios - 异步数据调用 & CoreAnimation

转载 作者:行者123 更新时间:2023-11-28 20:18:04 27 4
gpt4 key购买 nike

我目前正在这样做:

        NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];

然后我更新 UI 并运行大量动画来显示我刚收到的数据。

但是我现在尝试使用异步请求来加载信息,因为上述方法正在锁定主线程。

有什么想法吗?我试过设置 NSOperationQueue 并使用:

                NSData *responseGBP = [NSURLConnection sendAsynchronousRequest:requestGBP queue:operationQueue completionHandler:nil];

但是我得到这个错误:使用不兼容类型“void”的表达式初始化“NSData *__strong”

各位大侠能帮帮我吗?

最佳答案

sendAsynchronousRequest:queue:completionHandler:返回void,所以不能立即初始化NSData对象,需要等待响应,这是异步的。所以只要做这样的事情:

[NSURLConnection sendAsynchronousRequest:requestGBP queue:operationQueue completionHandler: ^(NSURLResponse* response, NSData* data, NSError* error)
{
responseBGP= data;
// Additional code handling the result goes here, not after the call.
}];
// Here responseBGP may be nil as well, you don't know when the concurrent
// operation will finish.

请注意,调用此方法后,并不是说 responseBGP 将被初始化,因为该方法是异步的,在队列上执行。

关于ios - 异步数据调用 & CoreAnimation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17051870/

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