Beispiel #1
0
        private void NotificationRouter(LocalNotificationTappedEvent e)
        {
            var route = e.Data.Split('/');

            switch (route[1])
            {
            case "consultation":
                try
                {
                    Console.WriteLine("Notification Poll " + route[2]);
                    ((MainPage)MainPage).CurrentPage.Navigation.PushAsync(new PollDetailsPage(route[2]));
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
                return;

            case "news":
                try
                {
                    Console.WriteLine("Notification News " + route[2]);
                    ((MainPage)MainPage).CurrentPage.Navigation.PushAsync(new NewsDetailsView(new NewsDetailsViewModel(new Guid(route[2]), "News")));
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception);
                }
                return;
            }
        }
        /// <inheritdoc />
        public override void DidReceiveNotificationResponse(UNUserNotificationCenter center,
                                                            UNNotificationResponse response, Action completionHandler)
        {
            try
            {
                // Take action based on identifier
                if (!response.IsDefaultAction)
                {
                    return;
                }

                var dictionary = response.Notification.Request.Content.UserInfo;

                if (!dictionary.ContainsKey(LocalNotificationService.ExtraReturnData))
                {
                    return;
                }

                var subscribeItem = new LocalNotificationTappedEvent
                {
                    Data = dictionary[LocalNotificationService.ExtraReturnData].ToString()
                };
                MessagingCenter.Send(subscribeItem, typeof(LocalNotificationTappedEvent).FullName);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }
        /// <summary>
        /// Show notification in iOS 8 , 9
        /// </summary>
        /// <param name="notification"></param>
        public static void NotifyNotificationTapped(UILocalNotification notification)
        {
            try
            {
                var dictionary = notification.UserInfo;

                if (!dictionary.ContainsKey(LocalNotificationService.ExtraReturnData))
                {
                    return;
                }

                var subscribeItem = new LocalNotificationTappedEvent
                {
                    Data = dictionary[LocalNotificationService.ExtraReturnData].ToString()
                };

                Device.BeginInvokeOnMainThread(() =>
                {
                    MessagingCenter.Instance.Send(subscribeItem, typeof(LocalNotificationTappedEvent).FullName);
                });
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
            }
        }
        private void LoadPageFromNotification(LocalNotificationTappedEvent e)
        {
            if (string.IsNullOrWhiteSpace(e.Data))
            {
                return;
            }

            var list = ObjectSerializer <List <string> > .DeserializeObject(e.Data);

            if (list.Count != 2)
            {
                return;
            }
            if (list[0] != typeof(NotificationPage).FullName)
            {
                return;
            }
            var tapCount = list[1];

            MainPage = new NotificationPage(int.Parse(tapCount));
        }
        /// <summary>
        /// Notify Local Notification Tapped.
        /// </summary>
        /// <param name="intent"></param>
        public static void NotifyNotificationTapped(Intent intent)
        {
            try
            {
                if (intent.HasExtra(ExtraReturnData) == false)
                {
                    return;
                }

                var subscribeItem = new LocalNotificationTappedEvent
                {
                    Data = intent.GetStringExtra(ExtraReturnData)
                };
                Xamarin.Forms.Device.BeginInvokeOnMainThread(() =>
                {
                    Xamarin.Forms.MessagingCenter.Instance.Send(subscribeItem, typeof(LocalNotificationTappedEvent).FullName);
                });
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
            }
        }
Beispiel #6
0
 private void OnLocalNotificationTapped(LocalNotificationTappedEvent e)
 {
     //Debug.WriteLine("Local Notification Tapped: " + e.Data);
 }
Beispiel #7
0
 private void OnLocalNotificationTapped(LocalNotificationTappedEvent obj)
 {
 }