我不熟悉Objective-C,当用户点击推送通知泡沫时,需要appDelegate中当前弹出窗口视图控制器的帮助。
我可以为我想要的vc呈现弹出窗口,但不能解散它。我想我没有设置根?请帮助。谢谢!
我的故事板流程:
[Navigation Controller][ViewControllerA] -> [ViewControllerB] -> [ViewControllerC]
我的代码只能显示ViewControllerC和解散按钮不工作(解散到ViewControllerB)。
我希望能够点击关闭按钮将ViewControllerC解散为ViewControllerB,点击B上的关闭按钮转到a。
//AppDelegate.m
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void(^)(void))completionHandler {
NSDictionary *userInfo = response.notification.request.content.userInfo;
if ([(userInfo[kGCMMessageIDKey]) isEqual: @"ViewControllerC"]) {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
ViewControllerC *vc = (ViewControllerC *)[storyboard instantiateViewControllerWithIdentifier:@"ViewControllerC"];
self.window.rootViewController = vc;
} else {
//go to another vc
}
// With swizzling disabled you must let Messaging know about the message, for Analytics
// [[FIRMessaging messaging] appDidReceiveMessage:userInfo];
// Print full message.
NSLog(@"%@", userInfo);
completionHandler();
}
//ViewControllerA.m
- (void) ViewControllerB_BackButtonPressed {
[self dismissViewControllerAnimated:YES completion:nil];
}
//ViewControllerB.m
- (void) ViewControllerC_BackButtonPressed {
[self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)backButtonPressed:(id)sender {
[self.delegate ViewControllerB_BackButtonPressed];
}
//ViewControllerC.m
- (IBAction) backButtonPressed:(id)sender {
[self.delegate ViewControllerC_BackButtonPressed];
}
我最终跳过ViewControllerB,将弹出窗口C呈现在a的顶部。
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void(^)(void))completionHandler {
ViewControllerA *viewControllerA = [mainStoryboard instantiateViewControllerWithIdentifier:@"ViewControllerA"];
//check top view controller
UIViewController *topViewController = self.window.rootViewController;
while (true) {
if (topViewController.presentedViewController) {
topViewController = topViewController.presentedViewController;
} else if ([topViewController isKindOfClass:[UINavigationController class]]) {
UINavigationController *nav = (UINavigationController *)topViewController;
topViewController = nav.topViewController;
} else {
break;
}
}
if (topViewController != viewController) {
[topViewController dismissViewControllerAnimated:YES completion:nil];
}
if ([(userInfo[kGCMMessageIDKey]) isEqual: @"ViewControllerC"]) {
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
UIViewController *viewControllerC = [mainStoryboard instantiateViewControllerWithIdentifier:@"ViewControllerC"];
viewControllerC.modalPresentationStyle = UIModalPresentationPopover;
viewControllerC.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionAny;
[self.window.rootViewController presentViewController:viewControllerC animated:YES completion:NULL];
} else {
//go to another vc
}
completionHandler();
}