2016-05-24 6 views
0

3つのタブを持つタブバーコントローラが3つあります。ナビゲーションコントローラの2つ目のコントローラにwhatsappのように移動します。バックグラウンド状態では正常に処理されましたが、実行状態ではありません。以下は、私のコードがdidiaishlaunch delegateメソッドのuiapplicationです。 2秒の遅延後に通知を発送アプリが実行されていない状態で通知バナーを介してアプリを開きます。

if (launchOptions != nil) { 
     // Launched from push notification 

     NSDictionary *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; 


     [self performSelector:@selector(notificationObserverAfterDelay:) withObject:notification afterDelay:2.0]; 

    } 

-(void)notificationObserverAfterDelay:(NSDictionary *)userInfo 
{ 
    [[NSNotificationCenter defaultCenter] postNotificationName:@"RefreshUIChatNotRunningState" object:self userInfo:userInfo]; 
} 
+0

です:) thatsのあなたのrootViewController ??タブバー付きのビューコントローラがロードされているときに、ナビゲーションスタックの状態はどうなりますか?遅延を伴う通知の放棄は私の考えでは悪いアプローチである –

+0

ナビゲーションスタックに1つのコントローラがある。私はsegueを通してもう一つ追加したい。 –

+0

このoneViewControllerはタブバーを持つものですか?したがって、あなたのrootViewControllerはUINavigationControllerで、そのnavigationStackには正しいtabbarを持つyourViewControllerがありますか? –

答えて

0

Nazishアリ、

は本当に良いアイデアではありません。

tabbarを持つviewControllerの引数としてuserInfo辞書を受け入れるメソッドを宣言します。

は今、なぜYourViewControllerが唯一の理由ではないとにかくする必要がありますactualViewController

-(void)appStartedFromPushNotification : (NSDictionary *)userInfo { 
     //now the control has reached yourViewController with tab bar 
     //change the tab bar selection and perform segue and load the next viewController and use prepareforSgue to pass the data 
} 

YourViewController.m

-(void)appStartedFromPushNotification : (NSDictionary *)userInfo; 

YourViewController.h

、としてそれを呼び出すことができますロードされた???あなたが手動でナビゲーションスタックを混乱させたくない理由です。 YourViewControllerがUINavigationControllerの子であり、UINavigationControllerがrootViewコントローラであるためYourViewControllerが自動的にロードされます。だからそれにアクセスし、自分のナビゲーションスタックが最終的に

Appdelegateで:)安定であり続けるように、タブの変更や負荷viewControllersを実行するために、それを聞いて、

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
NSDictionary *userInfo = [launchOptions valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; 
    if (launchOptions) { 
     [self handleReceiveRemoteNotification: userInfo]; 
    } 
    return YES; 
} 

AppDelegate.mやアクセス方法を宣言それにYourViewControllerインスタンスとハンドオーバのデータはすべて、タブバーを使用してビューコントローラは、ジョブ:)ハッピーコーディングを行う必要があります

- (void) handleReceiveRemoteNotification:(NSDictionary *)userInfo{ 
    UINavigationController *rootViewController = (UINavigationController *)self.window.rootViewController; 
    for(UIViewController *viewController in rootViewController.viewControllers){ 

     if([viewController isKindOfClass:[YourViewController class]]) { 
       [viewController appStartedFromPushNotification:userInfo]; 
     } 
} 

です:)

関連する問題