Example #1
0
        // This method should be used to release shared resources and it should store the application state.
        // If your application supports background exection this method is called instead of WillTerminate
        // when the user quits.
        public async override void DidEnterBackground(UIApplication uiApplication)
        {
            nint enterBackgroundTaskId = uiApplication.BeginBackgroundTask(() =>
            {
                // not much to do if we run out of time. just report it.
                string message = "Ran out of background time while entering background.";
                SensusServiceHelper.Get().Logger.Log(message, LoggingLevel.Normal, GetType());
                SensusException.Report(message);
            });

            iOSSensusServiceHelper serviceHelper = SensusServiceHelper.Get() as iOSSensusServiceHelper;

            // if the callback scheduler is timer-based and gps is not running then we need to request remote notifications
            if (SensusContext.Current.CallbackScheduler is iOSTimerCallbackScheduler scheduler)
            {
                bool gpsIsRunning = SensusServiceHelper.Get().GetRunningProtocols().SelectMany(x => x.Probes).OfType <ListeningLocationProbe>().Any(x => x.Enabled);

                await scheduler.RequestNotificationsAsync(gpsIsRunning);
            }

            // save app state
            await serviceHelper.SaveAsync();

            uiApplication.EndBackgroundTask(enterBackgroundTaskId);
        }
Example #2
0
        // This method should be used to release shared resources and it should store the application state.
        // If your application supports background exection this method is called instead of WillTerminate
        // when the user quits.
        public override void DidEnterBackground(UIApplication application)
        {
            iOSSensusServiceHelper serviceHelper = UiBoundSensusServiceHelper.Get(false) as iOSSensusServiceHelper;

            if (serviceHelper != null)
            {
                serviceHelper.SaveAsync();

                // app is no longer active, so reset the activation ID
                serviceHelper.ActivationId = null;
            }
        }
Example #3
0
        // This method should be used to release shared resources and it should store the application state.
        // If your application supports background exection this method is called instead of WillTerminate
        // when the user quits.
        public override void DidEnterBackground(UIApplication uiApplication)
        {
            (SensusContext.Current.CallbackScheduler as iOSCallbackScheduler).CancelSilentNotifications();

            iOSSensusServiceHelper serviceHelper = SensusServiceHelper.Get() as iOSSensusServiceHelper;

            // save app state in background
            nint saveTaskId = uiApplication.BeginBackgroundTask(() =>
            {
                // not much we can do if we run out of time...
            });

            serviceHelper.SaveAsync().ContinueWith(finishedTask =>
            {
                uiApplication.EndBackgroundTask(saveTaskId);
            });
        }
Example #4
0
        // This method should be used to release shared resources and it should store the application state.
        // If your application supports background exection this method is called instead of WillTerminate
        // when the user quits.
        public override void DidEnterBackground(UIApplication uiApplication)
        {
            (SensusContext.Current.Notifier as IiOSNotifier).CancelSilentNotifications();

            iOSSensusServiceHelper serviceHelper = SensusServiceHelper.Get() as iOSSensusServiceHelper;

            serviceHelper.IssuePendingSurveysNotificationAsync(true, true);

            // save app state in background
            nint saveTaskId = uiApplication.BeginBackgroundTask(() =>
            {
            });

            serviceHelper.SaveAsync(() =>
            {
                uiApplication.EndBackgroundTask(saveTaskId);
            });
        }
Example #5
0
        // This method should be used to release shared resources and it should store the application state.
        // If your application supports background exection this method is called instead of WillTerminate
        // when the user quits.
        public override void DidEnterBackground(UIApplication uiApplication)
        {
            iOSSensusServiceHelper serviceHelper = SensusServiceHelper.Get() as iOSSensusServiceHelper;

            // app is no longer active, so reset the activation ID
            serviceHelper.ActivationId = null;

            serviceHelper.IssuePendingSurveysNotificationAsync(true, true);

            // save app state in background
            nint saveTaskId = uiApplication.BeginBackgroundTask(() =>
            {
            });

            serviceHelper.SaveAsync(() =>
            {
                uiApplication.EndBackgroundTask(saveTaskId);
            });
        }
Example #6
0
        // This method should be used to release shared resources and it should store the application state.
        // If your application supports background exection this method is called instead of WillTerminate
        // when the user quits.
        public async override void DidEnterBackground(UIApplication uiApplication)
        {
            nint enterBackgroundTaskId = uiApplication.BeginBackgroundTask(() =>
            {
                // not much to do if we run out of time. just report it.
                string message = "Ran out of background time while entering background.";
                SensusServiceHelper.Get().Logger.Log(message, LoggingLevel.Normal, GetType());
                SensusException.Report(message);
            });

            iOSSensusServiceHelper serviceHelper = SensusServiceHelper.Get() as iOSSensusServiceHelper;

            // cancel all silent notifications, which should never be presented to the user. if these notifications
            // are not cancelled and the app enters the background, then they will appear in the notification
            // tray and confuse the user.
            (SensusContext.Current.CallbackScheduler as iOSCallbackScheduler).CancelSilentNotifications();

            // save app state
            await serviceHelper.SaveAsync();

            uiApplication.EndBackgroundTask(enterBackgroundTaskId);
        }