void ExecutePushNotificationCallback(object sender, ToastPush push) { Deployment.Current.Dispatcher.BeginInvoke(() => { PhoneApplicationFrame frame; PhoneApplicationPage page; CordovaView cView; if (TryCast(Application.Current.RootVisual, out frame) && TryCast(frame.Content, out page) && TryCast(page.FindName("CordovaView"), out cView)) { cView.Browser.Dispatcher.BeginInvoke(() => { try { string userdata = push.UserData; if (String.IsNullOrEmpty(userdata)) { userdata = "null"; } string pushPayload = JsonConvert.SerializeObject(push); string unifiedPayload = String.Format("{{ \"message\" : \"{0}\", \"userdata\" : {1}, \"onStart\" : {2}, \"foreground\" : {3}, \"wp8\" : {4} }}", push.Content, userdata, JsonConvert.SerializeObject(push.OnStart), JsonConvert.SerializeObject(!push.OnStart), pushPayload); cView.Browser.InvokeScript("eval", "cordova.require(\"pushwoosh-cordova-plugin.PushNotification\").notificationCallback(" + unifiedPayload + ")"); } catch (Exception ex) { Debug.WriteLine("ERROR: Exception in InvokeScriptCallback :: " + ex.Message); } }); } }); }
void ExecutePushNotificationCallback(object sender, ToastPush push) { Deployment.Current.Dispatcher.BeginInvoke(() => { PhoneApplicationFrame frame; PhoneApplicationPage page; CordovaView cView; if (TryCast(Application.Current.RootVisual, out frame) && TryCast(frame.Content, out page) && TryCast(page.FindName("CordovaView"), out cView)) { cView.Browser.Dispatcher.BeginInvoke(() => { try { string pushPayload = JsonConvert.SerializeObject(push); cView.Browser.InvokeScript("eval", "cordova.require(\"com.pushwoosh.plugins.pushwoosh.PushNotification\").notificationCallback(" + pushPayload + ")"); } catch (Exception ex) { Debug.WriteLine("ERROR: Exception in InvokeScriptCallback :: " + ex.Message); } }); } }); }
static public void HandleStartPush(string arguments) { if (arguments != null && arguments.Length != 0) { try { //Sample to handle push custom data on start ToastPush push = SDKHelpers.ParsePushData(arguments); if (push != null) { push.OnStart = true; NotificationService.StartPush = push; NotificationService service = NotificationService.GetCurrent(null); if (service != null) { StatisticRequest request = new StatisticRequest { AppId = service.AppID, Hash = push.Hash }; PushwooshAPIServiceBase.InternalSendRequestAsync(request, null, null); } } } catch { } } }
private void PushAccepted(ToastPush push) { if (OnPushAccepted != null) { OnPushAccepted(this, push); } }
private void ChannelShellToastNotificationReceived(object sender, NotificationEventArgs e) { Debug.WriteLine("/********************************************************/"); Debug.WriteLine("Received Toast: " + DateTime.Now.ToShortTimeString()); foreach (string key in e.Collection.Keys) { Debug.WriteLine("{0}: {1}", key, e.Collection[key]); if (key == "wp:Param") { LastPush = SDKHelpers.ParsePushData(e.Collection[key]); } } Debug.WriteLine("/********************************************************/"); Deployment.Current.Dispatcher.BeginInvoke(() => { var message = new PushNotificationMessage(e.Collection); message.Completed += (o, args) => { if (args.PopUpResult == PopUpResult.Ok) { FireAcceptedPush(); } }; message.Show(); }); }
void service_OnPushAccepted(object sender, ToastPush push) { string pushString = JsonConvert.SerializeObject(push); var alert = new MessageDialog("Notification content: " + pushString + " received"); alert.ShowAsync(); }
private void PushAccepted(ToastPush push) { string pushString = JsonConvert.SerializeObject(push); if (OnPushAccepted != null) { OnPushAccepted(this, pushString); } }
private void internalPushAccepted(object sender, ToastPush push) { string pushPayload = push.ToString(); PushEventArgs args = new PushEventArgs(); args.PushPayload = pushPayload; if (OnPushAccepted != null) { OnPushAccepted(this, args); } }
internal void FireAcceptedPush(ToastPush push) { if (push.Url != null || (push.HtmlId != -1 && push.HtmlId != 0)) { Uri uri = null; if (push.Url != null) { uri = push.Url; } else if (push.HtmlId != -1) { uri = new Uri(Constants.HtmlPageUrl + push.HtmlId, UriKind.Absolute); } Launcher.LaunchUriAsync(uri); } PushAccepted(push); }
internal void FireAcceptedPush(ToastPush push) { Statistic.SendPushOpen(push.Hash); if (push.Url != null || push.HtmlId != -1) { WebBrowserTask webBrowserTask = new WebBrowserTask(); if (push.Url != null) { webBrowserTask.Uri = push.Url; } else if (push.HtmlId != -1) { webBrowserTask.Uri = new Uri(Constants.HtmlPageUrl + push.HtmlId, UriKind.Absolute); } webBrowserTask.Show(); } PushAccepted(push); }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); ToastPush push = SDKHelpers.ParsePushData(e.Uri.ToString()); push.OnStart = true; NotificationService instance = NotificationService.GetCurrent(); if (instance != null) { instance.FireAcceptedPush(push); } else { NotificationService.StartPush = push; } string startPage = "/" + WMAppManifestReader.GetInstance().NavigationPage; ((PhoneApplicationFrame)Application.Current.RootVisual).Navigate(new Uri(startPage, UriKind.RelativeOrAbsolute)); }
private void ChannelShellToastNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs e) { Debug.WriteLine("/********************************************************/"); Debug.WriteLine("Incoming Notification: " + DateTime.Now.ToString()); String notificationContent = String.Empty; ToastPush push = null; String type = String.Empty; switch (e.NotificationType) { case PushNotificationType.Badge: notificationContent = e.BadgeNotification.Content.GetXml(); type = "Badge"; break; case PushNotificationType.Tile: notificationContent = e.TileNotification.Content.GetXml(); type = "Tile"; break; case PushNotificationType.Toast: notificationContent = e.ToastNotification.Content.GetXml(); try { IXmlNode node = e.ToastNotification.Content.DocumentElement.SelectSingleNode("/toast"); IXmlNode launchAttr = node.Attributes.GetNamedItem("launch"); String args = launchAttr.NodeValue.ToString(); push = SDKHelpers.ParsePushData(args); //Sample to handle push custom data on start StatisticRequest request2 = new StatisticRequest { AppId = AppID, Hash = push.Hash }; PushwooshAPIServiceBase.InternalSendRequestAsync(request2, null, null); } catch { } type = "Toast"; break; case PushNotificationType.Raw: notificationContent = e.RawNotification.Content; type = "Raw"; break; } if (push == null) { StatisticRequest request2 = new StatisticRequest { AppId = AppID }; PushwooshAPIServiceBase.InternalSendRequestAsync(request2, null, null); } Debug.WriteLine("Received {0} notification", type); Debug.WriteLine("Notification content: " + notificationContent); CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { try { if (push != null) { FireAcceptedPush(push); } } catch (Exception) { //Noting todo here } }); }