0

After I call a certain Google's Youtube library, my application suddenly becomes not responsive at all after one of its callback.

Not responsive means all UI components cannot be clicked.

Is there such thing in iOS that can disable entire screen to be not responsive at all?

The code:

self.uploadFileTicket = [service executeQuery:query
                                completionHandler:^(GTLServiceTicket *ticket,
                                                    GTLYouTubeVideo *uploadedVideo,
                                                    NSError *error) {
                                    // Callback
                                    _uploadFileTicket = nil;

                                    if (error == nil) {
                                        [_delegate videoUploadedSuccessfully:YES error:nil];

                                    } else {
                                        [_delegate videoUploadedSuccessfully:NO error:error.description];
                                    }
                                }];

Inside my ViewController:

- (void)videoUploadedSuccessfully:(BOOL)success error:(NSString *)errorMessage{
  dispatch_async(dispatch_get_main_queue(), ^{
    if(success){
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Youtube"
                                                      message:@"Video uploaded successfully"
                                                     delegate:nil
                                            cancelButtonTitle:nil
                                            otherButtonTitles:@"OK", nil];
      [alert show];
    }
    else{
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Youtube"
                                                      message:errorMessage
                                                     delegate:nil
                                            cancelButtonTitle:nil
                                            otherButtonTitles:@"OK", nil];
      [alert show];
    }
  });
}

Update

I have tried using Instrument and got following:

Thread

Does this mean my Working Thread are blocking Main Thread?

Rendy
  • 5,572
  • 15
  • 52
  • 95
  • First of all try to comment that entire code and check – Sohil R. Memon Jun 02 '16 at 09:43
  • Put breakpoint and check in which thread process launched – Evgeniy Kleban Jun 02 '16 at 09:44
  • If i comment of the calling on Youtube library, of course it works again lol – Rendy Jun 02 '16 at 09:44
  • All UI interactions are handled in a single (main) thread, what you described appears to be a deadlock. Check the documentation of the code you are using, perhaps it is designed to be called from a background thread only. – A-Live Jun 02 '16 at 09:45
  • are you calling it asynchronously? Are you performing UI operations on a thread other than the main/UI-thread? – luk2302 Jun 02 '16 at 09:46
  • Yes; you can occupy the main thread so it's unable to process UI events. – Droppy Jun 02 '16 at 09:46
  • Either you are blocking the main thread, or you put a UIView blocking all the touch above (which can be checked with the View Hierarchy: http://stackoverflow.com/questions/25963257/how-to-get-the-3d-view-of-ui-in-xcode-6) – Larme Jun 02 '16 at 09:51
  • I mainly suspect thread is the root issue, but I am not sure how to check the whole application's thread. While when I got the success delegate from Youtube's library, using this `[NSThread isMainThread]` returns me YES. @Larme, no it's not. I have checked it using Debug View Hierarchy. – Rendy Jun 02 '16 at 09:55
  • Giving the code of your implementation of that delegate may be helpful. You maybe miss the call for stopping something, but without code, we can just guess that your main thread is "blocked". – Larme Jun 02 '16 at 09:56
  • Looks like you are Querying or uploading something from UI thread, and no UI elements can be accessed until this execution is finished. – ogres Jun 02 '16 at 10:22
  • Well actually I am bit confused with Youtube library. Since above delegate has been called, but in Youtube video manager it's still uploading. However even after finished, my app still not responsive at all. – Rendy Jun 02 '16 at 10:24
  • All, I have uploaded image. Please help whether can I imply that Working Threads are blocking my Main Thread? – Rendy Jun 02 '16 at 10:38
  • call self.uploadFileTicket = [service executeQuery .. in background thread using dispatch_asynch() – Mohammad Sadiq Shaikh Jun 02 '16 at 10:58
  • Finally I solved my issue :) – Rendy Jun 02 '16 at 11:04

2 Answers2

1

Finally I found the ROOT cause of this issue. There is somewhere in the code before uploading the video to Youtube:

[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
Rendy
  • 5,572
  • 15
  • 52
  • 95
0

I cannot pin-point the issue. But, here are some of my suggestions.

The method call [service executeQuery:query completionHandler: has a completion handler. Therefore, it's mostly an async task. Therefore the task of the service should be done in a background thread and should not block the UI.

In case you're not sure whether the call is in the main thread, use the following LOC to clarify.

[NSThread isMainThread] will return true only if the executing thread is the main thread/ UI-thread.

Can you also put a NSLog at videoUploadedSuccessfully and check whether the delegate method gets called multiple times?

You do not need the block

dispatch_async(dispatch_get_main_queue(), ^{}

The delegate method should get executed on the main thread itself as long as you're calling the service-query method on the main thread.

Finally check whether you're calling the [service executeQuery:query method from the main thread?

Ruchira Randana
  • 4,021
  • 1
  • 27
  • 24