2017-11-23 17 views
0

내 애플 리케이션에서 바로 가기 항목을 알아 내는데 약간의 문제가 있습니다. 나는 모든 자습서를 따라 왔고 나는 모든 것을 올바르게했다고 믿는다; 그러나, 그것은 정말로 이상하게 행동하고 있습니다. 문제는 앱을 완전히 닫고 홈 화면에서 3D 터치 바로 가기 항목을 실행하면 올바른 부분으로 이동한다는 것입니다. 그러나 앱이 백그라운드에서 열리면 (홈 버튼을 클릭하기 만하면) 앱의 올바른 부분으로 이동하지 않고 방금 열립니다. 이것은 정말 이상하고 나는 모든 지시를 따랐기 때문에 무엇을해야할지 모르겠습니다. 정말 고맙습니다!바로 가기 아이템, 빠른 액션 3D 터치 스위프트

코드 :

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

    if shortcutItem.type == "com.myapp.newMessage" { 

     let sb = UIStoryboard(name: "Main", bundle: nil) 


     let vc = sb.instantiateViewController(withIdentifier: "RecentVC") as! UITabBarController 
     vc.selectedIndex = 2 //this takes me to the contacts controller 



     let root = UIApplication.shared.keyWindow?.rootViewController 

     root?.present(vc, animated: false, completion: { 
      completionHandler(true) 
     }) 


    } else if shortcutItem.type == "com.myapp.groups" { 
     let sb = UIStoryboard(name: "Main", bundle: nil) 


     let vc = sb.instantiateViewController(withIdentifier: "RecentVC") as! UITabBarController 
     vc.selectedIndex = 1 //this takes me to the groups controller 

     let root = UIApplication.shared.keyWindow?.rootViewController 

     root?.present(vc, animated: false, completion: { 
      completionHandler(true) 
     }) 

    } else { 
     //more short cut items I will add later 
    } 
} 

참고 : 제출 된이 기능은의 Info.plist 파일 이외의 응용 프로그램에있는 유일한 장소입니다, 이러한 정적 바로 가기 항목이고, 나는의 Info.plist 파일에 구성 바로 가기 항목에 대한 정보가 있습니다.

편집 : 내가이 일을 여러 가지 방법을 시도하기 때문에 이것은 RootViewController에 문제 같은 것, 그리고 그것은 여전히 ​​나에게 같은 경고 메시지를 제공

2017년 11월 22일 22 : 36 : 46.473195- 0800 QuickChat2.0 [3055 : 1068642] 경고 :보기가 창 계층 구조에 나타나지 않습니다!

방금이 방법으로 목표를 달성하려고 시도했지만 through this post과 똑같은 결과를 얻었습니다.

+0

'root '가 (아무 일도 일어나지 않는 상황에서) nil인지 확인 했습니까? 그것이 0이 아닌 경우 지연된 성능을 추가하여 도움이되는지 확인해 보셨습니까? – matt

+0

그것이 nil인지 어떻게 알 수 있습니까? – Jaqueline

+0

디버거를 사용하고 로깅을 삽입하십시오. 프로그래밍에 대한 추측은 필요 없습니다. 모든 단계에서 변수가 무엇인지 확인할 수 있습니다. – matt

답변

0

performActionForShortcutItem에 바로 가기 유형을 알려주고 거기에있는 코드를 applicationDidBecomeActive으로 옮기는 변수를 설정해야합니다. 당신의 모습은 이렇게 보일 것입니다

var shortcut: String? 

func applicationDidBecomeActive(application: UIApplication) { 
    if let shortcutItem = shortcut { 
     shortcut = nil 
     if shortcutItem == "com.myapp.newMessage" { 
      let sb = UIStoryboard(name: "Main", bundle: nil) 
      let vc = sb.instantiateViewController(withIdentifier: "RecentVC") as! UITabBarController 
      vc.selectedIndex = 2 //this takes me to the contacts controller 
      let root = UIApplication.shared.keyWindow?.rootViewController 
      root?.present(vc, animated: false, completion: nil) 
     } else if shortcutItem == "com.myapp.groups" { 
      let sb = UIStoryboard(name: "Main", bundle: nil) 
      let vc = sb.instantiateViewController(withIdentifier: "RecentVC") as! UITabBarController 
      vc.selectedIndex = 1 //this takes me to the groups controller 
      let root = UIApplication.shared.keyWindow?.rootViewController 
      root?.present(vc, animated: false, completion: nil) 
     } else { 
      //more short cut items I will add later 
     } 
    } 
} 

func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) { 
    shortcut = shortcutItem.type 
    completionHandler(true) 
} 
+0

방금 ​​시도한이 앱이 마치 지금하고있는 것처럼 앱을 닫을 때도 전혀 작동하지 않습니다. – Jaqueline

+0

중단 점을 설정하고 중단 점을 볼 수 있습니까? – Malik

+0

내 일이 왜 효과가 없는지 잘 모르겠습니다. 나는 튜토리얼을 정확히 따라 갔고 어떻게했는지를 완벽하게 잘 수행했다. 문제가 뭔지 모르겠다. – Jaqueline