我也遇到过这种问题。我想从推送中弹出一个模式,在我这样做之前,我想检查是否已经出现了某个屏幕,如果是,则关闭这些并弹出我的屏幕下面是代码。
// Dismiss all the modals which are currently shown.
- (void) dismissAllModalsIfAnyWithCompletion:(void(^)(BOOL success)) completion{
BOOL hiddenByModal = nil != [[UIApplication sharedApplication].keyWindow.rootViewController presentedViewController];
if (hiddenByModal) {
//We need to dismiss the existing modal and after completion pop up the new modal.
[[UIApplication sharedApplication].keyWindow.rootViewController dismissViewControllerAnimated:NO completion:^{
// After dismissing let the handler know.
completion(YES);
}];
}
else{
// If there is no modal, then simply let the handler know to pop the new modal.
completion(YES);
}
}