2017-03-03 7 views
0

SLRequest를 사용하여 사용자의 비디오를 트위터로 보내고 있습니다. 게시물 요청을 완료 한 후 사용자에게 업로드 성공 여부를 알려 드리고자합니다. 그러나 SLRequestHandler 내부에 UIAlertView를 표시하면 시스템이 중단되고 경고보기가 전혀 표시되지 않습니다. 그것은 SLRequestHandler 내부에 UIAlertView를 가지는 것이 아닌가? 게시물 요청의 결과를 기반으로 맞춤 메시지를 표시하는 더 좋은 방법은 무엇입니까?SLRequestHandler 내에서 UIAllertView를 표시 할 때 시스템이 멈 춥니 다.

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]; 
         } 
        }]; 
+0

메인 스레드에서 모든 UI 작업을 ,,, – Dhiru

답변

1

모든 UI 관련 작업이 메인 스레드에 있어야합니다 :

여기 내 예제 코드입니다.

경고보기로 기본 스레드를 보내시겠습니까?

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]; 
}); 

그 UIAlertView을 유의하시기 바랍니다는 아이폰 OS 8 이후 사용되지 않으며 UIAlertViewController의 사용이 권장된다.

0

블록에 경고 메시지를 표시하려고합니다. 경고는 UI 스레드 (주 스레드) 컨트롤입니다. 그래서, 다른 부분을 수정하고 dispatch_async에서 경고를 보여 주면 작동 할 것입니다.

dispatch_async(dispatch_get_main_queue(), ^{ 
    [theAlert show]; 
});