2016-01-06 9 views
9

की वजह से काम नहीं करेगा मैं एक आवेदन करने के लिए 3 डी टच शॉर्टकट जोड़ने के लिए कोशिश कर रहा हूँ, मैं शॉर्टकट प्रदर्शित किया जाना भी कामयाब रहे जब होमस्क्रीन से 3DTouch का उपयोग कर एप्लिकेशन आइकन पर ; हालांकि शॉर्टकट का उपयोग करते समय एप्लिकेशन लोड पर दुर्घटनाग्रस्त हो जाता है और मुझे यकीन नहीं है कि क्यों।3 डी टच शॉर्टकट अप्रत्याशित दुर्घटना

मैंने बुकमार्क शॉर्टकट के लिए एप्लिकेशन को लोड करने में कामयाब रहा है लेकिन यह BookmarksViewController शुरू नहीं करता है, यह सिर्फ InitialViewController लोड करता है।

आवेदन एक UITabBarController और प्रत्येक टैब के लिए एक UINavigationController भीतर एम्बेडेड है। दोनों व्यू कंट्रोलर जिन्हें मैं लोड करने की कोशिश कर रहा हूं, अलग-अलग टैब में हैं लेकिन नेविगेशन कंट्रोलर स्टैक में पहला दृश्य है।

क्या किसी को पता है कि मैं गलत कहां जा रहा हूं?

Info.plist फ़ाइल

enter image description here

अनुप्रयोग प्रतिनिधि

enum ShortcutItemType: String { 

case Bookmarks 
case Favourites 

init?(shortcutItem: UIApplicationShortcutItem) { 
    guard let last = shortcutItem.type.componentsSeparatedByString(".").last else { return nil } 
    self.init(rawValue: last) 
} 

var type: String { 
    return NSBundle.mainBundle().bundleIdentifier! + ".\(self.rawValue)" 
} 
} 

class AppDelegate: UIResponder, UIApplicationDelegate { 

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 
    if let shortcutItem = launchOptions?[UIApplicationLaunchOptionsShortcutItemKey] as? UIApplicationShortcutItem { 
     handleShortcutItem(shortcutItem) 
    } 

    return true 
} 

private func handleShortcutItem(shortcutItem: UIApplicationShortcutItem) { 

    if let rootViewController = window?.rootViewController, let shortcutItemType = ShortcutItemType(shortcutItem: shortcutItem) { 
    let sb = UIStoryboard(name: "main", bundle: nil) 

let favouritesVC = sb.instantiateViewControllerWithIdentifier("FavouritesVC") as! FavouritesTableViewController 
let bookmarksVC = sb.instantiateViewControllerWithIdentifier("BookmarksVC") as! BookmarksNotesViewController 

     switch shortcutItemType { 
     case .Bookmarks: 
      rootViewController.presentViewController(bookmarksVC, animated: true, completion: nil) 
      break 
     case .Favourites: 
      rootViewController.presentViewController(favouritesVC, animated: true, completion: nil) 
      break 
     } 
    } 
} 


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

} 

स्टोरीबोर्ड आईडी

ये दृश्य नियंत्रकों के लिए StoryboardID हैं।

enter image description here enter image description here

+0

मैं अपने प्रोजेक्ट के साथ वास्तव में ऐसा ही किया था, अपने कोड की जाँच के बाद, केवल अंतर यह है कि मैं "return false" appDidFinishLaunchWithOption विधि में शॉर्टकट आइटम संभाल के बाद यह performActionForShortcut आइटम विधि को क्रियान्वित करने को रोकने के लिए। आप इसे आजमा सकते हैं – Surely

+2

क्या आप दुर्घटना के लिए स्टैक ट्रेस प्रदान कर सकते हैं? –

उत्तर

5

मैं तुम्हें com.appName.Bookmark

enter image description here

में 'एस' भूल गया लगता है या फिर आप यहाँ बुकमार्क से 'एस' को हटाने की जरूरत:

enum ShortcutItemType: String { 

case Bookmarks 
case Favourites 
2

इसके बजाय, इस तरह के शॉर्टकट का उपयोग करने का प्रयास करें:

if shortcutItem.type == "com.appName.Bookmark" 
@available(iOS 9.0, *) 
func application(application: UIApplication, performActionForShortcutItem shortcutItem: UIApplicationShortcutItem, completionHandler: (Bool) -> Void) { 
    if shortcutItem.type == "com.appName.Bookmark" { 

    } 
}