繁体   English   中英

应用首次启动时3D Touch快速操作不起作用

[英]3D Touch quick actions not working when app first launches

3D Touch出现问题。 除非首次启动该应用程序,否则它运行完美。 这是我的AppDelegate中的以下代码:

 func handleQuickAction(shortcutItem: UIApplicationShortcutItem) -> Bool {
    var quickActionHandled = false
    let type = shortcutItem.type.componentsSeparatedByString(".").last!
    if let shortcutType = Shortcut(rawValue: type) {
        switch shortcutType {
        case .aboutMe:
            NSNotificationCenter.defaultCenter().addObserver(RAIntroductionViewController(), selector: #selector(RAIntroductionViewController.aboutMeTap), name: "about", object: nil)
            NSNotificationCenter.defaultCenter().postNotificationName("about", object: self)
            quickActionHandled = true
        case .education:
            NSNotificationCenter.defaultCenter().addObserver(RAIntroductionViewController(), selector: #selector(RAIntroductionViewController.educationTap), name: "education", object: nil)
            NSNotificationCenter.defaultCenter().postNotificationName("education", object: self)
            quickActionHandled = true
        case .projects:
            NSNotificationCenter.defaultCenter().addObserver(RAIntroductionViewController(), selector: #selector(RAIntroductionViewController.projectsTap), name: "projects", object: nil)
            NSNotificationCenter.defaultCenter().postNotificationName("projects", object: self)
            quickActionHandled = true
        case .why:
            NSNotificationCenter.defaultCenter().addObserver(RAIntroductionViewController(), selector: #selector(RAIntroductionViewController.whyPressed(_:)), name: "why", object: nil)
            NSNotificationCenter.defaultCenter().postNotificationName("why", object: self)
            quickActionHandled = true
        }
    }
    return quickActionHandled
}

func application(application: UIApplication, performActionForShortcutItem shortcutItem: UIApplicationShortcutItem, completionHandler: (Bool) -> Void) {
    completionHandler(handleQuickAction(shortcutItem))

}

这是RAIntroductionViewControllerviewDidLoad方法中的RAIntroductionViewController

 NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.aboutMeTap), name: "about", object: nil)
    NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.educationTap), name: "education", object: nil)
    NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.projectsTap), name: "projects", object: nil)
    NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.whyPressed(_:)), name: "why", object: nil)

那些观察者调用推导航控制器的方法。

尽管一切正常,但首次启动该应用程序时,导航控制器未推送到正确的页面。 它只是转到根视图控制器。

首次启动application:performActionForShortcutItem shortcutItem:completionHandler:未调用application:performActionForShortcutItem shortcutItem:completionHandler:

相反,您应该在application:didFinishLaunchingWithOptions:处理此问题。

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {        
    if let options = launchOptions,
       let shortcutItem = options[UIApplicationLaunchOptionsShortcutItemKey] as? UIApplicationShortcutItem {
       // do the work here..
    }
    return true
}

希望这可以帮助 :)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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