performActionForShortcutItem
我在调用函数时在应用程序中实现了 3D Touch Quick Action AppDelegate
,我在其中触发NotificationCenter
但不工作并调用
我的代码AppDelegate
:
func application(_ application: UIApplication, performActionFor
shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping
(Bool) -> Void) {
NotificationCenter.default.post(name: Notification.Name("action"), object: nil);
}
并使用它ViewController
:
override func viewDidLoad() {
super.viewDidLoad();
NotificationCenter.default.addObserver(self, selector: #selector(BaseViewController.didReceiveNotification), name: Notification.Name("action"), object: nil);
}
func didReceiveNotification() {
let alert = UIAlert(viewController: self);
alert.content = "NotificationCenter Worked";
alert.title = "NotificationCenter here!!";
alert.show();
}