public void RequestAccess(AccessType accessType) { _AccessType = accessType; var s = (accessType == AccessType.Full) ? "requestAlwaysAuthorization" : "requestWhenInUseAuthorization"; if (_Manager.RespondsToSelector(new Selector(s))) { _Manager.RequestAlwaysAuthorization(); } }
public override void ViewDidAppear(bool animated) { base.ViewDidAppear(animated); ViewModel.Title = "Acquiring location…"; if (locationManager == null) { locationManager = new CLLocationManager(); locationManager.DesiredAccuracy = CLLocation.AccuracyNearestTenMeters; locationManager.Delegate = this; if (locationManager.RespondsToSelector(new ObjCRuntime.Selector("requestWhenInUseAuthorization"))) { locationManager.RequestWhenInUseAuthorization(); } } StartTimer(); if (Mvx.Resolve <ICacheService>().SearchMode == SearchMode.Now) //park me now { Start60sTimer(); locationManager.StartUpdatingLocation(); Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this.ViewModel, true, string.Empty, true)); } else //park me later { ViewModel.GetParkingLists(); } ViewModel.UpdateValidTime(); }
public override void ViewDidLoad() { base.ViewDidLoad(); CLLocationManager locationManager = new CLLocationManager(); if (locationManager.RespondsToSelector(new ObjCRuntime.Selector("requestWhenInUseAuthorization"))) { locationManager.RequestWhenInUseAuthorization(); } MKPointAnnotation pinView = new MKPointAnnotation(); pinView.Title = "Teste"; pinView.SetCoordinate(new CoreLocation.CLLocationCoordinate2D(-23.548428, -46.631834)); mapa.AddAnnotation(pinView); mapa.Camera = new MKMapCamera() { CenterCoordinate = new CoreLocation.CLLocationCoordinate2D(-23.548428, -46.631834), Altitude = 3000 }; // Perform any additional setup after loading the view, typically from a nib. }
/// <summary> /// Initializes a new instance of the <see cref="Geolocator"/> class. /// </summary> public Geolocator() { _manager = GetManager(); _manager.AuthorizationChanged += OnAuthorizationChanged; _manager.Failed += OnFailed; if (_manager.RespondsToSelector(new Selector("requestWhenInUseAuthorization"))) { _manager.RequestWhenInUseAuthorization(); } if (!CLLocationManager.LocationServicesEnabled) { return; } if (UIDevice.CurrentDevice.CheckSystemVersion(6, 0)) { _manager.LocationsUpdated += OnLocationsUpdated; } else { _manager.UpdatedLocation += OnUpdatedLocation; } _manager.UpdatedHeading += OnUpdatedHeading; }
public override void ViewWillAppear(bool animated) { base.ViewWillAppear(animated); if (ViewModel.Status != Mvx.Resolve <ICacheService>().NextStatus) { ViewModel.UpdateTasksStatus(Mvx.Resolve <ICacheService>().NextStatus); } if (ViewModel.Parking != null && Mvx.Resolve <ICacheService>().CreateParkingRequest != null && Mvx.Resolve <ICacheService>().CreateParkingRequest.HourlyRate != null) { ViewModel.Parking.HourlyRate = Mvx.Resolve <ICacheService>().CreateParkingRequest.HourlyRate; } if (ViewModel.Status == AddSpotStatus.GPS) { if (locationManager == null) { locationManager = new CLLocationManager(); locationManager.DesiredAccuracy = CLLocation.AccuracyBest; locationManager.Delegate = this; // Check for iOS 8. Without this guard the code will crash with "unknown selector" on iOS 7. if (locationManager.RespondsToSelector(new ObjCRuntime.Selector("requestWhenInUseAuthorization"))) { locationManager.RequestWhenInUseAuthorization(); } locationManager.StartUpdatingLocation(); } } if (ViewModel.IsEditMode) { if (Mvx.Resolve <ICacheService>().NextStatus == AddSpotStatus.Activation) { return; } if (Mvx.Resolve <ICacheService>().NextStatus != AddSpotStatus.GotoSpot && Mvx.Resolve <ICacheService>().NextStatus != AddSpotStatus.Complete) { ViewModel.DoAddOrSaveParkingSpot(); } else if (Mvx.Resolve <ICacheService>().NextStatus == AddSpotStatus.Complete) { ViewModel.DoAddOrSaveParkingSpot(); } } else { if (Mvx.Resolve <ICacheService>().NextStatus == AddSpotStatus.SpotCalendar) { ViewModel.DoAddOrSaveParkingSpot(); } else if (Mvx.Resolve <ICacheService>().NextStatus == AddSpotStatus.Complete) { ViewModel.SaveParkingSpot(); } } }
void ShowActualLocationPermissionAlert() { _locationManager = new CLLocationManager(); _locationManager.Delegate = new LocationManagerDelegate(this); if (_locationAuthorizationType == ClusterLocationAuthorizationType.Always && _locationManager.RespondsToSelector(new Selector("requestAlwaysAuthorization"))) { _locationManager.RequestAlwaysAuthorization(); } else if (_locationAuthorizationType == ClusterLocationAuthorizationType.WhenInUse && _locationManager.RespondsToSelector(new Selector("requestWhenInUseAuthorization"))) { _locationManager.RequestWhenInUseAuthorization(); } _locationManager.StartUpdatingLocation(); }
static LocationHelper() { LocationManager = new CLLocationManager(); if (LocationManager.RespondsToSelector(new Selector("requestWhenInUseAuthorization"))) { LocationManager.RequestWhenInUseAuthorization(); } LocationManager.DistanceFilter = CLLocationDistance.FilterNone; LocationManager.LocationsUpdated += LocationManager_LocationsUpdated; LocationManager.StartUpdatingLocation(); _isTracking = true; }
public override void ViewWillAppear(bool animated) { base.ViewWillAppear(animated); if (locationManager == null) { locationManager = new CLLocationManager(); locationManager.DesiredAccuracy = CLLocation.AccurracyBestForNavigation; locationManager.Delegate = this; if (locationManager.RespondsToSelector(new ObjCRuntime.Selector("requestWhenInUseAuthorization"))) { locationManager.RequestWhenInUseAuthorization(); } } }
public void StartGetLocation() { if (locationManager == null) { locationManager = new CLLocationManager(); locationManager.DesiredAccuracy = CLLocation.AccuracyHundredMeters; locationManager.Delegate = this; if (locationManager.RespondsToSelector(new ObjCRuntime.Selector("requestWhenInUseAuthorization"))) { locationManager.RequestWhenInUseAuthorization(); } } locationManager.StartUpdatingLocation(); }
static LocationHelper() { LocationManager = new CLLocationManager(); if (LocationManager.RespondsToSelector(new Selector("requestWhenInUseAuthorization"))) { LocationManager.RequestWhenInUseAuthorization(); //LocationManager.RequestAlwaysAuthorization(); } LocationManager.DistanceFilter = CLLocationDistance.FilterNone; LocationManager.AllowsBackgroundLocationUpdates = true; LocationManager.PausesLocationUpdatesAutomatically = false; LocationManager.LocationsUpdated += LocationManager_FirstLocationsUpdated; LocationManager.StartUpdatingLocation(); _isTracking = true; }
public override void ViewDidAppear(bool animated) { base.ViewDidAppear(animated); if (locationManager == null) { locationManager = new CLLocationManager(); locationManager.DesiredAccuracy = CLLocation.AccuracyBest; locationManager.Delegate = this; // Check for iOS 8. Without this guard the code will crash with "unknown selector" on iOS 7. if (locationManager.RespondsToSelector(new ObjCRuntime.Selector("requestWhenInUseAuthorization"))) { locationManager.RequestWhenInUseAuthorization(); } locationManager.StartUpdatingLocation(); } }
/// <summary> /// Initializes a new instance of the <see cref="Geolocator"/> class. /// </summary> public Geolocator() { _manager = GetManager(); _manager.AuthorizationChanged += OnAuthorizationChanged; _manager.Failed += OnFailed; if (_manager.RespondsToSelector(new Selector("requestWhenInUseAuthorization"))) { _manager.RequestWhenInUseAuthorization(); } if (UIDevice.CurrentDevice.CheckSystemVersion(6, 0)) { _manager.LocationsUpdated += OnLocationsUpdated; } else { _manager.UpdatedLocation += OnUpdatedLocation; } _manager.UpdatedHeading += OnUpdatedHeading; }
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions) { MapServices.ProvideAPIKey ("AIzaSyA8WOvgGyHaw3rgkeYuUIqkIxhmW9Hrdjc"); locationManager = new CLLocationManager (); locationManager.Delegate = new locationManagerDelegate (); locationManager.DesiredAccuracy = CLLocation.AccuracyBest; locationManager.RequestAlwaysAuthorization (); if (locationManager.RespondsToSelector (new Selector ("requestWhenInUseAuthorization"))) { locationManager.RequestWhenInUseAuthorization (); } if (CLLocationManager.LocationServicesEnabled) { locationManager.StartUpdatingLocation (); } ProgressHUD.Shared.HudForegroundColor = UIColor.Gray; ProgressHUD.Shared.Ring.Color = UIColor.FromRGB(44/255f,146/255f,208/255f); ProgressHUD.Shared.HudForegroundColor = UIColor.FromRGB(44/255f,146/255f,208/255f); UIApplication.SharedApplication.SetStatusBarStyle (UIStatusBarStyle.LightContent, true); this.Window = new UIWindow (UIScreen.MainScreen.Bounds); UINavigationController navigation = new UINavigationController(new StartingScreen()); navigation.NavigationBar.TintColor = UIColor.White; navigation.NavigationBar.BarTintColor = UIColor.FromRGB(44/255f,146/255f,208/255f); navigation.NavigationBar.BarStyle = UIBarStyle.Black; navigation.SetNavigationBarHidden (true,true); this.Window.RootViewController = navigation; this.Window.MakeKeyAndVisible (); return true; }
public override void ViewWillAppear(bool animated) { base.ViewWillAppear(animated); Console.WriteLine("Map Appear"); if (locationManager == null) { locationManager = new CLLocationManager(); //locationManager.DesiredAccuracy = waiting for customer locationManager.Delegate = this; if (locationManager.RespondsToSelector(new ObjCRuntime.Selector("requestWhenInUseAuthorization"))) { locationManager.RequestWhenInUseAuthorization(); } } mTimeToken = Mvx.Resolve <IMvxMessenger>().Subscribe <TimeMessage>(message => { if (message.Sender.GetType() != typeof(ParkingReservedViewModel)) { return; } ViewModel.TotalParkingTime = message.TimeLeft; }); }
public async void NavigateUsingGoogleMaps(double destinationLat, double destinationLng, int zoomLevel = 1, DirectionsMode directionsMode = DirectionsMode.Driving) { if (CLLocationManager.Status == CLAuthorizationStatus.NotDetermined) { if (locationManager != null) { // Check for iOS 8. Without this guard the code will crash with "unknown selector" on iOS 7. if (locationManager.RespondsToSelector(new ObjCRuntime.Selector("requestWhenInUseAuthorization"))) { locationManager.RequestWhenInUseAuthorization(); } return; } } if (CLLocationManager.Status == CLAuthorizationStatus.Denied) { string title = (CLLocationManager.Status == CLAuthorizationStatus.Denied) ? "Location services are off" : "Location Service is not enabled"; string message = "To use Location Service you must turn on 'While using the app' in the Location Services Settings"; if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0)) { Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this.ViewModel, false)); UIAlertView alertView = new UIAlertView(title, message, null, "Cancel", "Settings"); alertView.Clicked += (object sender, UIButtonEventArgs e) => { if (e.ButtonIndex == alertView.CancelButtonIndex) //cancel { //ViewModel.CloseViewModel(); } else { //go to settings UIApplication.SharedApplication.OpenUrl(new NSUrl(UIApplication.OpenSettingsUrlString)); } }; alertView.Dismissed += (sender, e) => { alertView.Dispose(); alertView = null; }; alertView.Show(); } else { // ios 7 only has two CLAuthorizationStatus : Denied and AuthorizedAlways if (CLLocationManager.Status == CLAuthorizationStatus.AuthorizedAlways) { return; } Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this.ViewModel, false)); UIAlertView alertView = new UIAlertView(title, message, null, "OK"); alertView.Clicked += (sender, e) => { //if (e.ButtonIndex == alertView.CancelButtonIndex) //ViewModel.CloseViewModel(); }; alertView.Dismissed += (sender, e) => { alertView.Dispose(); alertView = null; }; alertView.Show(); } return; } //get current location Geolocator locator = new Geolocator() { DesiredAccuracy = 100 }; var location = await locator.GetPositionAsync(50000); Console.WriteLine("Position Status: {0}", location.Timestamp); Console.WriteLine("Position Latitude: {0}", location.Latitude); Console.WriteLine("Position Longitude: {0}", location.Longitude); var sourceLat = location.Latitude; var sourceLng = location.Longitude; var mode = directionsMode == DirectionsMode.Driving ? "driving" : "walking"; if (UIApplication.SharedApplication.CanOpenUrl(new NSUrl("comgooglemaps://"))) { // GoogleMaps is installed. Launch GoogleMaps and start navigation var urlString = string.Format("comgooglemaps://?saddr={0},{1}&daddr={2},{3}&zoom={4}&directionsmode={5}", sourceLat.ParseToCultureInfo(new CultureInfo("en-US")), sourceLng.ParseToCultureInfo(new CultureInfo("en-US")), destinationLat.ParseToCultureInfo(new CultureInfo("en-US")), destinationLng.ParseToCultureInfo(new CultureInfo("en-US")), zoomLevel, mode); UIApplication.SharedApplication.OpenUrl(new NSUrl(urlString)); } else { // GoogleMaps is not installed. Launch AppStore to install GoogleMaps app UIApplication.SharedApplication.OpenUrl(new NSUrl("http://itunes.apple.com/us/app/id585027354")); } }
public override void ViewDidLoad() { UserTrackingReporter.TrackUser(Constant.CATEGORY_LOGIN, "ViewDidLoad"); base.ViewDidLoad(); thisController = NavigationController; md5Hash = MD5.Create(); #if DEBUG usernameTextField.Text = "*****@*****.**"; passwordTextField.Text = "test1234"; #endif var tap = new UITapGestureRecognizer(() => { View.EndEditing(true); }); View.AddGestureRecognizer(tap); CLLocationManager locationManager; locationManager = new CLLocationManager(); if (locationManager.RespondsToSelector(new Selector("requestWhenInUseAuthorization"))) { locationManager.RequestWhenInUseAuthorization(); } locationManager.DistanceFilter = CLLocationDistance.FilterNone; locationManager.DesiredAccuracy = CLLocation.AccurracyBestForNavigation; locationManager.StartUpdatingLocation(); usernameTextField.ShouldReturn += TextFieldShouldReturn; passwordTextField.ShouldReturn += TextFieldShouldReturn; btnLogin.TouchUpInside += BtnLogin_TouchUpInside; btnCreateAccount.TouchUpInside += BtnCreateAccount_TouchUpInside; btnCallRoadrunner.TouchUpInside += BtnCallRoadrunner_TouchUpInside; #region Facebook _facebookLoginButton.TouchUpInside += BtnLogin_Facebook; #endregion #region Linkedin _linkedinLoginButton.TouchUpInside += BtnLogin_Linkedin; #endregion #region Google+ signIn = SignIn.SharedInstance; signIn.ClientId = RoadRunner.Shared.Constant.GOOGLECLIENTID; signIn.Scopes = new[] { PlusConstants.AuthScopePlusLogin, PlusConstants.AuthScopePlusMe }; signIn.ShouldFetchGoogleUserEmail = true; signIn.ShouldFetchGoogleUserId = true; signIn.Delegate = this; _googleLoginButton.TouchUpInside += BtnLogin_Google; #endregion #region AutoLogin // If the user is already logged in GooglePlus if (signIn.ClientId != null && signIn.TrySilentAuthentication) { } // If the user is already logged in Facebook if (Facebook.CoreKit.AccessToken.CurrentAccessToken != null) { FacebookLoggedIn(Facebook.CoreKit.AccessToken.CurrentAccessToken.UserID); } // If the user is already logged in Linkedin if (SessionManager.SharedInstance.Session.AccessToken != null) { LinkedInLoggedIn(); } if (!String.IsNullOrEmpty(AppSettings.UserLogin) && !String.IsNullOrEmpty(AppSettings.UserPassword)) { usernameTextField.Text = AppSettings.UserLogin; passwordTextField.Text = AppSettings.UserPassword; BtnLogin_TouchUpInside(new object(), new EventArgs()); } #endregion }
public override void ViewDidLoad() { base.ViewDidLoad(); this.NavigationController.NavigationBar.Translucent = true; //Estilos para la barra de navegacion this.NavigationController.NavigationBar.TintColor = UIColor.Gray; //this.NavigationController.NavigationBar.BarTintColor = UIColor.Blue; this.NavigationController.NavigationBar.Translucent = true; //Fin estilos barra navegacion GetData(); DataSource data = new DataSource(jsonObj, this); tvDatos.Source = data; tvDatos.ReloadData(); tvDatos.ReloadInputViews(); //Nuevos beacons var settings = UIUserNotificationSettings.GetSettingsForTypes( UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound, new NSSet()); UIApplication.SharedApplication.RegisterUserNotificationSettings(settings); locationMgr = new CLLocationManager(); if (locationMgr.RespondsToSelector(new Selector("requestWhenInUseAuthorization"))) { locationMgr.RequestAlwaysAuthorization(); } //primer beacon var shopUUID = new NSUuid(uuid); var beaconRegion = new CLBeaconRegion(shopUUID, firstShopId); beaconRegion.NotifyEntryStateOnDisplay = true; beaconRegion.NotifyOnEntry = true; beaconRegion.NotifyOnExit = true; locationMgr.StartMonitoring(beaconRegion); locationMgr.StartRangingBeacons(beaconRegion); //segundo beacon var shop2UUID = new NSUuid(uuid2); var beaconRegion2 = new CLBeaconRegion(shop2UUID, secondShopId); beaconRegion2.NotifyEntryStateOnDisplay = true; beaconRegion2.NotifyOnEntry = true; beaconRegion2.NotifyOnExit = true; locationMgr.StartMonitoring(beaconRegion2); locationMgr.StartRangingBeacons(beaconRegion2); locationMgr.RegionEntered += (object sender, CLRegionEventArgs e) => { Console.WriteLine("RegionEntered"); switch (e.Region.Identifier) { case "shop2": UILocalNotification notification = new UILocalNotification() { AlertBody = "Existe una promoción A!!!" }; UIApplication.SharedApplication.PresentLocationNotificationNow(notification); break; case "shop1": UILocalNotification notification2 = new UILocalNotification() { AlertBody = "Existe una promoción B!!!" }; UIApplication.SharedApplication.PresentLocationNotificationNow(notification2); break; } /* * if (e.Region.Identifier == secondShopId) { * UILocalNotification notification = new UILocalNotification () { AlertBody = "Existe una promoción A!!!" }; * UIApplication.SharedApplication.PresentLocationNotificationNow (notification); * } * if (e.Region.Identifier == firstShopId) { * UILocalNotification notification = new UILocalNotification () { AlertBody = "Existe una promoción B!!!" }; * UIApplication.SharedApplication.PresentLocationNotificationNow (notification); * } */ }; locationMgr.DidRangeBeacons += (object sender, CLRegionBeaconsRangedEventArgs e) => { System.Diagnostics.Debug.WriteLine("Entramos"); if (e.Beacons.Length > 0) { if (e.Region.Identifier == firstShopId) { CLBeacon beacon = e.Beacons [0]; switch (beacon.Proximity) { case CLProximity.Immediate: Console.WriteLine("Beacon 1"); var CategoryVC = new iBeaconVC(); this.NavigationController.PresentViewController(CategoryVC, true, null); break; } } if (e.Region.Identifier == secondShopId) { CLBeacon beacon = e.Beacons [0]; switch (beacon.Proximity) { case CLProximity.Immediate: Console.WriteLine("Beacon 2"); var Category2VC = new Catego2ViewController(); this.NavigationController.PresentViewController(Category2VC, true, null); break; } } } }; //locationMgr.StartMonitoring (beaconRegion2); //locationMgr.StartRangingBeacons (beaconRegion2); //this.NavigationController.PushViewController(CategoryVC, true); }
public virtual void AuthorizationChanged(CLLocationManager manager, CLAuthorizationStatus status) { Console.WriteLine(status.ToString()); if (status == CLAuthorizationStatus.NotDetermined) { if (locationManager != null) { // Check for iOS 8. Without this guard the code will crash with "unknown selector" on iOS 7. if (locationManager.RespondsToSelector(new ObjCRuntime.Selector("requestWhenInUseAuthorization"))) { locationManager.RequestWhenInUseAuthorization(); } return; } } if (status == CLAuthorizationStatus.AuthorizedAlways || status == CLAuthorizationStatus.Denied) { string title = (status == CLAuthorizationStatus.Denied) ? "Location services are off" : "Location Service is not enabled"; string message = "To use Location Service you must turn on 'While using the app' in the Location Services Settings"; if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0)) { Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this.ViewModel, false)); UIAlertView alertView = new UIAlertView(title, message, null, "Cancel", "Settings"); alertView.Clicked += (object sender, UIButtonEventArgs e) => { if (e.ButtonIndex == alertView.CancelButtonIndex) //cancel { ViewModel.CloseViewModel(); } else { //go to settings UIApplication.SharedApplication.OpenUrl(new NSUrl(UIApplication.OpenSettingsUrlString)); } }; alertView.Dismissed += (sender, e) => { alertView.Dispose(); alertView = null; }; alertView.Show(); } else { // ios 7 only has two CLAuthorizationStatus : Denied and AuthorizedAlways if (status == CLAuthorizationStatus.AuthorizedAlways) { return; } Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this.ViewModel, false)); UIAlertView alertView = new UIAlertView(title, message, null, "OK"); alertView.Clicked += (sender, e) => { if (e.ButtonIndex == alertView.CancelButtonIndex) { ViewModel.CloseViewModel(); } }; alertView.Dismissed += (sender, e) => { alertView.Dispose(); alertView = null; }; alertView.Show(); } } }
void ShowActualLocationPermissionAlert() { _locationManager = new CLLocationManager (); _locationManager.Delegate = new LocationManagerDelegate (this); if (_locationAuthorizationType == ClusterLocationAuthorizationType.Always && _locationManager.RespondsToSelector (new Selector ("requestAlwaysAuthorization"))) { _locationManager.RequestAlwaysAuthorization (); } else if (_locationAuthorizationType == ClusterLocationAuthorizationType.WhenInUse && _locationManager.RespondsToSelector (new Selector ("requestWhenInUseAuthorization"))) { _locationManager.RequestWhenInUseAuthorization (); } _locationManager.StartUpdatingLocation (); }