ios - 在 SLRequestHandler 中显示 UIAllertView 时系统挂起

标签 ios objective-c uialertview slrequest

我正在使用 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/

相关文章:

ios - 使用 CocoaPods 时如何向 Xcode 添加自定义项目配置?

Objective-C 基础知识 : Creating a Function with String

iphone - UIAlertViewDelegate 的 clickedButtonAtIndex 后崩溃并显示消息 [MPMoviePlayerViewController isKindOfClass :]: message sent to deallocated instance

objective-c - 在Objective-C中写 `static void * ptr = &ptr`是什么意思

ios - UIAlertView 灰色按钮

iphone - 以编程方式关闭 UIAlertView

ios - 添加 -ObjC 链接器标志构建失败

ios - iOS 上未收到 Firebase 云消息通知

ios - 添加 UIWindow 删除状态栏

ios - 存折自动化测试