Beispiel #1
0
        public static void Initialize(string notificationHubConnectionString, string notificationHubPath, NSDictionary options, bool autoRegistration = true, bool enableDelayedResponse = true)
        {
            Hub               = new SBNotificationHub(notificationHubConnectionString, notificationHubPath);
            TokenKey          = new NSString($"{notificationHubPath}_Token");
            PushRegisteredKey = $"{notificationHubPath}_PushRegistered";
            CrossAzurePushNotification.Current.NotificationHandler = CrossAzurePushNotification.Current.NotificationHandler ?? new DefaultPushNotificationHandler();

            if (options?.ContainsKey(UIApplication.LaunchOptionsRemoteNotificationKey) ?? false)
            {
                var pushPayload = options[UIApplication.LaunchOptionsRemoteNotificationKey] as NSDictionary;
                if (pushPayload != null)
                {
                    var parameters = GetParameters(pushPayload);

                    var notificationResponse = new NotificationResponse(parameters, string.Empty, NotificationCategoryType.Default);

                    if (_onNotificationOpened == null && enableDelayedResponse)
                    {
                        delayedNotificationResponse = notificationResponse;
                    }
                    else
                    {
                        _onNotificationOpened?.Invoke(CrossAzurePushNotification.Current, new AzurePushNotificationResponseEventArgs(notificationResponse.Data, notificationResponse.Identifier, notificationResponse.Type));
                    }

                    CrossAzurePushNotification.Current.NotificationHandler?.OnOpened(notificationResponse);
                }
            }

            if (autoRegistration)
            {
                CrossAzurePushNotification.Current.RegisterForPushNotifications();
            }
        }
Beispiel #2
0
        public static void ProcessIntent(Activity activity, Intent intent, bool enableDelayedResponse = true)
        {
            DefaultNotificationActivityType = activity.GetType();
            Bundle extras = intent?.Extras;

            if (extras != null && !extras.IsEmpty)
            {
                var parameters = new Dictionary <string, object>();
                foreach (var key in extras.KeySet())
                {
                    if (!parameters.ContainsKey(key) && extras.Get(key) != null)
                    {
                        parameters.Add(key, $"{extras.Get(key)}");
                    }
                }

                NotificationManager manager = _context.GetSystemService(Context.NotificationService) as NotificationManager;
                var notificationId          = extras.GetInt(DefaultPushNotificationHandler.ActionNotificationIdKey, -1);
                if (notificationId != -1)
                {
                    var notificationTag = extras.GetString(DefaultPushNotificationHandler.ActionNotificationTagKey, string.Empty);
                    if (notificationTag == null)
                    {
                        manager.Cancel(notificationId);
                    }
                    else
                    {
                        manager.Cancel(notificationTag, notificationId);
                    }
                }


                var response = new NotificationResponse(parameters, extras.GetString(DefaultPushNotificationHandler.ActionIdentifierKey, string.Empty));

                if (_onNotificationOpened == null && enableDelayedResponse)
                {
                    delayedNotificationResponse = response;
                }
                else
                {
                    _onNotificationOpened?.Invoke(CrossAzurePushNotification.Current, new AzurePushNotificationResponseEventArgs(response.Data, response.Identifier, response.Type));
                }

                CrossAzurePushNotification.Current.NotificationHandler?.OnOpened(response);
            }
        }
Beispiel #3
0
        public void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler)
        {
            var parameters = GetParameters(response.Notification.Request.Content.UserInfo);

            NotificationCategoryType catType = NotificationCategoryType.Default;

            if (response.IsCustomAction)
            {
                catType = NotificationCategoryType.Custom;
            }
            else if (response.IsDismissAction)
            {
                catType = NotificationCategoryType.Dismiss;
            }

            var notificationResponse = new NotificationResponse(parameters, $"{response.ActionIdentifier}".Equals("com.apple.UNNotificationDefaultActionIdentifier", StringComparison.CurrentCultureIgnoreCase) ? string.Empty : $"{response.ActionIdentifier}", catType);

            _onNotificationOpened?.Invoke(this, new AzurePushNotificationResponseEventArgs(notificationResponse.Data, notificationResponse.Identifier, notificationResponse.Type));

            CrossAzurePushNotification.Current.NotificationHandler?.OnOpened(notificationResponse);

            // Inform caller it has been handled
            completionHandler();
        }
Beispiel #4
0
 public virtual void OnOpened(NotificationResponse response)
 {
     System.Diagnostics.Debug.WriteLine($"{DomainTag} - OnOpened");
 }