public async void OnNavigatedTo(NavigationParameters parameters) { if (parameters.ContainsKey("ShowIt")) { LocalNotificationPayload fooLocalNotificationPayload = parameters["ShowIt"] as LocalNotificationPayload; Title = fooLocalNotificationPayload.ContentTitle; Message = fooLocalNotificationPayload.ContentText; OtherInformation = fooLocalNotificationPayload.OtherInformation; NotificationType = fooLocalNotificationPayload.Style.ToString(); } await ViewModelInit(); }
static void Main(string[] args) { var fooLocalNotificationPayload = new LocalNotificationPayload { NavigationPage = "DetailPage", OtherInformation = "這裡可以放入其他額外資訊", }; var bytes = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(fooLocalNotificationPayload)); var base64 = Convert.ToBase64String(bytes); Console.WriteLine(base64); Console.ReadKey(); }
public async void OnNavigatedTo(NavigationParameters parameters) { if (parameters.ContainsKey("LocalNotification")) { #region 需要繼續顯示到明細頁面 LocalNotificationPayload fooLocalNotificationPayload = parameters["LocalNotification"] as LocalNotificationPayload; var fooPara = new NavigationParameters(); fooPara.Add("ShowIt", fooLocalNotificationPayload); await _navigationService.NavigateAsync("DetailPage", fooPara); #endregion } await ViewModelInit(); }
public MainPageViewModel(INavigationService navigationService, IEventAggregator eventAggregator) { #region 相依性服務注入的物件 _eventAggregator = eventAggregator; _navigationService = navigationService; #endregion #region 頁面中綁定的命令 LaunchNotificationCommand = new DelegateCommand(() => { var fooLocalNotificationPayload = new LocalNotificationPayload { ContentTitle = Title, ContentText = Message, NavigationPage = NaviPageSelectedItem, OtherInformation = "這是額外要傳遞的資訊", SummaryText = SummaryText, Style = (LocalNotificationStyleEnum)Enum.Parse(typeof(LocalNotificationStyleEnum), StyleSelectedItem), Visibility = (LocalNotificationVisibilityEnum)Enum.Parse(typeof(LocalNotificationVisibilityEnum), VisibilitySelectedItem), Priority = (LocalNotificationPriorityEnum)Enum.Parse(typeof(LocalNotificationPriorityEnum), PrioritySelectedItem), Category = (LocalNotificationCategoryEnum)Enum.Parse(typeof(LocalNotificationCategoryEnum), CategorySelectedItem), LargeIcon = LargeIcon, Sound = Sound, Vibrate = Vibrate, }; foreach (var item in InboxStyleList) { fooLocalNotificationPayload.InboxStyleList.Add(item); } _eventAggregator.GetEvent <LocalNotificationEvent>().Publish(fooLocalNotificationPayload); }); #endregion #region 事件聚合器訂閱 #endregion }
public MainPageViewModel(INavigationService navigationService, IEventAggregator eventAggregator) { #region 相依性服務注入的物件 _eventAggregator = eventAggregator; _navigationService = navigationService; #endregion #region 頁面中綁定的命令 LaunchNotificationCommand = new DelegateCommand(() => { var fooLocalNotificationPayload = new LocalNotificationPayload { ContentTitle = Title, ContentText = Message, NavigationPage = "DetailPage", OtherInformation = "這是額外要傳遞的資訊", SummaryText = SummaryText, }; _eventAggregator.GetEvent <LocalNotificationEvent>().Publish(fooLocalNotificationPayload); }); #endregion #region 事件聚合器訂閱 _eventAggregator.GetEvent <LocalNotificationToPCLEvent>().Subscribe(async x => { if (x.NavigationPage == "DetailPage") { #region 需要繼續顯示到明細頁面 var fooPara = new NavigationParameters(); fooPara.Add("ShowIt", x); await _navigationService.NavigateAsync("DetailPage", fooPara); #endregion } }); #endregion }
/// <summary> /// 這個方法,將會於該應用程式在前景的時候,並且有本地端通知出現的時候,將會被執行 /// </summary> /// <param name="application"></param> /// <param name="notification"></param> public override void ReceivedLocalNotification(UIApplication application, UILocalNotification notification) { #region 因為應用程式正在前景,所以,顯示一個提示訊息對話窗 UIAlertView avAlert = new UIAlertView(notification.AlertAction, notification.AlertBody, null, "OK", null); avAlert.Show(); #endregion #region 重新設定徽章為 0 UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0; #endregion #region 使用 Prism 事件聚合器,送訊息給 核心PCL,切換到所指定的頁面 if (notification.UserInfo.ContainsKey(new NSString("LocalNotification"))) { // 取出這個通知的額外夾帶 Payload var fooPayloadtmp = notification.UserInfo[new NSString("LocalNotification")]; // 將夾帶的 Payload 的 JSON 字串取出來 var fooPayload = fooPayloadtmp.ToString(); // 將 JSON 字串反序列化,並送到 核心PCL LocalNotificationPayload fooLocalNotificationPayload = JsonConvert.DeserializeObject <LocalNotificationPayload>(fooPayload); myContainer.Resolve <IEventAggregator>().GetEvent <LocalNotificationToPCLEvent>().Publish(fooLocalNotificationPayload); } #endregion }
protected override void OnCreate(Bundle bundle) { TabLayoutResource = Resource.Layout.tabs; ToolbarResource = Resource.Layout.toolbar; base.OnCreate(bundle); notificationManager = GetSystemService(Context.NotificationService) as NotificationManager; global::Xamarin.Forms.Forms.Init(this, bundle); var fooApp = new App(new AndroidInitializer()); #region 檢查是否是由通知開啟 App,並且依據通知,切換到適當頁面 //自訂通知被點擊後的動作 //當通知出現在通知欄之後,在習慣的趨使下,有很大的機率會被使用者點擊。 //所以應該要實作出通知被點擊後的動作,好比開啟哪個Activity之類的。 //通知被點擊後的動作可以使用PendingIntent來實作,PendingIntent並不是一個Intent,它是一個Intent的容器, // 可以傳入context物件,並以這個context的身份來做一些事情,例如開啟Activity、開啟Service,或是發送Broadcast。 // 如果要使通知可以在被點擊之後做點什麼事,可以使用Notification.Builder的setContentIntent方法來替通知加入PendingIntent fooLocalNotificationPayload = null; if (Intent.Extras != null) { if (Intent.Extras.ContainsKey("NotificationObject")) { string fooNotificationObject = Intent.Extras.GetString("NotificationObject", ""); fooLocalNotificationPayload = JsonConvert.DeserializeObject <LocalNotificationPayload>(fooNotificationObject); } } #endregion XFLocalNotificationDroid.App.fooLocalNotificationPayload = fooLocalNotificationPayload; LoadApplication(new App(new AndroidInitializer())); #region 訂閱要發送本地通知的事件 // 取得 Xamarin.Forms 中的 Prism 注入物件管理容器 IUnityContainer myContainer = (App.Current as PrismApplication).Container; var fooEvent = myContainer.Resolve <IEventAggregator>().GetEvent <LocalNotificationEvent>().Subscribe(x => { #region 建立本地訊息通知物件 Notification.Builder builder = new Notification.Builder(this) .SetContentTitle(x.ContentTitle) .SetContentText(x.ContentText) .SetSmallIcon(Resource.Drawable.ic_notification) .SetAutoCancel(true); // 決定是否要顯示大圖示 if (x.LargeIcon) { builder.SetLargeIcon(BitmapFactory.DecodeResource(Resources, Resource.Drawable.monkey_icon)); } #region 針對不同通知類型作出設定 switch (x.Style) { case LocalNotificationStyleEnum.Normal: break; case LocalNotificationStyleEnum.BigText: //builder.SetContentText(x.ContentText); var textStyle = new Notification.BigTextStyle(); textStyle.BigText(x.ContentText); textStyle.SetSummaryText(x.SummaryText); builder.SetStyle(textStyle); break; case LocalNotificationStyleEnum.Inbox: var inboxStyle = new Notification.InboxStyle(); foreach (var item in x.InboxStyleList) { inboxStyle.AddLine(item); } inboxStyle.SetSummaryText(x.SummaryText); builder.SetStyle(inboxStyle); break; case LocalNotificationStyleEnum.Image: var picStyle = new Notification.BigPictureStyle(); picStyle.BigPicture(BitmapFactory.DecodeResource(Resources, Resource.Drawable.x_bldg)); picStyle.SetSummaryText(x.SummaryText); builder.SetStyle(picStyle); break; default: break; } #endregion #region 設定 visibility switch (x.Visibility) { case LocalNotificationVisibilityEnum.Public: builder.SetVisibility(NotificationVisibility.Public); break; case LocalNotificationVisibilityEnum.Private: builder.SetVisibility(NotificationVisibility.Private); break; case LocalNotificationVisibilityEnum.Secret: builder.SetVisibility(NotificationVisibility.Secret); break; default: break; } #endregion #region 設定 priority switch (x.Priority) { case LocalNotificationPriorityEnum.Default: builder.SetPriority((int)NotificationPriority.Default); break; case LocalNotificationPriorityEnum.High: builder.SetPriority((int)NotificationPriority.High); break; case LocalNotificationPriorityEnum.Low: builder.SetPriority((int)NotificationPriority.Low); break; case LocalNotificationPriorityEnum.Maximum: builder.SetPriority((int)NotificationPriority.Max); break; case LocalNotificationPriorityEnum.Minimum: builder.SetPriority((int)NotificationPriority.Min); break; default: break; } #endregion #region 設定 category switch (x.Category) { case LocalNotificationCategoryEnum.Call: builder.SetCategory(LocalNotificationCategoryEnum.Call.ToString()); break; case LocalNotificationCategoryEnum.Message: builder.SetCategory(LocalNotificationCategoryEnum.Message.ToString()); break; case LocalNotificationCategoryEnum.Alarm: builder.SetCategory(LocalNotificationCategoryEnum.Alarm.ToString()); break; case LocalNotificationCategoryEnum.Email: builder.SetCategory(LocalNotificationCategoryEnum.Email.ToString()); break; case LocalNotificationCategoryEnum.Event: builder.SetCategory(LocalNotificationCategoryEnum.Event.ToString()); break; case LocalNotificationCategoryEnum.Promo: builder.SetCategory(LocalNotificationCategoryEnum.Promo.ToString()); break; case LocalNotificationCategoryEnum.Progress: builder.SetCategory(LocalNotificationCategoryEnum.Progress.ToString()); break; case LocalNotificationCategoryEnum.Social: builder.SetCategory(LocalNotificationCategoryEnum.Social.ToString()); break; case LocalNotificationCategoryEnum.Error: builder.SetCategory(LocalNotificationCategoryEnum.Error.ToString()); break; case LocalNotificationCategoryEnum.Transport: builder.SetCategory(LocalNotificationCategoryEnum.Transport.ToString()); break; case LocalNotificationCategoryEnum.System: builder.SetCategory(LocalNotificationCategoryEnum.System.ToString()); break; case LocalNotificationCategoryEnum.Service: builder.SetCategory(LocalNotificationCategoryEnum.Service.ToString()); break; case LocalNotificationCategoryEnum.Recommendation: builder.SetCategory(LocalNotificationCategoryEnum.Recommendation.ToString()); break; case LocalNotificationCategoryEnum.Status: builder.SetCategory(LocalNotificationCategoryEnum.Status.ToString()); break; default: break; } #endregion #region 準備設定當使用者點選通知之後要做的動作 // Setup an intent for SecondActivity: Intent secondIntent = new Intent(this, typeof(MainActivity)); // 設定當使用點選這個通知之後,要傳遞過去的資料 secondIntent.PutExtra("NotificationObject", JsonConvert.SerializeObject(x)); // 若在首頁且使用者按下回上頁實體按鈕,則會離開這個 App TaskStackBuilder stackBuilder = TaskStackBuilder.Create(this); stackBuilder.AddNextIntent(secondIntent); PendingIntent pendingIntent = stackBuilder.GetPendingIntent(pendingIntentId++, PendingIntentFlags.OneShot); // Uncomment this code to setup an intent so that notifications return to this app: // Intent intent = new Intent (this, typeof(MainActivity)); // const int pendingIntentId = 0; // pendingIntent = PendingIntent.GetActivity (this, pendingIntentId, intent, PendingIntentFlags.OneShot); // builder.SetContentText("Hello World! This is my first action notification!"); // Launch SecondActivity when the users taps the notification: builder.SetContentIntent(pendingIntent); // 產生一個 notification 物件 Notification notification = builder.Build(); #region 決定是否要發出聲音 if (x.Sound) { notification.Defaults |= NotificationDefaults.Sound; } #endregion #region 決定是否要有震動 if (x.Vibrate) { notification.Defaults |= NotificationDefaults.Vibrate; } #endregion // 顯示本地通知: notificationManager.Notify(notificationId++, notification); // 解開底下程式碼註解,將會於五秒鐘之後,才會發生本地通知 // Thread.Sleep(5000); // builder.SetContentTitle("Updated Notification"); // builder.SetContentText("Changed to this message after five seconds."); // notification = builder.Build(); // notificationManager.Notify(notificationId, notification); #endregion #endregion }); #endregion }
// // This method is invoked when the application has loaded and is ready to run. In this // method you should instantiate the window, load the UI into it and then make the window // visible. // // You have 17 seconds to return from this method, or iOS will terminate your application. // public override bool FinishedLaunching(UIApplication app, NSDictionary options) { global::Xamarin.Forms.Forms.Init(); #region 要使用者允許接收通知之設定 // 系統版本是否大於或等於指定的主要和次要值. if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0)) { var notificationSettings = UIUserNotificationSettings.GetSettingsForTypes( UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound, null ); app.RegisterUserNotificationSettings(notificationSettings); } #endregion #region 這個,將會當該應用程式在背景或者沒有執行的時候,且使用點選通知後,將會被執行 // ----------------------------------------------- // 這裡的方法,需要在 LoadApplication(new App(new iOSInitializer())) 程序前先執行 // ----------------------------------------------- #region 檢查此次啟動應用程式,是否因為點選了通知的關係 if (options != null) { #region 若有本地端的通知 Payload 傳入,需要取出這些資訊,並且 if (options.ContainsKey(UIApplication.LaunchOptionsLocalNotificationKey)) { var localNotification = options[UIApplication.LaunchOptionsLocalNotificationKey] as UILocalNotification; if (localNotification != null) { // 底下為顯示出本地端的對話窗 //UIAlertView avAlert = new UIAlertView(localNotification.AlertAction, localNotification.AlertBody, null, "OK", null); //avAlert.Show(); // 設定徽章為 0 UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0; #region 將 Payload 設定 核心PCL 的 App 類別中,所以,當應用程式一開啟的時候,就會自動切換到指定頁面 if (localNotification.UserInfo.ContainsKey(new NSString("LocalNotification"))) { // 取出這個通知的額外夾帶 Payload var fooPayloadtmp = localNotification.UserInfo[new NSString("LocalNotification")]; // 將夾帶的 Payload 的 JSON 字串取出來 var fooPayload = fooPayloadtmp.ToString(); // 將 JSON 字串反序列化,並送到 核心PCL LocalNotificationPayload fooLocalNotificationPayload = JsonConvert.DeserializeObject <LocalNotificationPayload>(fooPayload); // 設定這個應用程式冷啟動的時候,將會依據 Payload 的內容,切換到指定頁面內 XFLocalNotificationiOS.App.fooLocalNotificationPayload = fooLocalNotificationPayload; } #endregion } } #endregion } #endregion #endregion LoadApplication(new App(new iOSInitializer())); #region 取得 Xamarin.Forms 中的 Prism 注入物件管理容器 myContainer = (App.Current as PrismApplication).Container; #endregion #region 訂閱要發送本地通知的事件(事件將會從 核心PCL 送出) var fooEvent = myContainer.Resolve <IEventAggregator>().GetEvent <LocalNotificationEvent>().Subscribe(x => { #region 建立本地訊息通知物件 // 建立通知物件 var notification = new UILocalNotification(); // 設定顯示通知的延遲時間 notification.FireDate = NSDate.FromTimeIntervalSinceNow(10); // 設定通知的主題與內容 notification.AlertAction = x.ContentTitle; notification.AlertBody = x.ContentText; // 修改徽章數值 notification.ApplicationIconBadgeNumber = 68; // 使用預設音效來撥放聲音 notification.SoundName = UILocalNotification.DefaultSoundName; #region 加入額外的 Payload 資訊到此次的通知中 NSMutableDictionary dict = new NSMutableDictionary(); var fooPayload = JsonConvert.SerializeObject(x); dict.Add(new NSString("LocalNotification"), new NSString(fooPayload)); notification.UserInfo = dict; #endregion #region 啟動這個預約通知對話窗 UIApplication.SharedApplication.ScheduleLocalNotification(notification); Console.WriteLine("Scheduled..."); #endregion #endregion }); #endregion return(base.FinishedLaunching(app, options)); }
// // This method is invoked when the application has loaded and is ready to run. In this // method you should instantiate the window, load the UI into it and then make the window // visible. // // You have 17 seconds to return from this method, or iOS will terminate your application. // public override bool FinishedLaunching(UIApplication app, NSDictionary options) { global::Xamarin.Forms.Forms.Init(); #region 要使用者允許接收通知之設定 // 系統版本是否大於或等於指定的主要和次要值. if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0)) { var notificationSettings = UIUserNotificationSettings.GetSettingsForTypes( UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound, null ); app.RegisterUserNotificationSettings(notificationSettings); // 這能夠支援遠端通知,並要求推播註冊 UIApplication.SharedApplication.RegisterForRemoteNotifications(); } else { UIRemoteNotificationType notificationTypes = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge | UIRemoteNotificationType.Sound; UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(notificationTypes); } #endregion #region 檢查此次啟動應用程式,是否因為點選了通知的關係 if (options != null) { #region 若有本地端的通知 Payload 傳入,需要取出這些資訊,並且 if (options.ContainsKey(UIApplication.LaunchOptionsRemoteNotificationKey)) { //var foo4 = options.ToString(); //UIAlertView avAlert4 = new UIAlertView("Re-Check", fooO, null, "OK", null); //avAlert4.Show(); var OptionNotification = options[UIApplication.LaunchOptionsRemoteNotificationKey] as NSDictionary; if (OptionNotification != null) { #region 將 Payload 設定 核心PCL 的 App 類別中,所以,當應用程式一開啟的時候,就會自動切換到指定頁面 if (OptionNotification.ContainsKey(new NSString("aps"))) { try { // 取出這個通知的額外夾帶 aps Payload var aps = OptionNotification[new NSString("aps")] as NSDictionary; #region 取出 asp 內的兩個項目 alert / args string alert = string.Empty; string args = string.Empty; if (aps.ContainsKey(new NSString("alert"))) { alert = (aps[new NSString("alert")] as NSString).ToString(); } if (aps.ContainsKey(new NSString("args"))) { args = (aps[new NSString("args")] as NSString).ToString(); } #endregion // 將夾帶的 Payload 的 JSON 字串取出來 var fooPayload = args; // 將 JSON 字串反序列化,並送到 核心PCL var fooFromBase64 = Convert.FromBase64String(fooPayload); fooPayload = Encoding.UTF8.GetString(fooFromBase64); LocalNotificationPayload fooLocalNotificationPayload = JsonConvert.DeserializeObject <LocalNotificationPayload>(fooPayload); // 設定這個應用程式冷啟動的時候,將會依據 Payload 的內容,切換到指定頁面內 XFRNotiiOS.App.fooLocalNotificationPayload = fooLocalNotificationPayload; } catch (Exception ex) { UIAlertView avAlertEx = new UIAlertView("Exception", ex.Message, null, "OK", null); avAlertEx.Show(); } } else { UIAlertView avAlert168 = new UIAlertView("aps", "Not Found", null, "OK", null); avAlert168.Show(); } #endregion } } #endregion } #endregion LoadApplication(new App(new iOSInitializer())); #region 延緩 1.5 秒,不要讓冷啟動 App的同時,DidReceiveRemoteNotification 也會一併執行 Task.Factory.StartNew(() => { Thread.Sleep(1500); CoolStartApp = false; }); #endregion #region 取得 Xamarin.Forms 中的 Prism 注入物件管理容器 myContainer = (App.Current as PrismApplication).Container; #endregion #region 檢測點 myContainer.Resolve <IEventAggregator>().GetEvent <UpdateInfoEvent>().Publish(new UpdateInfoEventPayload { Name = "FinishedLaunching", time = DateTime.Now, }); ILogService fooILogService = new LogService(); fooILogService.Write("FinishedLaunching : " + DateTime.Now.ToString()); #endregion return(base.FinishedLaunching(app, options)); }
public override void ReceivedRemoteNotification(UIApplication application, NSDictionary userInfo) { #region 檢測點 myContainer.Resolve <IEventAggregator>().GetEvent <UpdateInfoEvent>().Publish(new UpdateInfoEventPayload { Name = "ReceivedRemoteNotification", time = DateTime.Now, }); WriteNotificationLog("ReceivedRemoteNotification" + DateTime.Now.ToString()); #endregion #region 取出 aps 推播內容,進行處理 if (userInfo.ContainsKey(new NSString("aps"))) { try { NSDictionary aps = userInfo.ObjectForKey(new NSString("aps")) as NSDictionary; #region 取出相關推播通知的 Payload string alert = string.Empty; string args = string.Empty; if (aps.ContainsKey(new NSString("alert"))) { alert = (aps[new NSString("alert")] as NSString).ToString(); } if (aps.ContainsKey(new NSString("args"))) { args = (aps[new NSString("args")] as NSString).ToString(); } #endregion #region 因為應用程式正在前景,所以,顯示一個提示訊息對話窗 if (!string.IsNullOrEmpty(args)) { SystemSound.Vibrate.PlaySystemSound(); UIAlertView avAlert = new UIAlertView("Notification", alert, null, "OK", null); avAlert.Show(); #region 使用 Prism 事件聚合器,送訊息給 核心PCL,切換到所指定的頁面 if (string.IsNullOrEmpty(args) == false) { // 將夾帶的 Payload 的 JSON 字串取出來 var fooPayload = args; // 將 JSON 字串反序列化,並送到 核心PCL var fooFromBase64 = Convert.FromBase64String(fooPayload); fooPayload = Encoding.UTF8.GetString(fooFromBase64); LocalNotificationPayload fooLocalNotificationPayload = JsonConvert.DeserializeObject <LocalNotificationPayload>(fooPayload); myContainer.Resolve <IEventAggregator>().GetEvent <LocalNotificationToPCLEvent>().Publish(fooLocalNotificationPayload); } #endregion } #endregion } catch { } } #endregion }
/// <summary> /// 當應用程式執行時,此方法會處理傳入的通知 /// </summary> /// <param name="application"></param> /// <param name="userInfo"></param> /// <param name="completionHandler"></param> public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action <UIBackgroundFetchResult> completionHandler) { #region 檢測點 try { myContainer.Resolve <IEventAggregator>().GetEvent <UpdateInfoEvent>().Publish(new UpdateInfoEventPayload { Name = "DidReceiveRemoteNotification", time = DateTime.Now, }); } catch { } try { ILogService fooILogService = new LogService(); fooILogService.Write("DidReceiveRemoteNotification : " + DateTime.Now.ToString()); } catch { } #endregion //if (application.ApplicationState == UIApplicationState.Inactive) //{ // completionHandler(UIBackgroundFetchResult.NoData); // return; //} //if (CoolStartApp == true) //{ // return; //} #region 取出 aps 推播內容,進行處理 try { if (userInfo.ContainsKey(new NSString("aps"))) { try { NSDictionary aps = userInfo.ObjectForKey(new NSString("aps")) as NSDictionary; #region 取出相關推播通知的 Payload string alert = string.Empty; string args = string.Empty; if (aps.ContainsKey(new NSString("alert"))) { alert = (aps[new NSString("alert")] as NSString).ToString(); } if (aps.ContainsKey(new NSString("args"))) { args = (aps[new NSString("args")] as NSString).ToString(); } #endregion #region 因為應用程式正在前景,所以,顯示一個提示訊息對話窗 if (!string.IsNullOrEmpty(args)) { SystemSound.Vibrate.PlaySystemSound(); UIAlertView avAlert = new UIAlertView("Notification", alert, null, "OK", null); avAlert.Show(); #region 使用 Prism 事件聚合器,送訊息給 核心PCL,切換到所指定的頁面 if (string.IsNullOrEmpty(args) == false) { // 將夾帶的 Payload 的 JSON 字串取出來 var fooPayload = args; // 將 JSON 字串反序列化,並送到 核心PCL var fooFromBase64 = Convert.FromBase64String(fooPayload); fooPayload = Encoding.UTF8.GetString(fooFromBase64); LocalNotificationPayload fooLocalNotificationPayload = JsonConvert.DeserializeObject <LocalNotificationPayload>(fooPayload); myContainer.Resolve <IEventAggregator>().GetEvent <LocalNotificationToPCLEvent>().Publish(fooLocalNotificationPayload); } #endregion } #endregion } catch { } } } catch { } try { ILogService fooILogService = new LogService(); fooILogService.Write("DidReceiveRemoteNotification Complete : " + DateTime.Now.ToString()); } catch { } completionHandler(UIBackgroundFetchResult.NoData); #endregion }