Пример #1
0
        public override void ReceivedLocalNotification(UIApplication application, UILocalNotification notification)
        {
            if (notification.UserInfo != null)
            {
                iOSSensusServiceHelper serviceHelper = SensusServiceHelper.Get() as iOSSensusServiceHelper;

                // check whether this is a callback notification and service it if it is
                NSNumber isCallbackValue = notification.UserInfo.ValueForKey(new NSString(SensusServiceHelper.SENSUS_CALLBACK_KEY)) as NSNumber;
                if (isCallbackValue?.BoolValue ?? false)
                {
                    serviceHelper.ServiceCallbackNotificationAsync(notification);
                }

                // check whether the user opened a pending-survey notification (indicated by an application state that is not active). we'll
                // also get notifications when the app is active, due to how we manage pending-survey notifications.
                if (application.ApplicationState != UIApplicationState.Active)
                {
                    NSString notificationId = notification.UserInfo.ValueForKey(new NSString(SensusServiceHelper.NOTIFICATION_ID_KEY)) as NSString;
                    if (notificationId != null && notificationId.ToString() == SensusServiceHelper.PENDING_SURVEY_NOTIFICATION_ID)
                    {
                        // display the pending scripts page if it is not already on the top of the navigation stack
                        SensusContext.Current.MainThreadSynchronizer.ExecuteThreadSafe(async() =>
                        {
                            IReadOnlyList <Page> navigationStack = Xamarin.Forms.Application.Current.MainPage.Navigation.NavigationStack;
                            Page topPage = navigationStack.Count == 0 ? null : navigationStack.Last();
                            if (!(topPage is PendingScriptsPage))
                            {
                                await Xamarin.Forms.Application.Current.MainPage.Navigation.PushAsync(new PendingScriptsPage());
                            }
                        });
                    }
                }
            }
        }
Пример #2
0
 private void ServiceNotificationAsync(UILocalNotification notification)
 {
     if (notification.UserInfo != null)
     {
         NSNumber isCallbackValue = notification.UserInfo.ValueForKey(new NSString(SensusServiceHelper.SENSUS_CALLBACK_KEY)) as NSNumber;
         if (isCallbackValue != null && isCallbackValue.BoolValue)
         {
             _serviceHelper.ServiceCallbackNotificationAsync(notification);
         }
     }
 }