2017-03-23 40 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); 
     } 
    } 
相關問題