コード例 #1
0
        //
        // This method is invoked when the application has loaded and is ready to run. In this
        // method you should instantiate the window, load the UI into it and then make the window
        // visible.
        //
        // You have 17 seconds to return from this method, or iOS will terminate your application.
        //
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            global::Xamarin.Forms.Forms.Init();
            var xamApp          = new App();
            var permissions     = new iOSRequestPermissions();
            var errorHandler    = new ExceptionHandlerService();
            var locationManager = LocationListener.CreateLocationManager();

            locationManager.AllowsBackgroundLocationUpdates = true;
            if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
            {
                locationManager.ShowsBackgroundLocationIndicator = true;
            }

            var locationService =
                LocationListener
                .CreatePlatform(exceptionHandler: errorHandler, locationManager: locationManager);


            errorHandler
            .OnError
            .Select(x => x as LocationActivationException)
            .Where(x => x?.Reason == ActivationFailedReasons.PermissionsIssue)
            .SelectMany(_ => permissions.Location)
            .Subscribe();

            xamApp
            .MainViewModel
            .SetLocationService(locationService);

            LoadApplication(xamApp);

            return(base.FinishedLaunching(app, options));
        }