0

I am using SLRequest to send user's video to twitter. After finishing the post request, I want to inform the user whether the upload is successful. But if I show a UIAlertView inside the SLRequestHandler, the system simply hangs and doesn't show the alert view at all. Is it a no-go to have a UIAlertView inside the SLRequestHandler? What is the better way to show a custom message based on the result of the post request?

Here is my sample code:

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];
                      }
                  }];
Thinium
  • 171
  • 1
  • 14

2 Answers2

1

All UI related operations must be on the main thread.

Would you try to dispatch on the main thread your alert 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];
});

Please note that UIAlertView is deprecated since iOS 8, and the use of UIAlertViewController is recommended.

Giuseppe Lanza
  • 3,519
  • 1
  • 18
  • 40
0

You are trying to show the alert message in a block. Alerts are UI Thread (main thread) controls. So, modify else part and show your alert in dispatch_async, it will work.

dispatch_async(dispatch_get_main_queue(), ^{
  [theAlert show];
});
KGen
  • 50
  • 3