public void SendNotification(PushNotificationData data) { if (CheckPlatform) { m_adjObjTable[(int)ANDROID_PLUGIN_TYPE.TYPE_PUSH].CallStatic("sendNativePush", data.id.ToString(), data.title, data.message, data.tickerMsg, (long)Util.GetDateTimeToUnixTime(data.dateTime)); } }
public static PushNotificationData GetNotificationData(RemoteMessage message) { /* * JSON Sample for notifications * * * * { * "data": { * "title": "", * "body": "", * "action": 0, // Default value 0 stands for plain message (title and body) * "payload": { // Optional. A custom JSON payload to be used in conjunction with the action } * } * } * */ if (message == null) { return(null); } var data = new PushNotificationData(); data.Add("title", message.Data.ContainsKey("title") ? message.Data["title"] : null); data.Add("body", message.Data.ContainsKey("body") ? message.Data["body"] : null); data.Add("action", message.Data.ContainsKey("action") ? Int32.Parse(message.Data["action"]) : 0); data.Add("payload", message.Data.ContainsKey("payload") ? message.Data["payload"] : null); return(data); }
private async Task SendMessageAsync <T>(PushType type, T payload, bool excludeCurrentContext) { var contextId = GetContextIdentifier(excludeCurrentContext); var request = new PushNotificationData <T>(type, payload, contextId); await SendAsync(HttpMethod.Post, "send", request); }
protected override void OnMessage(Context context, Intent intent) { var payloadString = intent.Extras.GetString("payload"); PushNotificationData data = JsonConvert.DeserializeObject <PushNotificationData> (payloadString); string title = ""; string detail = ""; PushNotificationUtils.GetDetailedActionDescription(data, out title, out detail); long[] vibratePattern = { 0, 500, 100, 200, 100, 200 }; Intent todoIntent = new Intent(context, typeof(MyGamesActivity)); PendingIntent pendingIntent = PendingIntent.GetActivity(context, 123, todoIntent, PendingIntentFlags.CancelCurrent); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .SetContentTitle(title) .SetContentText(detail) .SetSmallIcon(Resource.Drawable.Icon) .SetVibrate(vibratePattern) .SetLights(Color.Purple.ToArgb(), 1000, 2000) .SetContentIntent(pendingIntent) .SetOnlyAlertOnce(true); if (!string.IsNullOrEmpty(data.ThumbnailUri)) { WebClient client = new WebClient(); var imgData = client.DownloadData(data.ThumbnailUri); var bmp = BitmapFactory.DecodeByteArray(imgData, 0, imgData.Length); builder.SetLargeIcon(bmp); } // Obtain a reference to the NotificationManager var notification = builder.Build(); NotificationManager notificationManager = (NotificationManager)GetSystemService(Context.NotificationService); notificationManager.Notify(125165626, notification); }
public void HandlePushNotification(PushNotificationData notification) { int action = (int)notification["action"]; string payload = (string)notification["payload"]; PushNotificationReceived?.Invoke(this, new PushNotificationEventArgs(action, payload)); }
public void SendNotification(PushNotificationData data) { Debug.Log(string.Format("{0} >> PushMessage : {1} - {2} - {3}", Util.GetNowDateGameTime(), data.id, data.message, data.dateTime)); #if UNITY_ANDROID m_adPlugin.SendNotification(data); #elif UNITY_IOS m_ipPlugin.SendNotification(data); #else #endif }
public override void OnCreate() { base.OnCreate(); PushNotificationData notification = null; if (AppKitFirebaseMessagingService.HasStartUpNotification(out notification)) { PushNotificationManager.Current.StorePendingNotification(notification); } }
public override void OnMessageReceived(RemoteMessage message) { if (AppKitApplication.Current == null || !AppKitApplication.Current.IsApplicationInForeground) { var data = GetNotificationData(message); string title = (string)data["title"]; string text = (string)data["body"]; if (AppKitApplication.Current == null) { _launchNotification = data; } Intent intent = new Intent(); intent.AddFlags(ActivityFlags.ReorderToFront); intent.SetComponent(GetRootActivityComponentName()); PendingIntent pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.UpdateCurrent); var notificationBuilder = new NotificationCompat.Builder(this) .SetSmallIcon(GetSmallIconResourceId()) .SetContentIntent(pendingIntent) .SetContentTitle(title) .SetContentText(text) .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification)) .SetAutoCancel(true); if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { notificationBuilder.SetDefaults(NotificationCompat.DefaultVibrate); notificationBuilder.SetPriority(NotificationCompat.PriorityDefault); notificationBuilder.SetVibrate(new long[] { 50, 50 }); } string channelID = "PushMainChannel"; if (Build.VERSION.SdkInt >= BuildVersionCodes.O) { NotificationChannel channel = new NotificationChannel(channelID, "PushMainChannel", NotificationImportance.High); notificationBuilder.SetChannelId(channelID); var notificationManager = NotificationManager.FromContext(this); notificationManager.CreateNotificationChannel(channel); notificationManager.Notify(0, notificationBuilder.Build()); } else { var notificationManager = NotificationManager.FromContext(this); notificationManager.Notify(0, notificationBuilder.Build()); } } AppKitApplication.Current?.OnReceivedRemoteNotification(message); }
public void SendNotification(PushNotificationData data) { if (CheckPlatform) { UnityEngine.iOS.LocalNotification iosNoti = new UnityEngine.iOS.LocalNotification(); iosNoti.fireDate = data.dateTime; iosNoti.alertAction = data.title; iosNoti.alertBody = data.message; iosNoti.hasAction = true; iosNoti.userInfo.Add(PushManager.NOTIFICATION_ID, data.id); UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(iosNoti); } }
public static bool HasStartUpNotification(out PushNotificationData launchNotification) { launchNotification = null; if (_launchNotification == null) { return(false); } launchNotification = _launchNotification; _launchNotification = null; return(true); }
public static async Task SendNotificationToHubAsync(PushNotificationData <object> notification, IHubContext <NotificationsHub> hubContext, CancellationToken cancellationToken = default(CancellationToken)) { switch (notification.Type) { case Core.Enums.PushType.SyncCipherUpdate: case Core.Enums.PushType.SyncCipherCreate: case Core.Enums.PushType.SyncCipherDelete: case Core.Enums.PushType.SyncLoginDelete: var cipherPayload = JsonConvert.DeserializeObject <SyncCipherPushNotification>( JsonConvert.SerializeObject(notification.Payload)); if (cipherPayload.UserId.HasValue) { await hubContext.Clients.User(cipherPayload.UserId.ToString()) .SendAsync("ReceiveMessage", notification, cancellationToken); } else if (cipherPayload.OrganizationId.HasValue) { await hubContext.Clients.Group( $"Organization_{cipherPayload.OrganizationId}") .SendAsync("ReceiveMessage", notification, cancellationToken); } break; case Core.Enums.PushType.SyncFolderUpdate: case Core.Enums.PushType.SyncFolderCreate: case Core.Enums.PushType.SyncFolderDelete: var folderPayload = JsonConvert.DeserializeObject <SyncFolderPushNotification>( JsonConvert.SerializeObject(notification.Payload)); await hubContext.Clients.User(folderPayload.UserId.ToString()) .SendAsync("ReceiveMessage", notification, cancellationToken); break; case Core.Enums.PushType.SyncCiphers: case Core.Enums.PushType.SyncVault: case Core.Enums.PushType.SyncOrgKeys: case Core.Enums.PushType.SyncSettings: var userPayload = JsonConvert.DeserializeObject <SyncUserPushNotification>( JsonConvert.SerializeObject(notification.Payload)); await hubContext.Clients.User(userPayload.UserId.ToString()) .SendAsync("ReceiveMessage", notification, cancellationToken); break; default: break; } }
protected bool RegisterMainLauncher(UIViewController mainViewController, NSDictionary launchOptions) { PushNotificationData notification = null; if (!AppKitApnMessagingService.HandleStartUpNotification(launchOptions, out notification)) { PushNotificationManager.Current.StorePendingNotification(notification); } this.Window = new UIWindow(UIScreen.MainScreen.Bounds); this.Window.RootViewController = mainViewController; this.Window.MakeKeyAndVisible(); return(true); }
public IHttpActionResult Test(string registrationId) { var notification = new PushNotificationData { Action = 1, Message = "Test notification", Data = new { payload = "Test payload" } }; //new GcmProvider().CreateNotification(notification, registrationId).SendAsync().Wait(); return(Ok(new ApiResponse(200, notification))); }
public static bool HandleStartUpNotification(NSDictionary launchOptions, out PushNotificationData launchNotification) { launchNotification = null; if (launchOptions != null && launchOptions.ContainsKey(UIApplication.LaunchOptionsRemoteNotificationKey)) { var message = launchOptions.ObjectForKey(UIApplication.LaunchOptionsRemoteNotificationKey) as NSDictionary; if (message != null) { launchNotification = GetNotificationData(message); return(true); } } return(false); }
public PushNotificationData ConsumePendingNotification(bool notify = false) { if (_pendingNotification == null) { return(null); } PushNotificationData notification = _pendingNotification; _pendingNotification = null; if (notify) { HandlePushNotification(notification); } return(notification); }
public static async Task ProcessPushNotification() { var data = PushNotificationData; if (data != null) { PushNotificationData = null; if (Current.MainPage.Navigation.NavigationStack.LastOrDefault() is BaseContentPage currentPage) { if (!string.IsNullOrEmpty(data.DocumentId)) { await currentPage.OpenDetailPage(data.DocumentId, true); } var rootContentUI = new RootContentUI(); await currentPage.DisplayAlert(data.Title, data.Text, rootContentUI.TxtOk); } } }
public static async void OnNotificationOpened(object source, FirebasePushNotificationResponseEventArgs e) { if (e.Identifier != "cancel") { string title = null; string text = null; if (e.Data.ContainsKey("title") && e.Data.ContainsKey("body")) { title = e.Data["title"]?.ToString(); text = e.Data["body"]?.ToString(); } if (e.Data.ContainsKey("aps.alert.title") && e.Data.ContainsKey("aps.alert.body")) { title = e.Data["aps.alert.title"]?.ToString(); text = e.Data["aps.alert.body"]?.ToString(); } if (!string.IsNullOrEmpty(title) || !string.IsNullOrEmpty(text)) { e.Data.TryGetValue("documentId", out var id); var documentId = id?.ToString(); PushNotificationData = new PushNotificationData { Title = title, Text = text, DocumentId = documentId }; if (RootPage != null) { await ProcessPushNotification(); } } } }
public void StorePendingNotification(PushNotificationData notification) { _pendingNotification = notification; }
public async Task PostNotification([FromBody] PushNotificationData <object> model) { await HubHelpers.SendNotificationToHubAsync(model, _hubContext); }
public virtual void OnReceivedRemoteNotification(RemoteMessage message) { PushNotificationData notification = AppKitFirebaseMessagingService.GetNotificationData(message); OnReceivedRemoteNotification(notification); }
public bool OnPushNotificationClicked(Context p0, PushNotificationData p1) { Log.Debug("WebEngageTest", "Push notification clicked"); return(false); }
public PushNotificationData OnPushNotificationReceived(Context p0, PushNotificationData p1) { Log.Debug("WebEngageTest", "Push notification received"); return(p1); }
public void UpdatePushData(PushNotificationData pushData) { PushNotificationData = pushData; }
public static PushNotificationData GetNotificationData(NSDictionary message) { /* * JSON Sample for notifications * * * * { * "aps":{ * "alert": { * "title": "", * "body": "" * } * }, * "data":{ * "action": 0, // Default value 0 stands for plain message (title and body) * "payload":{ // Optional. A custom JSON payload to be used in conjunction with the action } * } * } * */ if (message == null) { return(null); } PushNotificationData notification = new PushNotificationData(); // Are we getting this from an "remote notification launch options" ? if (message.ContainsKey(UIApplication.LaunchOptionsRemoteNotificationKey)) { message = (NSDictionary)message.ObjectForKey(UIApplication.LaunchOptionsRemoteNotificationKey); } // Check to see if the dictionary has the aps key. // This is the notification payload you would have sent if (message.ContainsKey(new NSString("aps"))) { //Get the aps dictionary NSDictionary aps = message.ObjectForKey(new NSString("aps")) as NSDictionary; if (aps != null) { //Extract the alert text // NOTE: If you're using the simple alert by just specifying // " aps:{alert:"alert msg here"} ", this will work fine. // But if you're using a complex alert with Localization keys, etc., // your "alert" object from the aps dictionary will be another NSDictionary. // Basically the JSON gets dumped right into a NSDictionary, // so keep that in mind. if (aps.ContainsKey(new NSString("alert"))) { if (aps.ObjectForKey(new NSString("alert")) is NSString) { var alert = aps.ObjectForKey(new NSString("alert")) as NSString; notification.Add("title", null); notification.Add("body", alert.ToString()); } else if (aps.ObjectForKey(new NSString("alert")) is NSDictionary) { var alert = aps.ObjectForKey(new NSString("alert")) as NSDictionary; if (alert != null) { if (alert.ContainsKey(new NSString("title"))) { notification.Add("title", alert.ObjectForKey(new NSString("title")).ToString()); } if (alert.ContainsKey(new NSString("body"))) { notification.Add("body", alert.ObjectForKey(new NSString("body")).ToString()); } } } } } } // Check to see if the dictionary has the data key. // This is the custom payload you would have sent if (message.ContainsKey(new NSString("data"))) { //Get the data dictionary NSDictionary data = message.ObjectForKey(new NSString("data")) as NSDictionary; if (data != null) { notification.Add("action", (data.ObjectForKey(new NSString("action")) as NSNumber).Int32Value); if (data.ContainsKey(new NSString("payload"))) { if (data.ObjectForKey(new NSString("payload")) is NSString) { NSString payload = data.ObjectForKey(new NSString("payload")) as NSString; notification.Add("payload", payload.ToString()); } else if (data.ObjectForKey(new NSString("payload")) is NSDictionary) { NSDictionary target = data.ObjectForKey(new NSString("payload")) as NSDictionary; if (target != null) { NSError error = null; NSData d = NSJsonSerialization.Serialize(target, NSJsonWritingOptions.PrettyPrinted, out error); NSString json = NSString.FromData(d, NSStringEncoding.UTF8); notification.Add("payload", json.ToString()); } } } } } else { notification.Add("action", 0); notification.Add("payload", null); } return(notification); }
public virtual void ReceivedRemoteNotification(PushNotificationData data) { }
public void OnPushNotificationDismissed(Context p0, PushNotificationData p1) { Log.Debug("WebEngageTest", "Push notification dismissed"); }
public override void ReceivedRemoteNotification(UIApplication application, NSDictionary userInfo) { PushNotificationData notification = AppKitApnMessagingService.GetNotificationData(userInfo); ReceivedRemoteNotification(notification); }
public void OnPushNotificationShown(Context p0, PushNotificationData p1) { Log.Debug("WebEngageTest", "Push notification shown"); }