private async void StartBeaconing() { if (this.BeaconManager == null) { Estimote.Config.Setup(LHPEEstimoteId, LHPEEstimoteKey); // TODO: Remove from source before distributing this.BeaconManager = new Estimote.SecureBeaconManager(); this.BeaconManager.Delegate = new BeaconManagerDelegate(); } this.StopBeaconing(); // fetch beacon regions var BeaconRegions = await Lighthouse.GetBeaconRegions(); if (FirstBeaconing) { this.GetBeaconRegionsState(); } else { // start monitoring on each region foreach (Lighthouse.LHPEBeaconRegion region in BeaconRegions) { CLBeaconRegion BeaconRegion = null; if (region.Minor != null) { BeaconRegion = new CLBeaconRegion(new NSUuid(region.UUID), (ushort)region.Major, (ushort)region.Minor, region.Id); } else if (region.Major != null) { BeaconRegion = new CLBeaconRegion(new NSUuid(region.UUID), (ushort)region.Major, region.Id); } else { BeaconRegion = new CLBeaconRegion(new NSUuid(region.UUID), region.Id); } this.BeaconManager.StartMonitoring(BeaconRegion); } } }
// // 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) { AppCenter.Start("app-center-secret", typeof(Analytics), typeof(Crashes)); _settings = FreshIOC.Container.Resolve <ISettings>(); _deviceTwin = FreshIOC.Container.Resolve <IDeviceTwin>(); _azureIoTHub = FreshIOC.Container.Resolve <IAzureIoTHub>(); global::Xamarin.Forms.Forms.Init(); InitializeCachedImageService(); Estimote.Config.SetupAppId("estimote-app-id", "estimote-app-token"); _secureBeaconManager = new SecureBeaconManager(); _monitoringV2ManagerImmediate = new MonitoringV2Manager(ImmediateMeanTriggerDistance, this); LoadApplication(new App(_azureIoTHub)); _settings.PropertyChanged += async(sender, args) => { await OccupantStateUpdated(); }; _secureBeaconManager.RequestAlwaysAuthorization(); _monitoringV2ManagerImmediate.RequestAlwaysAuthorization(); UNUserNotificationCenter.Current.RequestAuthorization( UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound, (approved, err) => { // Handle approval }); UIApplication.SharedApplication.RegisterForRemoteNotifications(); UNUserNotificationCenter.Current.Delegate = new UserNotificationCenterDelegate(_azureIoTHub); MonitorHomeGeolocation(); MonitorSecureBeacons(); MonitorProximityBeacons(); return(base.FinishedLaunching(app, options)); }