public override bool FinishedLaunching(UIApplication uiApplication, NSDictionary launchOptions) { SensusServiceHelper.Initialize(() => new iOSSensusServiceHelper()); // facebook settings Settings.AppID = "873948892650954"; Settings.DisplayName = "Sensus"; Forms.Init(); FormsMaps.Init(); MapExtendRenderer.Init(); // toasts for iOS DependencyService.Register<ToastNotificatorImplementation>(); ToastNotificatorImplementation.Init(); LoadApplication(new App()); uiApplication.RegisterUserNotificationSettings(UIUserNotificationSettings.GetSettingsForTypes(UIUserNotificationType.Badge | UIUserNotificationType.Sound | UIUserNotificationType.Alert, new NSSet())); _serviceHelper = SensusServiceHelper.Get() as iOSSensusServiceHelper; #if UNIT_TESTING Forms.ViewInitialized += (sender, e) => { if (!string.IsNullOrWhiteSpace(e.View.StyleId)) e.NativeView.AccessibilityIdentifier = e.View.StyleId; }; Calabash.Start(); #endif return base.FinishedLaunching(uiApplication, launchOptions); }
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()); } }); } } } }
// 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); }
public override bool FinishedLaunching(UIApplication uiApplication, NSDictionary launchOptions) { SensusServiceHelper.Initialize(() => new iOSSensusServiceHelper()); // facebook settings Settings.AppID = "873948892650954"; Settings.DisplayName = "Sensus"; Forms.Init(); FormsMaps.Init(); MapExtendRenderer.Init(); ToastNotificatorImplementation.Init(); App app = new App(); LoadApplication(app); uiApplication.RegisterUserNotificationSettings(UIUserNotificationSettings.GetSettingsForTypes(UIUserNotificationType.Badge | UIUserNotificationType.Sound | UIUserNotificationType.Alert, new NSSet())); _serviceHelper = SensusServiceHelper.Get() as iOSSensusServiceHelper; UiBoundSensusServiceHelper.Set(_serviceHelper); app.SensusMainPage.DisplayServiceHelper(UiBoundSensusServiceHelper.Get(true)); return(base.FinishedLaunching(uiApplication, launchOptions)); }
// 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; } }
public override async void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken) { // hang on to the token. we register for remote notifications after initializing the helper, // so this should be fine. iOSSensusServiceHelper serviceHelper = SensusServiceHelper.Get() as iOSSensusServiceHelper; serviceHelper.PushNotificationTokenData = deviceToken; // update push notification registrations. this depends on internet connectivity to S3 // so it might hang if connectivity is poor. ensure we don't violate execution limits. CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); nint updatePushNotificationRegistrationsTaskId = application.BeginBackgroundTask(cancellationTokenSource.Cancel); await serviceHelper.UpdatePushNotificationRegistrationsAsync(cancellationTokenSource.Token); application.EndBackgroundTask(updatePushNotificationRegistrationsTaskId); }
// 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); }); }
public override void OnActivated(UIApplication uiApplication) { // since all notifications are about to be rescheduled, clear any scheduled / delivered notifications. UIApplication.SharedApplication.CancelAllLocalNotifications(); UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0; _serviceHelper.ActivationId = Guid.NewGuid().ToString(); iOSSensusServiceHelper sensusServiceHelper = UiBoundSensusServiceHelper.Get(true) as iOSSensusServiceHelper; sensusServiceHelper.StartAsync(() => { sensusServiceHelper.UpdateCallbackNotificationActivationIdsAsync(); }); base.OnActivated(uiApplication); }
// 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); }); }
// 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); }); }
public override void OnActivated(UIApplication uiApplication) { // since all notifications are about to be rescheduled/serviced, clear all current notifications. UIApplication.SharedApplication.CancelAllLocalNotifications(); UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0; iOSSensusServiceHelper serviceHelper = SensusServiceHelper.Get() as iOSSensusServiceHelper; serviceHelper.ActivationId = Guid.NewGuid().ToString(); try { serviceHelper.BarcodeScanner = new ZXing.Mobile.MobileBarcodeScanner(UIApplication.SharedApplication.KeyWindow.RootViewController); } catch (Exception ex) { serviceHelper.Logger.Log("Failed to create barcode scanner: " + ex.Message, LoggingLevel.Normal, GetType()); } serviceHelper.StartAsync(() => { serviceHelper.UpdateCallbackNotificationActivationIdsAsync(); #if UNIT_TESTING // load and run the unit testing protocol string filePath = NSBundle.MainBundle.PathForResource("UnitTestingProtocol", "json"); using (Stream file = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { Protocol.RunUnitTestingProtocol(file); } #endif }); // background authorization will be done implicitly when the location manager is used in probes, but the authorization is // done asynchronously so it's likely that the probes will believe that GPS is not enabled/authorized even though the user // is about to grant access (if they choose). now, the health test should fix this up by checking for GPS and restarting // the probes, but the whole thing will seem strange to the user. instead, prompt the user for background authorization // immediately. this is only done one time after the app is installed and started. new CLLocationManager().RequestAlwaysAuthorization(); base.OnActivated(uiApplication); }
public override void OnActivated(UIApplication uiApplication) { iOSSensusServiceHelper serviceHelper = SensusServiceHelper.Get() as iOSSensusServiceHelper; serviceHelper.StartAsync(async() => { await(SensusContext.Current.CallbackScheduler as IiOSCallbackScheduler).UpdateCallbacksAsync(); #if UI_TESTING // load and run the UI testing protocol string filePath = NSBundle.MainBundle.PathForResource("UiTestingProtocol", "json"); using (Stream file = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { Protocol.RunUiTestingProtocol(file); } #endif }); base.OnActivated(uiApplication); }
// 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); }
public override bool FinishedLaunching(UIApplication uiApplication, NSDictionary launchOptions) { SensusServiceHelper.Initialize(() => new iOSSensusServiceHelper()); // facebook settings Settings.AppID = "873948892650954"; Settings.DisplayName = "Sensus"; Forms.Init(); FormsMaps.Init(); MapExtendRenderer.Init(); ToastNotificatorImplementation.Init(); App app = new App(); LoadApplication(app); uiApplication.RegisterUserNotificationSettings(UIUserNotificationSettings.GetSettingsForTypes(UIUserNotificationType.Badge | UIUserNotificationType.Sound | UIUserNotificationType.Alert, new NSSet())); _serviceHelper = SensusServiceHelper.Get() as iOSSensusServiceHelper; UiBoundSensusServiceHelper.Set(_serviceHelper); app.SensusMainPage.DisplayServiceHelper(UiBoundSensusServiceHelper.Get(true)); if (launchOptions != null) { NSObject launchOptionValue; if (launchOptions.TryGetValue(UIApplication.LaunchOptionsLocalNotificationKey, out launchOptionValue)) ServiceNotificationAsync(launchOptionValue as UILocalNotification); else if (launchOptions.TryGetValue(UIApplication.LaunchOptionsUrlKey, out launchOptionValue)) Protocol.DisplayFromBytesAsync(File.ReadAllBytes((launchOptionValue as NSUrl).Path)); } // service all other notifications whose fire time has passed foreach (UILocalNotification notification in uiApplication.ScheduledLocalNotifications) if (notification.FireDate.ToDateTime() <= DateTime.UtcNow) ServiceNotificationAsync(notification); return base.FinishedLaunching(uiApplication, launchOptions); }
public override bool FinishedLaunching(UIApplication uiApplication, NSDictionary launchOptions) { SensusServiceHelper.Initialize(() => new iOSSensusServiceHelper()); // facebook settings Settings.AppID = "873948892650954"; Settings.DisplayName = "Sensus"; Forms.Init(); FormsMaps.Init(); MapExtendRenderer.Init(); ToastNotificatorImplementation.Init(); App app = new App(); LoadApplication(app); uiApplication.RegisterUserNotificationSettings(UIUserNotificationSettings.GetSettingsForTypes(UIUserNotificationType.Badge | UIUserNotificationType.Sound | UIUserNotificationType.Alert, new NSSet())); _serviceHelper = SensusServiceHelper.Get() as iOSSensusServiceHelper; UiBoundSensusServiceHelper.Set(_serviceHelper); app.SensusMainPage.DisplayServiceHelper(UiBoundSensusServiceHelper.Get(true)); return base.FinishedLaunching(uiApplication, launchOptions); }