Advertisement
Guest User

Untitled

a guest
Oct 10th, 2015
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. func application(application: UIApplication, performActionForShortcutItem shortcutItem: UIApplicationShortcutItem, completionHandler: (Bool) -> Void) {
  2. let handeled = handleShortcutItem(shortcutItem)
  3. completionHandler(handeled)
  4. }
  5.  
  6. private func handleShortcutItem(shortcutItem:UIApplicationShortcutItem) -> Bool {
  7. var handeledShortcutItem = false
  8. switch shortcutItem.type{
  9. case ShortcutTypes.first:
  10. if let tabBarController = self.window?.rootViewController as? UITabBarController {
  11. tabBarController.selectedIndex = 0
  12. }
  13. handeledShortcutItem = true
  14. break
  15. case ShortcutTypes.second:
  16. if let tabBarController = self.window?.rootViewController as? UITabBarController {
  17. tabBarController.selectedIndex = 1
  18. }
  19. handeledShortcutItem = true
  20. break
  21. case ShortcutTypes.third:
  22. if let tabBarController = self.window?.rootViewController as? UITabBarController {
  23. tabBarController.selectedIndex = 2
  24. }
  25. handeledShortcutItem = true
  26. break
  27. default:
  28. break
  29. }
  30.  
  31. return handeledShortcutItem
  32. }
  33.  
  34. func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
  35. // Override point for customization after application launch.
  36. var performShortcut = true
  37.  
  38. if let shortcut = launchOptions?[UIApplicationLaunchOptionsShortcutItemKey] as? UIApplicationShortcutItem {
  39. self.selectedShortcutItem = shortcut
  40. performShortcut = false
  41. }
  42. return performShortcut
  43. }
  44.  
  45. func applicationDidBecomeActive(application: UIApplication) {
  46. if let shortcut = selectedShortcutItem {
  47. handleShortcutItem(shortcut)
  48. }
  49. selectedShortcutItem = nil
  50. // 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.
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement