当应用程序被杀死并重新启动时,故事板未加载到performActionForShortcutItem中

时间:2019-01-21 20:21:07

标签: ios swift 3dtouch

我正在尝试在我的应用中添加3D触摸操作。我有两个用于两个动作的视图控制器,其中一个是通过编程创建的,一个是从情节提要中创建的。当应用程序最小化并从3d-touch操作启动时,两者均正确显示。但是,当我终止该应用程序并仅使用程序化视图控制器重新启动操作时,没有情节提要视图控制器。

由于故事板视图控制器在最小化应用程序时可以很好地打开,我担心当应用程序被杀死并启动时,故事板不会被初始化。我该如何解决?

这是我的performaction委托方法和该方法的处理程序-

func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
        completionHandler(handleShortcuts(shortcutItem: shortcutItem))
    }

    func handleShortcuts(shortcutItem:UIApplicationShortcutItem)->Bool{
        switch shortcutItem.type {
        case "com.anuran.ios.place-settings":
            if UDManager.isLoggedIn() {
                let placePickerVC = PlacePickerViewController()
                placePickerVC.isFromSettings=true
                placePickerVC.isFromShortcut=true
                self.window?.rootViewController = placePickerVC
                self.window?.makeKeyAndVisible()
                return true
            }
            break
        case "com.anuran.ios.activity-log":
            if UDManager.isLoggedIn() {
                print("anuran storyboard going to load")
                let storyBoard=UIStoryboard(name: "Main", bundle: nil)
                print("anuran storyboard loaded")
                let activityLogViewController = storyBoard.instantiateViewController(withIdentifier: "ActivityLogVC") as! ActivityLogViewController
                print("anuran VC loading")
                self.window?.rootViewController = activityLogViewController
                self.window?.makeKeyAndVisible()
                print("anuran window visible")
                return true
            }
            break
        default:
            print("")
        }
        return false
    }

这是我的applicationDidBecomeActive方法

func applicationDidBecomeActive(_ application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.


        guard let shortcut = shortcutItem else { return }

        print("- Shortcut property has been set")

        let _ = handleShortcuts(shortcutItem: shortcut)

        self.shortcutItem = nil



    }

最后这是我的didFinishLaunchingWithOptions,在这里我要处理是否处理操作的情况

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {



        var performShortcutDelegate = true

        if let shortcutItem = launchOptions?[UIApplicationLaunchOptionsKey.shortcutItem] as? UIApplicationShortcutItem {

            print("Application launched via shortcut")
            self.shortcutItem = shortcutItem
            performShortcutDelegate = false
        }else {
            let vc = SplashScreenViewController()
            self.window?.rootViewController = vc
            self.window?.makeKeyAndVisible()
        }

        return performShortcutDelegate

    }

0 个答案:

没有答案