2017-03-23 5 views
0

私はXamarin.iOSの新機能です。問題を見つけようとしましたが、通知を処理する方法を知りましたが、viewControllerをロードしてデータを渡すことでリモート通知を処理する

ちょうどwhatsappのように、あなたがデータで特定のViewControllerを開くという通知をタッチすると、私は似たようなことをしたいと思います。一度私はそれにテキストでリモート通知を取得し、私はメインのViewControllerでそのテキストを表示したい。どうやってするか ?

私はいくつかの同様の質問が見つかりましたが、彼らはどちらかスウィフトやObjective-Cの

hereherehere

答えて

0
//when you app in background and user click your notification 
    public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions) 
    { 
     Window = new UIWindow(UIScreen.MainScreen.Bounds); 
     var userInfo = launchOptions.ValueForKey(UIApplication.LaunchOptionsRemoteNotificationKey) as NSDictionary; 
     if (userInfo != null) 
     { 
      var message = userInfo.ValueForKey(new NSString("yourTextKey")) as NSString; 
      var vc = new MessageViewController(); 
      vc.TextView.Text = message; 
      Window.RootViewController = vc; 

     } 
     else 
     { 
      Window.RootViewController = new OtherRootViewController(); 
     } 
     Window.MakeKeyAndVisible(); 
     return true; 
    } 

    //when you app in foreground 
    public override void ReceivedRemoteNotification(UIApplication application, NSDictionary userInfo) 
    { 
     if (userInfo != null) 
     { 
      var message = userInfo.ValueForKey(new NSString("yourTextKey")) as NSString; 
      var vc = new MessageViewController(); 
      vc.TextView.Text = message; 
      Window.RootViewController.PresentViewController(vc, true, null); 
     } 
    } 
であります
関連する問題