private void HandleGcmNotification(GcmNotificationReceivedEvent theEvent) { RemoteNotificationReceivedEvent internalEvent = null; try { var notificationId = theEvent.Intent.GetStringExtra("notificationId"); var payload = theEvent.Intent.GetStringExtra("payload"); var notificationType = theEvent.Intent.GetStringExtra("type"); var deserialisedPayload = _serialiser.Deserialise<Dictionary<string, object>>(payload); internalEvent = new RemoteNotificationReceivedEvent { NotificationId = notificationId, NotificationType = notificationType, Publisher = DonkyAndroid.Module, Payload = deserialisedPayload }; } catch (Exception exception) { Logger.Instance.LogWarning("Could not parse GCM notification - may not be a Donky notification. Details: {0}", exception.Message); } if (internalEvent != null) { _eventBus.PublishAsync(internalEvent).ExecuteInBackground(); } }
private void HandleApnsNotificationReceived(ApnsNotificationReceivedEvent apnsEvent) { Logger.Instance.LogDebug("Received APNS Push: {0}", apnsEvent.UserInfo.ToString()); var notificationId = apnsEvent.UserInfo.GetValueOrDefault<string>("notificationId", null); if (notificationId != null) { var notificationEvent = new RemoteNotificationReceivedEvent { NotificationId = notificationId, NotificationType = "NOTIFICATIONPENDING", Publisher = DonkyiOS.Module }; _eventBus.PublishAsync(notificationEvent).ExecuteInBackground(); } if (apnsEvent.CompletionHandler != null) { apnsEvent.CompletionHandler(UIBackgroundFetchResult.NoData); } }
private async Task HandleNotificationReceivedInternal(RemoteNotificationReceivedEvent notificationEvent) { Logger.Instance.LogInformation("Processing remote notification of type {0}", notificationEvent.NotificationType); if (notificationEvent.NotificationType == "NOTIFICATIONPENDING") { if (!String.IsNullOrEmpty(notificationEvent.NotificationId)) { await _notificationManager.GetAndProcessNotificationAsync(notificationEvent.NotificationId); } else { Logger.Instance.LogDebug("No notification id found on remote notification - performing a full sync instead"); await _notificationManager.SynchroniseAsync(); } } else { Logger.Instance.LogError("Unexpected notification type {0} from remote notification", notificationEvent.NotificationType); throw new InvalidOperationException("Unexpected notification type"); } }
private void HandleNotificationReceived(RemoteNotificationReceivedEvent notificationEvent) { HandleNotificationReceivedInternal(notificationEvent).ExecuteInBackground(); }