Exemple #1
0
        public static void Initialize(NSDictionary options, bool autoRegistration = true)
        {
            if (App.DefaultInstance == null)
            {
                App.Configure();
            }

            CrossFirebasePushNotification.Current.NotificationHandler = CrossFirebasePushNotification.Current.NotificationHandler ?? new DefaultPushNotificationHandler();
            Messaging.SharedInstance.AutoInitEnabled = autoRegistration;

            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(CrossFirebasePushNotification.Current, new FirebasePushNotificationResponseEventArgs(notificationResponse.Data, notificationResponse.Identifier, notificationResponse.Type));

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

            if (autoRegistration)
            {
                CrossFirebasePushNotification.Current.RegisterForPushNotifications();
            }
        }
        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)}");
                    }
                }

                if (parameters.Count > 0)
                {
                    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(CrossFirebasePushNotification.Current, new FirebasePushNotificationResponseEventArgs(response.Data, response.Identifier, response.Type));
                    }


                    CrossFirebasePushNotification.Current.NotificationHandler?.OnOpened(response);
                }
            }
        }
        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 FirebasePushNotificationResponseEventArgs(notificationResponse.Data, notificationResponse.Identifier, notificationResponse.Type));

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

            // Inform caller it has been handled
            completionHandler();
        }
Exemple #4
0
 public void OnOpened(NotificationResponse response)
 {
     System.Diagnostics.Debug.WriteLine($"{DomainTag} - OnOpened");
 }
Exemple #5
0
        internal static void RegisterAction(IDictionary <string, object> data, string identifier = "", NotificationCategoryType type = NotificationCategoryType.Default)
        {
            var response = new NotificationResponse(data, data.ContainsKey(DefaultPushNotificationHandler.ActionIdentifierKey) ? $"{data[DefaultPushNotificationHandler.ActionIdentifierKey]}" : string.Empty);

            _onNotificationAction?.Invoke(CrossFirebasePushNotification.Current, new FirebasePushNotificationResponseEventArgs(response.Data, response.Identifier, response.Type));
        }