gpt4 book ai didi

ios - 显示消息会导致崩溃吗?

转载 作者:行者123 更新时间:2023-11-28 22:44:58 26 4
gpt4 key购买 nike

我有这个代码:

[NSURLConnection sendAsynchronousRequest:urlRequest queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
{
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;

if ( error != nil )
{
// Display a message to the screen.
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"There was a server error getting your business plan. We use a remote server to backup your work."
message:@"Please make sure your phone is connected to the Internet. If the problem persists, please let us know about this."
delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];

[message show];

但它会在 NSUrlConnection 从服务器返回时执行。它在极少数情况下会造成崩溃。是否可以?这似乎是一段无害的代码。

谢谢!

最佳答案

NSURLConnection 是否在某个奇怪的线程上返回结果?我不知道,但我怀疑 UIAlertView 只能在 UI 线程上工作,因为它是从 UI 开始的。

 (dispatch_async(dispatch_get_main_queue(), ^{ 
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"There was a server error getting your business plan. We use a remote server to backup your work."
message:@"Please make sure your phone is connected to the Internet. If the problem persists, please let us know about this."
delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];

[message show];
});)

抱歉,还没有编译这个,可能某处有错别字。

关于ios - 显示消息会导致崩溃吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13445108/

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