gpt4 book ai didi

iphone - 无法显示 UIAlertView

转载 作者:行者123 更新时间:2023-12-03 20:34:07 29 4
gpt4 key购买 nike

在我的应用程序中,我使用验证 key 通过 Wi-Fi 从服务器下载内容。如果许可证 key 错误或 wi-fi 不可用,我需要显示 UIAlert。我已经编写了用于显示警报 View 的男女混合代码,但警报没有显示...这让我的头流血了...任何人都可以帮忙吗...控件正在越过这一行,但仍然是未显示警报。

-(void)connectionDidFinishLoading:(NSURLConnection *)connection{

NSFileManager *fileManager = [NSFileManager defaultManager];

NSString *documentsDirectory= [[[UIApplication sharedApplication] delegate] applicationDocumentsDirectory]; //[pathToStore objectAtIndex:0];

NSString *path = [documentsDirectory stringByAppendingFormat:@"packages"];

NSString *packagePath = [NSString stringWithFormat:@"%@/%@", path,isbnTemp];

[recievedData writeToFile:[documentsDirectory stringByAppendingPathComponent:@"file.zip"] atomically:YES];
NSString *zipPath=[documentsDirectory stringByAppendingPathComponent:@"file.zip"];

[fileManager createDirectoryAtPath:documentsDirectory withIntermediateDirectories:NO attributes:nil error:nil];

ZipArchive *zipArchive = [[ZipArchive alloc]init];

if([zipArchive UnzipOpenFile:zipPath]){

if([zipArchive UnzipFileTo:packagePath overWrite:YES]){

[self loadContent];


}
else{
NSLog(@"Unable to UnArchieve the packages");
}


}
else {


NSLog(@"Failure To Open Archive");
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Your ISBN and/or Licence Key are incorrect" message:Nil delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil];
[alert show];
[alert release];
}

}

最佳答案

您是否尝试在从主线程以外的线程调用的方法中显示 UIAlertView?例如,如果您尝试在异步回调中显示 UIAlertView,它可能在单独的线程上运行。

如果是这样,您需要将显示 UIAlertView 的代码移至单独的选择器,并使用 performSelectorOnMainThread: 方法之一在主线程上调用它。

例如,将以下方法添加到您的类中:

-(void)showAlert {
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Your ISBN and/or Licence Key are incorrect" message:Nil delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil];
[alert show];
[alert release];
}

然后更改当前代码中的最后一个 else 子句,以便它使用:

[self performSelectorOnMainThread:@selector(showAlert) withObject:nil waitUntilDone:NO];

请参阅NSObject class reference有关 performSelectorOnMainThread: 方法的更多信息。

关于iphone - 无法显示 UIAlertView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5326905/

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