• Apfeltalk ändert einen Teil seiner Allgemeinen Geschäftsbedingungen (AGB), das Löschen von Useraccounts betreffend.
    Näheres könnt Ihr hier nachlesen: AGB-Änderung
  • Was gibt es Schöneres als den Mai draußen in der Natur mit allen Sinnen zu genießen? Lasst uns teilhaben an Euren Erlebnissen und macht mit beim Thema des Monats Da blüht uns was! ---> Klick

quick actions in ios 9

SpecialFighter

Fießers Erstling
Registriert
25.04.12
Beiträge
131
hallo zusammen,

ich bin seit gestern im Besitz vom 6s und kann damit jetzt das 3D touch testen.
aktuell beschäftige ich mich mit den quick actions von ios 9 und möchte damit meine app "ausrüsten"

folgende Codezeilen habe ich in mein app delegate eingefügt:
Code:
        import UIKit
        enum ShortcutType: String {
            case NewScan = "QuickAction.NewScan"
            case Settings = "QuickAction.Settings"
        }
        @UIApplicationMain
        class AppDelegate: UIResponder, UIApplicationDelegate {
       
            var window: UIWindow?
            static let applicationShortcutUserInfoIconKey = "applicationShortcutUserInfoIconKey"
       
            func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
           
                UIViewController.prepareInterstitialAds()
           
                if(UIApplication.instancesRespondToSelector(Selector("registerUserNotificationSettings:"))) {
                    UIApplication.sharedApplication().registerUserNotificationSettings(UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil))
                }
           
                // QUICK ACTIONS
                    var launchedFromShortCut = false
               
                    if #available(iOS 9.0, *) {
                        if let shortcutItem = launchOptions?[UIApplicationLaunchOptionsShortcutItemKey] as? UIApplicationShortcutItem {
                            launchedFromShortCut = true
                            handleShortCutItem(shortcutItem)
                        }
                    } else {
                        return true
                    }
                    return !launchedFromShortCut
           
            }
       
       
       
       
       
            /**************** QUICK ACTIONS ****************/
            @available(iOS 9.0, *)
            func application(application: UIApplication, performActionForShortcutItem shortcutItem: UIApplicationShortcutItem, completionHandler: Bool -> Void) {
                    let handledShortCutItem = handleShortCutItem(shortcutItem)
                    completionHandler(handledShortCutItem)
            }
            @available(iOS 9.0, *)
            func handleShortCutItem(shortcutItem: UIApplicationShortcutItem) -> Bool {
                var handled = false
                if let shortcutType = ShortcutType.init(rawValue: shortcutItem.type) {
                    let rootNavigationViewController = window!.rootViewController as? UINavigationController
                    let rootViewController = rootNavigationViewController?.viewControllers.first as UIViewController?
                    rootNavigationViewController?.popToRootViewControllerAnimated(false)
                    switch shortcutType {
                        case .NewScan:
                       
                            rootViewController?.performSegueWithIdentifier("goToCamera", sender: nil)
                            handled = true
                   
                        case.Settings:
                            rootViewController?.performSegueWithIdentifier("goToSettings", sender: nil)
                            handled = true
                    }
                }
                return handled
            }
        }


ich drücke fest auf das app icon > Quick Actions erscheinen > ich wähle die Quick Action "New Scan" aus > und es öffnet sich die App mit dem richtigen ViewController

mit dem Code klappt es jetzt - allerdings nicht so wie ich es benötige. ich muss den navigation controller und den first viewcontroller via Storyboard ID ansprechen.

so habe ich diese Zeilen:
Code:
let rootNavigationViewController = window!.rootViewController as? UINavigationController
let rootViewController = rootNavigationViewController?.viewControllers.first as UIViewController?


durch diese ersetzt:
Code:
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let rootNavigationViewController = storyboard.instantiateViewControllerWithIdentifier("NC") as? UINavigationController
    let rootViewController = storyboard.instantiateViewControllerWithIdentifier("VC") as! ViewController

Allerdings wird so das segue nicht mehr ausgeführt und ich bleibe im VC "hängen".
Wo ist der Fehler? :/


P.S. ich beziehe mich auf dieses Beispiel: https://github.com/stringcode86/Static-icon-shortcuts-sample
 
Zuletzt bearbeitet: