iOS:使用多个相同的viewcontroller处理多个uilocalnotification
我正在使用UILocalnotification…在收到通知时,我会在应用程序处于活动模式时打开viewcontroller…但如果同时收到多个通知…我如何打开多个viewcontroller…彼此上方并依次关闭它们…我尝试打开viewcontroller,但收到此错误iOS:使用多个相同的viewcontroller处理多个uilocalnotification,ios,objective-c,iphone,uiviewcontroller,uilocalnotification,Ios,Objective C,Iphone,Uiviewcontroller,Uilocalnotification,我正在使用UILocalnotification…在收到通知时,我会在应用程序处于活动模式时打开viewcontroller…但如果同时收到多个通知…我如何打开多个viewcontroller…彼此上方并依次关闭它们…我尝试打开viewcontroller,但收到此错误 Warning: Attempt to present <NotificationViewController: 0x7fc033b43900> on <UINavigationController: 0x7f
Warning: Attempt to present <NotificationViewController: 0x7fc033b43900> on <UINavigationController: 0x7fc031859600> whose view is not in the window hierarchy!
警告:尝试显示其视图不在窗口层次结构中的对象!
有一种黑客可以做到这一点
将扩展写入视图控制器:
extension UIViewController {
var lastPresentedViewController: UIViewController {
guard let presentedViewController = presentedViewController else { return self }
return presentedViewController.lastPresentedViewController()
}
}
或objc:
UIViewController+LastPresentedViewController.h:
@interface UIViewController (LastPresentedViewController)
-(UIViewController *)lastPresentedViewController;
@end
UIViewController+LastPresentedViewController.m:
@implementation UIViewController (LastPresentedViewController)
- (UIViewController *)lastPresentedViewController {
if (self.presentedViewController) {
return [self.presentedViewController lastPresentedViewController];
} else {
return self;
}
}
@end
当需要从navigationController显示视图控制器时,只需按如下方式调用此方法:
navigationController.lastPresentedViewController.presentViewController(....
如果您已经在navigationController中,只需调用
lastPresentedViewController.presentViewController(…
嗯,我很久没有写objective-c了,让我试试:)我想你能想出怎么称呼它吗?非常好,谢谢…再问一个问题…当我点击一个通知时,你知道如何确认其他uilocalnotification吗?你可以存储旧的一个或多个通知