private CBPeripheral RetrieveKnownPeripheral(NSUuid deviceUuid) { if (deviceUuid == null || !deviceUuid.AsString().Any()) return null; CBPeripheral[] peripheralList = _centralManager.RetrievePeripheralsWithIdentifiers(deviceUuid); return peripheralList[0]; }
public override void ViewWillAppear(bool animated) { base.ViewWillAppear(animated); CLBeaconRegion region = (CLBeaconRegion)locationManger.MonitoredRegions.AnyObject; enabled = (region != null); if (enabled) { uuid = region.ProximityUuid; major = region.Major; minor = region.Minor; notifyOnEntry = region.NotifyOnEntry; notifyOnExit = region.NotifyOnExit; notifyOnDisplay = region.NotifyEntryStateOnDisplay; } else { uuid = Defaults.DefaultProximityUuid; major = minor = null; notifyOnEntry = true; notifyOnExit = true; notifyOnDisplay = false; } majorTextField.Text = major == null ? String.Empty : major.Int32Value.ToString(); minorTextField.Text = minor == null ? String.Empty : minor.Int32Value.ToString(); uuidTextField.Text = uuid.AsString(); enabledSwitch.On = enabled; notifyOnEntrySwitch.On = notifyOnEntry; notifyOnExitSwitch.On = notifyOnExit; notifyOnDisplaySwitch.On = notifyOnDisplay; }
async partial void ToggleAppTileClick(UIButton sender) { if (client != null && client.IsConnected) { Output("Creating tile..."); // the number of tile spaces left var capacity = await client.TileManager.GetRemainingTileCapacityTaskAsync(); Output("Remaning tile space: " + capacity); // create the tile NSError operationError; var tileName = "iOS Sample"; var tileIcon = BandIcon.FromUIImage(UIImage.FromBundle("tile.png"), out operationError); var smallIcon = BandIcon.FromUIImage(UIImage.FromBundle("badge.png"), out operationError); var tile = BandTile.Create(tileId, tileName, tileIcon, smallIcon, out operationError); tile.BadgingEnabled = true; // get the tiles try { var tiles = await client.TileManager.GetTilesTaskAsync(); if (tiles.Any(x => x.TileId.AsString() == tileId.AsString())) { // a tile exists, so remove it await client.TileManager.RemoveTileTaskAsync(tileId); Output("Removed tile!"); } else { // the tile does not exist, so add it await client.TileManager.AddTileTaskAsync(tile); Output("Added tile!"); } } catch (BandException ex) { Output("Error: " + ex.Message); } } else { Output("Band is not connected. Please wait...."); } }
void ScheduleURLSession () { var uuuid = new NSUuid (); var backgroundConfigObject = NSUrlSessionConfiguration.CreateBackgroundSessionConfiguration (uuuid.AsString ()); backgroundConfigObject.SessionSendsLaunchEvents = true; var backgroundSession = NSUrlSession.FromConfiguration (backgroundConfigObject); var downloadTask = backgroundSession.CreateDownloadTask (sampleDownloadURL); downloadTask.Resume (); }
public String GetDeviceId() { if (UIDevice.CurrentDevice.CheckSystemVersion(7, 0)) { ASIdentifierManager idManager = ASIdentifierManager.SharedManager; NSUuid uuid = idManager.AdvertisingIdentifier; return(uuid.AsString()); } else { return(UniqueID()); } }
/// <summary> /// Starts the monitoring region. /// </summary> /// <param name="UUID">UUI.</param> public void StartMonitoringRegion(string UUID) { rangingBeacons.Clear(); if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0)) { #if DEBUG SystemLogger.Log(SystemLogger.Module.PLATFORM, "Using new iOS 8 Location Services Authorization"); #endif locationManager.RequestWhenInUseAuthorization(); //only requests for authorization in app running (foreground) } /*if (adapter != null) { * if (adapter.IsScanning) { * this.StopMonitoringBeacons (); * } * Guid region = new Guid (UUID); * adapter.StartScanningForDevices (region); * SystemLogger.Log("adapter.StartScanningForDevices(" + UUID +")"); * }*/ Unknowns = new List <CLBeacon> (); Immediates = new List <CLBeacon> (); Nears = new List <CLBeacon> (); Fars = new List <CLBeacon> (); beaconsLocation = new List <CLBeacon> [4] { Unknowns, Immediates, Nears, Fars }; NSUuid uuid; if (UUID != null && UUID.Any()) { uuid = new NSUuid(UUID); SystemLogger.Log(SystemLogger.Module.PLATFORM, "uuid: " + UUID); regionLocation = new CLBeaconRegion(uuid, uuid.AsString()); locationManager.StartRangingBeacons(regionLocation); } timeStop = new Timer(); timeStop.Interval = 5000; timeStop.Start(); timeStop.Elapsed += (x, y) => { SystemLogger.Log(SystemLogger.Module.PLATFORM, "STOPPED!"); if (timeStop != null) { timeStop.Stop(); } this.StopMonitoringBeacons(); }; //timeStop.Elapsed += this.StopMonitoringBeacons (); //NSTimer.CreateScheduledTimer(new TimeSpan(5000), new Action }
/// <summary> /// Handles the FinishedLaunching event of the application delegate. /// </summary> /// <param name="app">The current application.</param> /// <param name="options">The application options.</param> /// <returns><c>true</c> - if the application was launched; <c>false</c> otherwise.</returns> /// <remarks> /// <para> /// 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. /// </para> /// <para> /// You have 17 seconds to return from this method, or iOS will terminate your application. /// </para> /// </remarks> public override bool FinishedLaunching(UIApplication app, NSDictionary options) { // Initialize the platform dependent components Xamarin.Forms.Forms.Init(); Xamarin.FormsMaps.Init(); MediaPicker.Instance = new Media.MediaPickerIOS(); Settings.Instance = new SettingsIOS(); // Setup exception handler AppDomain.CurrentDomain.UnhandledException += AppDelegate.CurrentDomainOnUnhandledException; AppDelegate.DisplayCrashReport(); // Get the device identifier #if !TARGET_IPHONE_SIMULATOR var deviceUuid = UIDevice.CurrentDevice.IdentifierForVendor; #else var deviceUuid = new NSUuid("CA90424A-5E89-468E-BC7B-9DE7D82FC02D"); #endif // Initialize the application // ReSharper disable once UseObjectOrCollectionInitializer var application = new App(); application.CurrentCultureInfo = AppDelegate.GetCurrentCultureInfo(); application.DeviceId = $"{Xamarin.Forms.Device.OS}:{deviceUuid.AsString()}"; application.LaunchUriDelegate = AppDelegate.LaunchUri; // If launched with the URI if (options != null) { NSObject obj; options.TryGetValue(UIApplication.LaunchOptionsUrlKey, out obj); var uri = obj as NSUrl; if (uri != null) { // Save the URI this.launchedUri = new Uri(uri.ToString()); } } // Request notification permission var pushSettings = UIUserNotificationSettings.GetSettingsForTypes( UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound, new NSSet()); UIApplication.SharedApplication.RegisterUserNotificationSettings(pushSettings); // Load the current application this.LoadApplication(application); return(base.FinishedLaunching(app, options)); }
public void Ctor4() { TestRuntime.AssertSystemVersion(PlatformName.iOS, 7, 0, throwIfOtherPlatform: false); using (var uuid = new NSUuid("E2C56DB5-DFFB-48D2-B060-D0F5A71096E0")) using (var br = new CLBeaconRegion(uuid, 2, 3, "identifier")) { Assert.That(br.Major.Int32Value, Is.EqualTo(2), "Major"); Assert.That(br.Minor.Int32Value, Is.EqualTo(3), "Minor"); Assert.False(br.NotifyEntryStateOnDisplay, "NotifyEntryStateOnDisplay"); Assert.That(uuid.AsString(), Is.EqualTo(br.ProximityUuid.AsString()), "ProximityUuid"); // CLRegion Assert.That(br.Identifier, Is.EqualTo("identifier"), "identifier"); Assert.True(br.NotifyOnEntry, "NotifyOnEntry"); Assert.True(br.NotifyOnExit, "NotifyOnExit"); } }
async Task CreatePlaylistIfNeededAsync() { if (MediaPlaylist != null) { return; } // To create a new playlist or lookup a playlist there // are several steps you need to do. NSUuid playlistUuid; MPMediaPlaylistCreationMetadata playlistCreationMetadata = null; var userDefaults = NSUserDefaults.StandardUserDefaults; if (userDefaults.StringForKey(playlistUuidKey) is string playlistUuidString) { // In this case, the sample already created a playlist in // a previous run. In this case we lookup the UUID that // was used before. playlistUuid = new NSUuid(playlistUuidString); } else { // Create an instance of `UUID` to identify the new playlist. playlistUuid = new NSUuid(); // Create an instance of `MPMediaPlaylistCreationMetadata`, // this represents the metadata to associate with the new playlist. playlistCreationMetadata = new MPMediaPlaylistCreationMetadata("Test Playlist") { DescriptionText = $"This playlist was created using {NSBundle.MainBundle.InfoDictionary ["CFBundleName"]} to demonstrate how to use the Apple Music APIs" }; // Store the `UUID` that the sample will use for looking // up the playlist in the future. userDefaults.SetString(playlistUuid.AsString(), playlistUuidKey); userDefaults.Synchronize(); } // Request the new or existing playlist from the device. MediaPlaylist = await MPMediaLibrary.DefaultMediaLibrary.GetPlaylistAsync(playlistUuid, playlistCreationMetadata); InvokeOnMainThread(() => NSNotificationCenter.DefaultCenter.PostNotificationName(LibraryDidUpdate, null)); }
public void Ctor4() { if (!TestRuntime.CheckSystemAndSDKVersion(7, 0)) { Assert.Ignore("Requires iOS7"); } using (var uuid = new NSUuid("E2C56DB5-DFFB-48D2-B060-D0F5A71096E0")) using (var br = new CLBeaconRegion(uuid, 2, 3, "identifier")) { Assert.That(br.Major.Int32Value, Is.EqualTo(2), "Major"); Assert.That(br.Minor.Int32Value, Is.EqualTo(3), "Minor"); Assert.False(br.NotifyEntryStateOnDisplay, "NotifyEntryStateOnDisplay"); Assert.That(uuid.AsString(), Is.EqualTo(br.ProximityUuid.AsString()), "ProximityUuid"); // CLRegion Assert.That(br.Identifier, Is.EqualTo("identifier"), "identifier"); Assert.True(br.NotifyOnEntry, "NotifyOnEntry"); Assert.True(br.NotifyOnExit, "NotifyOnExit"); } }
public BeaconInfo updateBeacon(NSUuid uuid, NSNumber major, NSNumber minor, double distance) { System.Console.WriteLine(Tag + "add beacon"); String key = major + ":" + minor; BeaconInfo beaconInfo = null; // si existe, actualizo if (beacons.Contains(key)) { beaconInfo = (BeaconInfo)beacons[key]; // saco distancia vieja if (distances.ContainsValue(key)) { distances.Remove(beaconInfo.distance); } beaconInfo.addDistance(distance); } //sino, agrego else { beaconInfo = new BeaconInfo(); beaconInfo.uuid = uuid.AsString(); beaconInfo.major = major; beaconInfo.minor = minor; beaconInfo.addDistance(distance); beacons.Add(key, beaconInfo); } //actualizo distancias try { distances.Add(beaconInfo.distance, key); } catch (ArgumentException e) { //TODO que hacemos? le sumamos un cm y la dibujamos? System.Console.WriteLine(Tag + "add beacon -> clave duplicada en distancias"); System.Console.WriteLine(Tag + e.Message); } return(beaconInfo); }
public string GetIdentifier() { string serial = string.Empty; try { NSUuid tempImei = UIDevice.CurrentDevice.IdentifierForVendor; String str = tempImei.AsString().Replace("-", ""); if (str.Length > 50) { serial = str.Substring(0, 50); } else { serial = str; } } catch (Exception) { } return(serial); }
/// <summary> /// Starts the monitoring region. /// </summary> /// <param name="UUID">UUI.</param> public void StartMonitoringRegion(string UUID) { rangingBeacons.Clear (); if (UIDevice.CurrentDevice.CheckSystemVersion (8, 0)) { #if DEBUG SystemLogger.Log(SystemLogger.Module.PLATFORM, "Using new iOS 8 Location Services Authorization"); #endif locationManager.RequestWhenInUseAuthorization(); //only requests for authorization in app running (foreground) } /*if (adapter != null) { if (adapter.IsScanning) { this.StopMonitoringBeacons (); } Guid region = new Guid (UUID); adapter.StartScanningForDevices (region); SystemLogger.Log("adapter.StartScanningForDevices(" + UUID +")"); }*/ Unknowns = new List<CLBeacon> (); Immediates = new List<CLBeacon> (); Nears = new List<CLBeacon> (); Fars = new List<CLBeacon> (); beaconsLocation = new List<CLBeacon> [4] { Unknowns, Immediates, Nears, Fars }; NSUuid uuid; if (UUID != null && UUID.Any ()) { uuid = new NSUuid (UUID); SystemLogger.Log(SystemLogger.Module.PLATFORM, "uuid: " + UUID ); regionLocation = new CLBeaconRegion (uuid, uuid.AsString ()); locationManager.StartRangingBeacons (regionLocation); } timeStop = new Timer (); timeStop.Interval = 5000; timeStop.Start (); timeStop.Elapsed += (x, y) => { SystemLogger.Log(SystemLogger.Module.PLATFORM, "STOPPED!" ); if (timeStop != null) timeStop.Stop(); this.StopMonitoringBeacons(); }; //timeStop.Elapsed += this.StopMonitoringBeacons (); //NSTimer.CreateScheduledTimer(new TimeSpan(5000), new Action }
/// <summary> /// Gets the device identifier. /// </summary> /// <returns>The device identifier as a Guid.</returns> /// <param name="id">The device identifier as a NSUuid.</param> public static Guid DeviceIdentifierToGuid(NSUuid id) { return Guid.ParseExact(id.AsString(), "d"); }
/// <summary> /// Gets the device identifier. /// </summary> /// <returns>The device identifier as a Guid.</returns> /// <param name="id">The device identifier as a NSUuid.</param> public static Guid DeviceIdentifierToGuid(NSUuid id) { return(Guid.ParseExact(id.AsString(), "d")); }
public static Guid ToGuid(this NSUuid uuid) { return(Guid.ParseExact(uuid.AsString(), "d")); }
public static Guid ToGuid(this NSUuid uuid) => Guid.ParseExact(uuid.AsString(), "d");
public override void ViewDidLoad() { base.ViewDidLoad(); this.Title = "Configure"; enabledSwitch.ValueChanged += (sender, e) => { enabled = enabledSwitch.On; }; uuidTextField.AutoresizingMask = UIViewAutoresizing.FlexibleWidth; uuidTextField.InputView = new UuidPickerView(uuidTextField); uuidTextField.EditingDidBegin += HandleEditingDidBegin; uuidTextField.EditingDidEnd += (sender, e) => { uuid = new NSUuid(uuidTextField.Text); NavigationItem.RightBarButtonItem = saveButton; }; uuidTextField.Text = uuid.AsString(); majorTextField.KeyboardType = UIKeyboardType.NumberPad; majorTextField.ReturnKeyType = UIReturnKeyType.Done; majorTextField.AutoresizingMask = UIViewAutoresizing.FlexibleWidth; majorTextField.EditingDidBegin += HandleEditingDidBegin; majorTextField.EditingDidEnd += (sender, e) => { major = numberFormatter.NumberFromString(majorTextField.Text); NavigationItem.RightBarButtonItem = saveButton; }; minorTextField.KeyboardType = UIKeyboardType.NumberPad; minorTextField.ReturnKeyType = UIReturnKeyType.Done; minorTextField.AutoresizingMask = UIViewAutoresizing.FlexibleWidth; minorTextField.EditingDidBegin += HandleEditingDidBegin; minorTextField.EditingDidEnd += (sender, e) => { minor = numberFormatter.NumberFromString(minorTextField.Text); NavigationItem.RightBarButtonItem = saveButton; }; measuredPowerTextField.KeyboardType = UIKeyboardType.NumberPad; measuredPowerTextField.ReturnKeyType = UIReturnKeyType.Done; measuredPowerTextField.AutoresizingMask = UIViewAutoresizing.FlexibleWidth; measuredPowerTextField.EditingDidBegin += HandleEditingDidBegin; measuredPowerTextField.EditingDidEnd += (sender, e) => { power = numberFormatter.NumberFromString(measuredPowerTextField.Text); NavigationItem.RightBarButtonItem = saveButton; }; doneButton = new UIBarButtonItem(UIBarButtonSystemItem.Done, (sender, e) => { uuidTextField.ResignFirstResponder(); majorTextField.ResignFirstResponder(); minorTextField.ResignFirstResponder(); measuredPowerTextField.ResignFirstResponder(); TableView.ReloadData(); }); saveButton = new UIBarButtonItem(UIBarButtonSystemItem.Save, (sender, e) => { if (peripheralManager.State < CBPeripheralManagerState.PoweredOn) { new UIAlertView("Bluetooth must be enabled", "To configure your device as a beacon", null, "OK", null).Show(); return; } if (enabled) { CLBeaconRegion region = Helpers.CreateRegion(uuid, major, minor); if (region != null) { peripheralManager.StartAdvertising(region.GetPeripheralData(power)); } } else { peripheralManager.StopAdvertising(); } NavigationController.PopViewControllerAnimated(true); }); NavigationItem.RightBarButtonItem = saveButton; }
public static Guid FromNative(this NSUuid uuid) { return(new Guid(uuid.AsString())); }
void ScheduleURLSession() { var uuuid = new NSUuid(); var backgroundConfigObject = NSUrlSessionConfiguration.CreateBackgroundSessionConfiguration(uuuid.AsString()); backgroundConfigObject.SessionSendsLaunchEvents = true; var backgroundSession = NSUrlSession.FromConfiguration(backgroundConfigObject); var downloadTask = backgroundSession.CreateDownloadTask(sampleDownloadURL); downloadTask.Resume(); }
public static bool IsUuidEqual(this NSUuid firstUuid, NSUuid secondUuid) { return firstUuid.AsString().Equals(secondUuid.AsString(), StringComparison.OrdinalIgnoreCase); }
public static bool IsUuidEqual(this CBPeripheral peripheral, NSUuid uuid) { return peripheral.Identifier.AsString().Equals(uuid.AsString(), StringComparison.OrdinalIgnoreCase); }
public static Guid FromNative(this NSUuid uuid) => new Guid(uuid.AsString());