2017-04-11 1 views
0

푸시 알림에서 응용 프로그램을 열 때 (자세히보기) 열어야 만 답변을 찾으려고했지만 시도 할 수 없었습니다.푸시 알림 후 특정보기로드

내가 열어야하는보기 (녹색보기)를 보여주는 이미지가 첨부되었습니다. 나를 안내 해줘.

enter image description here

+0

가능한 중복 https://stackoverflow.com/ 질문/43058261/ios-swift-navigate-to-certain-viewcontroller- 프로그래밍 방식에서 푸시 알림) –

답변

0

당신은 approch 아래 시도 할 수 있습니다 :

은 AppDelegate에 클래스에서이 메서드를 추가합니다

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { 

     // Register the below observer in the rootviewcontroller so its registered first and than Pass NSDictionary 
     [[NSNotificationCenter defaultCenter] postNotificationName:@"pushModalPopUp" object:userInfo]; 
    } 
+0

객관적인 C –

+0

업데이트를 사용하고 있습니다. 한번보세요. –

+0

감사합니다. 나와 함께 작동합니다. –

0

Window.rootView> A> B> C

이 간단한 방법입니다 : 당신이 통지를받을 때

  1. 이 NSUserDefault에 키를 추가 (예 : "NeedShowViewC" = true),보기 제어기 A를로드하십시오.
  2. 보기 제어기의 viewDidLoad에서 해당 키 ("NeedShowViewC")가 참인지,보기 B를 읽는 지 등을 확인하십시오.
  3. 보기 컨트롤러 C 표시가 끝나면 해당 키를 다시 false 또는 원격으로 설정하십시오.
0

그냥 참고 코드 Hunterr의 1 일이 다른 approch입니다

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { 
    // Open Your Details view controller directly using segue 
    // You can pass details id and then fetch details and display in the view. 
    SettingViewController *moreVC = [[SettingViewController alloc] initWithNibName:@"SettingViewController" bundle:nil]; 
    UINavigationController *navigationRootController = [[UINavigationController alloc] initWithRootViewController:moreVC]; 
    [[[[UIApplication sharedApplication] keyWindow] rootViewController] presentViewController:navigationRootController animated:YES completion:NULL]; 
} 

접근 : 새 viewcontorller (대상 "녹색"VC) + 새 UINavigationVC 시작 :

012 시작
SettingViewController *moreVC = [[SettingViewController alloc] initWithNibName:@"SettingViewController" bundle:nil]; 
UINavigationController *navigationRootController = [[UINavigationController alloc] initWithRootViewController:moreVC]; 

이렇게하면 두 VC의 새 인스턴스가 만들어집니다. 기능적으로는 문제가되지 않지만 잠재적으로 메모리 관리 문제가 발생할 수 있습니다. 사용자가 앱을 닫을 때 이미 녹색 세부 정보보기를보고 있고 푸시를 수신하면 그 결과 앱을 열고 녹색 VC로 자동 탐색하고 다시 녹색 VC 인스턴스가 두 개 있습니다. 메모리 (실제로 이것을보기 위해 Xcode 디버거 메모리 맵을 확인할 수 있습니다). 이 작업을 반복하여 ARC가 VC의 이전 인스턴스를 릴리스하지 않으면 (MVC 구현에 따라 다름) 결국 메모리 사용량이 증가 할 수 있습니다.

또한 이전에 테이블 뷰없이 세부 VC를 직접 표시하면 방금 만든 새 NavVC가 VC 스택에 테이블 뷰를 갖지 않으므로 '뒤로'탐색이 엉망이됩니다.

대안은 다음과 같습니다

1) 응용 프로그램의 루트 뷰 컨트롤러를 사용 UNUserNotificationCenterDelegate

2)의 탐색 컨트롤러를 잡아 didReceiveRemoteNotification() 또는() 아이폰 OS 10의 새로운를 사용하여 푸시 알림 받기 첫 번째 탭 -> 녹색 세부 정보보기로 연결되는 탭.

3) 그런 다음 네비게이션 스택을 롤백하십시오 -> 이것은 사용자가 마지막으로 열어 본 VC /보기에 상관없이 처음부터 네비게이션을 시작하고 세부 VC (또는 향후 VCs 귀하의 추가는 tableVC보다 더 깊습니다).

4) 필요한 행의 세부 정보를 표시하기 위해 방금 얻은 navVC의 rootVC 인 tableVC를 말합니다. public func/API를 tabelVC에 추가하거나 tableVC가 준수하는 알림을 사용하여이 작업을 수행 할 수 있습니다 (Code Hunterr의 두 번째 접근 방식에서 제안 된 것처럼).

예 (그것의 빠른하지만 ObjC로 번역하기 쉽게해야합니다) :

//grab the navVC - in this example I'm assuming your tabVC is the rootVC of the app you need the 1st VC of the tabVC's array 
if let topNavController = UIApplication.shared.keyWindow?.rootViewController?.viewControllers.first as? UINavigationController { 
      //grab the content VC (which is your table VC) 
      if let topContentController = topNavController.viewControllers.first as? MyAppsTableView { 
       //pop the navVC stack all the way back to its root (the table) 
       topNavController.popToRootViewController(animated: false) 
       //tell your table view to show detail of a certain row 
       topContentController.pleaseShowItem(item: xyzzy) 
      } 
     } 
[프로그램 푸시 알림에서 특정의 ViewController에 아이폰 OS 스위프트 이동] (의