gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 11:07:04 25 4
gpt4 key购买 nike

我在使用 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 方法中的代码:

 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)

那些观察者调用推送导航 Controller 的方法。

虽然一切正常,但当应用程序首次启动时,导航 Controller 并没有被推送到正确的页面。它只是转到 Root View Controller 。

最佳答案

应用首次启动时,不会调用 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
}

希望这有帮助:)

关于ios - 应用程序首次启动时 3D Touch 快速操作不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36949489/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com