简体   繁体   中英

IOS/Objective-C: Dismiss view controller after SLComposer message

I am trying dismiss a view controller after the SLComposer sends a message.

To do this, I'm using the completion block in the SLComposer method as follows:

  [myPostSheet setCompletionHandler:^(SLComposeViewControllerResult result) {

            switch (result) {


        case SLComposeViewControllerResultCancelled:
                NSLog(@"Post Canceled");
            [self alertPostFail];
                break;
            case SLComposeViewControllerResultDone:
                NSLog(@"Post Successful");
                success = 1;
                [self dismissUnderlyingVC ];

                break;

            default:
                break;
        }
    }];

-(void)dismissUnderlyingVC {
    LogDebug(@"trying to dismiss Underlying VC");
   [self dismissViewControllerAnimated:YES completion:nil];
}

However, despite my putting the dismissal in the completion block, it is firing before the SLComposer is actually dismissed, is not dismissing the next VC down and is giving following error:

     -[myVC dismissUnderlyingVC][Line 227] [DEBUG]
 trying to dismiss Underlying VC
    2018-08-28 20:23:59.579416-0400 idaru[1772:662392]
 [core] SLComposeViewController skipping explicit 
dismiss because isBeingDismissed is already 1
    2018-08-28 20:23:59.588142-0400 
idaru[1772:662392] [core] SLComposeViewController dealloc 

I gather that the SLComposer does not have a delegate so wondering how I can ascertain that it has actually been dismissed so that I can dismiss the next VC below it.

Thanks in advance for any suggestions.

Your view controller is currently presenting the SLComposeViewController .

So, when you call dismissViewControllerAnimated:completion: on self , you're actually asking to dismiss the SLComposeViewController (which is already in the process of being dismissed).

Try asking the presentingViewController to dismiss instead:

[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM