2016-01-06 9 views
-1

Я добавил 3D Touch на свой значок приложения, чтобы отобразить меню быстрого действия. Думаю, я должен был все правильно настроить.iPhone замерзает при использовании QuickActionItems

Проблема заключается в том, что когда я выбираю один из элементов в меню быстрого действия, iPhone замерзает в течение нескольких секунд, прежде чем он откроет приложение.

Это мой AppDelegate.swift:

import UIKit 
import Parse 


@available(iOS 9.0, *) 
@UIApplicationMain 
class AppDelegate: UIResponder, UIApplicationDelegate { 

    var window: UIWindow? 

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 
     // Override point for customization after application launch. 

     Parse.setApplicationId("xx", 
      clientKey: "xx") 

     let currentInstallation: PFInstallation = PFInstallation.currentInstallation() 
     currentInstallation.badge = 0 
     currentInstallation.saveEventually() 

     return true 
    } 

    func applicationWillResignActive(application: UIApplication) { 
     // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 
     // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 
    } 

    func applicationDidEnterBackground(application: UIApplication) { 
     // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
     // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 
    } 

    func applicationWillEnterForeground(application: UIApplication) { 
     // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 
    } 

    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. 
    } 

    func applicationWillTerminate(application: UIApplication) { 
     // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 
    } 

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

     let rootNavigationViewController = window!.rootViewController as? UINavigationController 
     let rootViewController = rootNavigationViewController?.viewControllers.first as UIViewController? 

     rootNavigationViewController?.popToRootViewControllerAnimated(false) 

     if shortcutItem.type == "JEGHARALDRI" { 
      rootViewController?.performSegueWithIdentifier("JEGHARALDRISEGUE", sender: nil) 
     } 
     if shortcutItem.type == "PLING" { 
      rootViewController?.performSegueWithIdentifier("PLINGSEGUE", sender: nil) 
     } 
     if shortcutItem.type == "FLASKETUTENPEKERPÅ" { 
      rootViewController?.performSegueWithIdentifier("FLASKETUTENPEKERPÅSEGUE", sender: nil) 
     } 
     if shortcutItem.type == "KORTETTALER" { 
      rootViewController?.performSegueWithIdentifier("KORTETTALERSEGUE", sender: nil) 
     } 
    } 
} 
+0

Как вы справляетесь с этим? Похоже, он сбой, потому что приложение не знает, что показывать –

+0

@QuentinRibierre Ну, это не сбой. Я показываю, что мне нужно делать, но проблема в том, что iPhone замерзает на несколько секунд, прежде чем он откроет приложение. –

ответ

1

Я думаю, что ваше приложение делегат должен более выглядит как-то вроде этого

import UIKit 

@UIApplicationMain 
class AppDelegate: UIResponder, UIApplicationDelegate { 

    //MARK: - Properties 

    var window: UIWindow? 

    lazy var quickActionManager: QuickActionsManager = { 
     return QuickActionsManager() 
    }() 

    //MARK: - AppDelegate Methods 

    func application(application: UIApplication, 
     didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool 
    { 
     return self.setupQuickActions(launchOptions) 
    } 

    func application(application: UIApplication, performActionForShortcutItem 
     shortcutItem: UIApplicationShortcutItem, completionHandler: (Bool) -> Void) 
    { 
     completionHandler(self.quickActionManager.handleShortcut(shortcutItem)) 
    } 

    //MARK: - Private Methods 

    private func setupQuickActions(launchOptions: [NSObject: AnyObject]?) -> Bool 
    { 
     guard let shortcutItem = launchOptions?[UIApplicationLaunchOptionsShortcutItemKey] 
     as? UIApplicationShortcutItem else { return false } 
     return self.quickActionManager.handleShortcut(shortcutItem) 
    } 
} 

И так, то вы получите всю логику для обработки быстрых действий в вашем менеджер быстрого действия, который будет выглядеть примерно так

//MARK: - Public Methods 

    func handleShortcut(shortcut: UIApplicationShortcutItem?) -> Bool 
    { 
     guard let shortcut = shortcut else { return false } 
     // Get the key of the shortcutItem 
     let key = self.shortKeyForType(shortcut.type) 
     // Check if that key is the key of a knowed viewController 
     guard let viewControllerKey = ViewControllerKeys(rawValue: key) else { return false } 
     // Try to show This View Controller 
     return self.showViewController(viewControllerKey) 
    } 

Предполагая, что вы получили перечисление viewController для отображения соответствующих быстрых действий.

Надеюсь, что ответ на ваш вопрос, сообщите мне, если у вас есть еще.

+0

Спасибо! Но последний код дает мне две ошибки: http://s11.postimg.org/sqn14qpsj/Screen_Shot_2016_01_08_at_16_11_57.png –