Пример #1
0
        // To receive notifications in foregroung on iOS 9 and below.
        // To receive notifications in background in any iOS version
        public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action <UIBackgroundFetchResult> completionHandler)
        {
            // If you are receiving a notification message while your app is in the background,
            // this callback will not be fired 'till the user taps on the notification launching the application.

            // If you disable method swizzling, you'll need to call this method.
            // This lets FCM track message delivery and analytics, which is performed
            // automatically with method swizzling enabled.
            //Messaging.GetInstance ().AppDidReceiveMessage (userInfo);
            if (NotificationReceived == null)
            {
                return;
            }

            var e = new UserInfoEventArgs {
                UserInfo = userInfo
            };

            NotificationReceived(this, e);

            if (application.ApplicationState == UIApplicationState.Active)
            {
                System.Diagnostics.Debug.WriteLine(userInfo);
                var aps_d   = userInfo["aps"] as NSDictionary;
                var alert_d = aps_d["alert"] as NSDictionary;
                var body    = alert_d["body"] as NSString;
                var title   = alert_d["title"] as NSString;

                System.Diagnostics.Debug.WriteLine($"---> push title={title}, body{body}");
            }
        }
Пример #2
0
        public void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler)
        {
            if (NotificationReceived == null)
            {
                return;
            }

            var e = new UserInfoEventArgs {
                UserInfo = response.Notification.Request.Content.UserInfo
            };

            NotificationReceived(this, e);

            System.Diagnostics.Debug.WriteLine("--->get message " + response.Notification.Date);
        }
Пример #3
0
        public void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, Action <UNNotificationPresentationOptions> completionHandler)
        {
            if (NotificationReceived == null)
            {
                return;
            }

            var e = new UserInfoEventArgs {
                UserInfo = notification.Request.Content.UserInfo
            };

            NotificationReceived(this, e);

            var title = notification.Request.Content.Title;
            var body  = notification.Request.Content.Body;

            System.Diagnostics.Debug.WriteLine($"---> push title={title}, body{body}");
        }