2014-11-28 1 views
1

내 애플리케이션이 닫히면 Core-Data에 따라 UILocalNotification을 설정하고 NSManagedObject에 대한 링크는 userInfo 속성에 저장됩니다. 이것은 잘 작동합니다. 알림을 전달한 후 ViewController를로드하는 방법

그런 다음 UILocalNotification 화재와 사용자가이를 와이프, 응용 프로그램로드와 나는 성공적으로 내 MainViewControlleruserInfo을 통과 NSNotificationCenter를 사용할 때. 이것은 잘 작동합니다.

Core-Data 개체를 찾으려면 managedObjectIDForURIRepresentation을 사용하고 DetailViewController을 표시하려면 performSegue을 실행하십시오. 이게 잘 작동합니다. IF 사용자가 응용 프로그램을 닫은 동안 MainViewController

내 문제는 사용자가 종료 할 때 응용 프로그램의 위치에 따라 다릅니다.

SettingsViewController을 보면서 그들이 UILocalNotification에 액세스 할 때 그들이 종료, 다음은 SettingsViewController의 상단에 DetailViewController를 밀어 것입니다 예를 들어 말. 그들이 올바른 개체 그러나 나는 다시 버튼을 MainViewController

같은 그들이 깊은 DetailViewController 종료로 UIViewController 3, 4 층에있는 경우에 간다에 다시 걸렸다 것을 선호 볼 수 있다는 것은 좋은 것입니다. 그들은 UILocalNotification에 액세스 할 때 DetaiViewController을 맨 위에 슬라이드합니다. 다시 말하지만, 나는 이전의 DetailViewController을 붕괴시키고 신선한 것을 시작하는 응용 프로그램을 선호합니다.

희망적입니다. UILocalNotification에 액세스 할 때 트리거되는 "unwind"segues를 많이 설정해보십시오. 더 간단하고 나은 접근 방법이 있습니까?

업데이트

다음

내가에 연결된 2 UINavigationController의 (마스터 & 세부) 터지는의 아이디어를 좋아하지 최대 업데이트 didReceiveLocalNotification

func application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification) { 
    var state:UIApplicationState = application.applicationState 
    if state == UIApplicationState.Inactive { 
     println("app del notification : \(notification.userInfo)") 
     NSNotificationCenter.defaultCenter().postNotificationName(kShowNotification, object: notification.userInfo) 
    } 
} 

확인 해요 무엇인가 UISplitViewController하지만 실제로 어떻게하는지 잘 모릅니다.

서브 클래스 UISplitViewControllerNSNotificationCenter 메시지를 받도록 설정했습니다. 그러나이 수는 항상 1 : 여기

// MARK: Notifications 
func showEventNotication(notification: NSNotification) { 
    println("split view controllers: \(self.viewControllers.count)") 
} 

는 현재 설정입니다 :

enter image description here

답변

0

당신이 당신의 AppDelegate에있는 UINavigationController에 대한 참조가있는 경우 탐색을 변경하는 방법 - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification을 사용할 수 있습니다 스택. 당신이 UINavigationController에 대한 참조가있는 경우

단순히 스택을 팝업 할 [navController popToRootViewControllerAnimated:NO]를 호출 한 후 다음 MainViewController와 밀어 당신의 DetailViewController 당신이 지금처럼.

+0

좀 더 자세한 정보를 제공해 주시겠습니까? 서브 클래 싱 된 실제로는'UISplitViewController'가 있습니다 (예 :'MySplitViewController'). 통지를받은 후 거기에서 뭔가를하겠습니까? – Richard

+0

추가 세부 사항 : – Rick

0

이전에이 작업을 수행하지 않았습니다. 나는 너에게 제안을했다.

알림이 끝나면 현재 탐색 계층에보기 컨트롤러를 삽입하는 것은 좋지 않거나 적절하지 않습니다. git 저장소가 각 복제본/체크 아웃에 대해 별도의 brach를 유지한다는 것을 알고있는 경우처럼 현명한 작업을 수행 할 수 있습니다.

이렇게하면 이런 식으로해야합니다. 당신은 무언가의 한가운데에 있고 통보가 나타나면 현재 탐색 흐름을 떠나 그 지점에서 새로운 지점을 시작합니다.

그래서 결국 안전하게 응용 프로그램의 이전 흐름을 회복 할 노드/접합부가 마지막에이 알림과 관련된 흐름 굴착 (당신이 통지를 받기 전에 다시 이전보기 컨트롤러에 당신을 이끌 것입니다 & 다시 말했듯이.)

나는이 일을 생각하는 편이 현재보기 컨트롤러에서 presentViewController입니다. 나는 이것을 시도하지는 않았지만 효과가있다.

didReceiveLocalNotification 메서드에서 현재보기 컨트롤러를 가져 와서 여기에 알림에 대한 링크 인 현재보기 컨트롤러가 있습니다.

화보 흐름 :

NavigationController ----> VC1 ----> SettingsViewController 
            /    | 
            /     | 
            /     | 
           /     | 
          Back /_______________ Notification received 
           |       | 
           |       | present view controller 
          Back |       | 
           |       V 
           |     NotificationViewController 
           |       | 
           |       V 
           Storage <----------------- Operations 
+0

답장을 보내 주셔서 감사합니다. 솔직히 말하면 응용 프로그램이 현재 올바르게 작동하는 것입니다. 사용자가 앱에있을 때 알림보기가 맨 위에 표시되면 알림과 상호 작용할 수 있고 결국 다시 자신이하고있는 일을 계속하기 위해 누를 수 있습니다. 이 디자인을 이해하기에 유감스럽게 생각합니다. 사실 내 탐색 컨트롤러를 제대로 파악할 수 없다는 사실도 있습니다. – Richard

1

그것은 나 (스위프트 2.0) 작동합니다. TabBarController 및 NavigationController + ViewControllers가 있습니다. 앱에서 localNotification을 받고 버튼을 탭하면 MyViewController가 표시됩니다. In AppDelegate :

func application(application: UIApplication, handleActionWithIdentifier identifier: String?, forLocalNotification notification: UILocalNotification, completionHandler:() -> Void) { 

    if identifier == "showDetails" { 

     let tabBarController = window?.rootViewController as! UITabBarController 
     tabBarController.selectedIndex = 0 

     let myViewController = window?.rootViewController!.storyboard?.instantiateViewControllerWithIdentifier("MyViewController") as? MyViewController 

     let controller = tabBarController.selectedViewController as! UINavigationController 
     controller.pushViewController(myViewController!, animated: false) 
    } 

    completionHandler() 
} 
관련 문제