我正在使用 SLRequest 将用户的视频发送到 Twitter。完成post请求后,我想通知用户上传是否成功。但是,如果我在 SLRequestHandler 内显示 UIAlertView,系统就会挂起并且根本不显示警报 View 。 SLRequestHandler 中不能有 UIAlertView 吗?根据发布请求的结果显示自定义消息的更好方法是什么?
这是我的示例代码:
SLRequest *postRequest2 = [SLRequest
requestForServiceType:SLServiceTypeTwitter
requestMethod:SLRequestMethodPOST
URL:requestURL2 parameters:message2];
postRequest2.account = twitterAccount;
[postRequest2
performRequestWithHandler:^(NSData *responseData,
NSHTTPURLResponse *urlResponse, NSError *error)
{
if (error != nil) {
NSLog(@"error: %@", error);
}
else {
UIAlertView *theAlert = [[UIAlertView alloc] initWithTitle:@"Success!"
message:@"Your video is now available in your Twitter account"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[theAlert show];
}
}];
最佳答案
所有与 UI 相关的操作都必须在主线程上。
您会尝试在主线程上调度您的警报 View 吗?
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *theAlert = [[UIAlertView alloc] initWithTitle:@"Success!" message:@"Your video is now available in your Twitter account" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[theAlert show];
});
请注意,自 iOS 8 起,UIAlertView 已被弃用,建议使用 UIAlertViewController。
关于ios - 在 SLRequestHandler 中显示 UIAllertView 时系统挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42583386/