void ConfigureView()
        {
            // Update the user interface for the detail item
            if (IsViewLoaded && detailItem != null)
            {
                detailDescriptionLabel.Text = detailItem.ToString();
            }

            this.Title = detailItem.Code;

            if (peripheralMgr != null)
            {
                peripheralMgr.StopAdvertising();
            }
            else
            {
                peripheralDelegate = new BTPeripheralDelegate();
                peripheralMgr      = new CBPeripheralManager(peripheralDelegate, DispatchQueue.DefaultGlobalQueue);
            }

            beaconUUID   = new NSUuid(detailItem.UUID);
            beaconRegion = new CLBeaconRegion(beaconUUID, (ushort)detailItem.Major, (ushort)detailItem.Minor, beaconId);



            //power - the received signal strength indicator (RSSI) value (measured in decibels) of the beacon from one meter away
            var power = new NSNumber(-59);

            peripheralData = beaconRegion.GetPeripheralData(power);
            peripheralMgr.StartAdvertising(peripheralData);

            QRCode.LoadUrl(GenerateQRCodeUrl(detailItem.ToString(), QRCodeSize.Medium, QRErrorCorrection.H));
        }
    void ConfigureView()
    {
      // Update the user interface for the detail item
      if (IsViewLoaded && detailItem != null)
      {
        detailDescriptionLabel.Text = detailItem.ToString();
      }

      this.Title = detailItem.Code;

      if(peripheralMgr != null)
      {
        peripheralMgr.StopAdvertising();
      }
      else
      {
        peripheralDelegate = new BTPeripheralDelegate();
        peripheralMgr = new CBPeripheralManager(peripheralDelegate, DispatchQueue.DefaultGlobalQueue);
      }

      beaconUUID = new NSUuid(detailItem.UUID);
      beaconRegion = new CLBeaconRegion(beaconUUID, (ushort)detailItem.Major, (ushort)detailItem.Minor, beaconId);



      //power - the received signal strength indicator (RSSI) value (measured in decibels) of the beacon from one meter away
      var power = new NSNumber(-59);
      peripheralData = beaconRegion.GetPeripheralData(power);
      peripheralMgr.StartAdvertising(peripheralData);

      QRCode.LoadUrl(GenerateQRCodeUrl(detailItem.ToString(), QRCodeSize.Medium, QRErrorCorrection.H));
    }
Esempio n. 3
0
        public void StartBroadcasting()
        {
            CLBeaconRegion region = Helpers.CreateRegion(new NSUuid("8E6DBFBB-489D-418A-9560-1BA1CE6301AA"), new NSNumber(5050), new NSNumber(1234));

            if (region != null)
            {
                peripheralManager.StartAdvertising(region.GetPeripheralData(new NSNumber(50)));
            }
        }
Esempio n. 4
0
        /// <summary>
        /// iBeacon発信開始処理(UUID、Major、Minorを直指定して発信)
        /// </summary>
        /// <param name="uuid">UUID</param>
        /// <param name="major">Major</param>
        /// <param name="minor">Minor</param>
        public void StartTransmission(Guid uuid, ushort major, ushort minor, sbyte txPower)
        {
            // BLE発信制御クラスに渡すためのiBeacon定義を作成する。
            NSUuid         nsUuid         = new NSUuid(uuid.ToString());
            CLBeaconRegion region         = new CLBeaconRegion(nsUuid, major, minor, uuid.ToString());
            NSNumber       nsnumTxPower   = new NSNumber(txPower);
            NSDictionary   peripheralData = region.GetPeripheralData(nsnumTxPower);

            // iBeaconの発信を開始する。
            _peripheralManager.StartAdvertising(peripheralData);
        }
        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear (animated);

            beaconUUID = new NSUuid (uuid);
            beaconRegion = new CLBeaconRegion (beaconUUID, beaconMajor, beaconMinor, beaconId);

            //power - the received signal strength indicator (RSSI) value (measured in decibels) of the beacon from one meter away
            var power = new NSNumber (-59);

            var peripheralData = beaconRegion.GetPeripheralData (power);
            peripheralDelegate = new BTPeripheralDelegate ();
            peripheralManager.StartAdvertising (peripheralData);
        }
Esempio n. 6
0
        public void speak()
        {
            var monkeyUUID    = new NSUuid(uuid_person);
            var beaconRegion2 = new CLBeaconRegion(monkeyUUID, "Person");

            //power - the received signal strength indicator (RSSI) value (measured in decibels) of the beacon from one meter away
            var power = new NSNumber(-59);
            NSMutableDictionary peripheralData = beaconRegion2.GetPeripheralData(power);

            peripheralDelegate = new BTPeripheralDelegate();
            peripheralMgr      = new CBPeripheralManager(peripheralDelegate, DispatchQueue.DefaultGlobalQueue);

            peripheralMgr.StartAdvertising(peripheralData);
        }
Esempio n. 7
0
        private void Initialize()
        {
            var beaconId     = BeaconInfo.BeaconUuid;// + _phoneNumber;
            var beaconUUID   = new NSUuid(beaconId);
            var beaconRegion = new CLBeaconRegion(beaconUUID, _phoneNumber);

            //power - the received signal strength indicator (RSSI) value (measured in decibels) of the beacon from one meter away
            var power = new NSNumber(-59);

            _peripheralData     = beaconRegion.GetPeripheralData(power);
            _peripheralDelegate = new BTPeripheralDelegate();
            _peripheralMgr      = new CBPeripheralManager(_peripheralDelegate, DispatchQueue.DefaultGlobalQueue);
            //_peripheralMgr.StartAdvertising(_peripheralData);
        }
Esempio n. 8
0
        public void StartAdvertisingBeacons(UserDataModel userData)
        {
            _userData = userData;

            if (_beaconTransmitter.State < CBPeripheralManagerState.PoweredOn)
            {
                System.Diagnostics.Debug.WriteLine("Bluetooth must be enabled");
                // new UIAlertView("Bluetooth must be enabled", "To configure your device as a beacon", null, "OK", null).Show();
                return;
            }

            CLBeaconRegion region  = new CLBeaconRegion(new NSUuid(AppConstants.iBeaconAppUuid), ushort.Parse(_userData.Major), ushort.Parse(_userData.Minor), _userData.UserUuid);
            NSNumber       txPower = new NSNumber(-59);

            _beaconTransmitter.StartAdvertising(region.GetPeripheralData(txPower));
        }
Esempio n. 9
0
        public void Start(string UUID)
        {
            var proximityUUID = new NSUuid("12345678-1234-1234-1234-123456780001");
            var beaconRegion  = new CLBeaconRegion(proximityUUID, 100, 1, "Whatever");

            //power - the received signal strength indicator (RSSI) value (measured in decibels) of the beacon from one meter away
            var power = new NSNumber(-59);
            NSMutableDictionary peripheralData = beaconRegion.GetPeripheralData(power);

            peripheralDelegate = new BTPeripheralDelegate(peripheralData);
            peripheralMgr      = new CBPeripheralManager(peripheralDelegate, DispatchQueue.DefaultGlobalQueue);


            Console.WriteLine("Beacon Debug: " + "Started Advertising:" + UUID);
            ShowAlert("Started Advertising:" + UUID, 5);
        }
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			beaconUUID = new NSUuid (uuid);
			beaconRegion = new CLBeaconRegion (beaconUUID, beaconMajor, beaconMinor, beaconId);



			//power - the received signal strength indicator (RSSI) value (measured in decibels) of the beacon from one meter away
			var power = new NSNumber (-59);

			NSMutableDictionary peripheralData = beaconRegion.GetPeripheralData (power);
			peripheralDelegate = new BTPeripheralDelegate ();
			peripheralMgr = new CBPeripheralManager (peripheralDelegate, DispatchQueue.DefaultGlobalQueue);

			peripheralMgr.StartAdvertising (peripheralData);
		}
Esempio n. 11
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            beaconUUID   = new NSUuid(uuid);
            beaconRegion = new CLBeaconRegion(beaconUUID, beaconMajor, beaconMinor, beaconId);



            //power - the received signal strength indicator (RSSI) value (measured in decibels) of the beacon from one meter away
            var power = new NSNumber(-59);

            NSMutableDictionary peripheralData = beaconRegion.GetPeripheralData(power);

            peripheralDelegate = new BTPeripheralDelegate();
            peripheralMgr      = new CBPeripheralManager(peripheralDelegate, DispatchQueue.DefaultGlobalQueue);

            peripheralMgr.StartAdvertising(peripheralData);
        }
Esempio n. 12
0
        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);


            beaconUUID   = new NSUuid(uuid);
            beaconRegion = new CLBeaconRegion(beaconUUID, beaconMajor, beaconMinor, beaconId);



            //power - the received signal strength indicator (RSSI) value (measured in decibels) of the beacon from one meter away
            var power = new NSNumber(-59);

            var peripheralData = beaconRegion.GetPeripheralData(power);

            peripheralDelegate = new BTPeripheralDelegate();
            peripheralManager.StartAdvertising(peripheralData);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            var uuid = new NSUuid ("A1F30FF0-0A9F-4DE0-90DA-95F88164942E");
            var beaconId = "iOSBeacon";
            var beaconRegion = new CLBeaconRegion (uuid, beaconId) {
                NotifyEntryStateOnDisplay = true,
                NotifyOnEntry = true,
                NotifyOnExit = true
            };

            var peripheralData = beaconRegion.GetPeripheralData (new NSNumber (-59));

            peripheralDelegate = new BTPeripheralDelegate ();
            peripheralMgr = new CBPeripheralManager (peripheralDelegate, DispatchQueue.DefaultGlobalQueue);
            peripheralMgr.StartAdvertising (peripheralData);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var uuid         = new NSUuid("A1F30FF0-0A9F-4DE0-90DA-95F88164942E");
            var beaconId     = "iOSBeacon";
            var beaconRegion = new CLBeaconRegion(uuid, beaconId)
            {
                NotifyEntryStateOnDisplay = true,
                NotifyOnEntry             = true,
                NotifyOnExit = true
            };

            var peripheralData = beaconRegion.GetPeripheralData(new NSNumber(-59));

            peripheralDelegate = new BTPeripheralDelegate();
            peripheralMgr      = new CBPeripheralManager(peripheralDelegate, DispatchQueue.DefaultGlobalQueue);
            peripheralMgr.StartAdvertising(peripheralData);
        }
Esempio n. 15
0
        private void DidStateUpdated(object sender, EventArgs e)
        {
            System.Diagnostics.Debug.WriteLine("DidStateUpdated");
            CBPeripheralManager trasmitter = sender as CBPeripheralManager;

            if (trasmitter.State < CBPeripheralManagerState.PoweredOn)
            {
                System.Diagnostics.Debug.WriteLine("Bluetooth must be enabled");
                // new UIAlertView("Bluetooth must be enabled", "To configure your device as a beacon", null, "OK", null).Show();
                return;
            }

            if (_transmitterFlg)
            {
                CLBeaconRegion region  = new CLBeaconRegion(new NSUuid(AppConstants.iBeaconAppUuid), ushort.Parse(_userData.Major), ushort.Parse(_userData.Minor), _userData.UserUuid);
                NSNumber       txPower = new NSNumber(-59);
                trasmitter.StartAdvertising(region.GetPeripheralData(txPower));
            }
            else
            {
                trasmitter.StopAdvertising();
            }
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Perform any additional setup after loading the view, typically from a nib.
            var beaconRegion = new CLBeaconRegion(beaconId, beaconRegionName)
            {
                NotifyOnEntry             = true,
                NotifyEntryStateOnDisplay = true,
                NotifyOnExit = true
            };

            if (!UserInterfaceIdiomIsPhone)
            {
                //power - the received signal strength indicator (RSSI) value (measured in decibels) of the beacon from one meter away
                var power = new NSNumber(-59);
                NSMutableDictionary peripheralData = beaconRegion.GetPeripheralData(power);
                peripheralDelegate = new BTPeripheralDelegate(peripheralData);
                peripheralMgr      = new CBPeripheralManager(peripheralDelegate, DispatchQueue.DefaultGlobalQueue);
            }
            else
            {
                locationMgr = new CLLocationManager();

                locationMgr.RegionEntered += (object sender, CLRegionEventArgs e) => {
                    if (e.Region.Identifier == beaconRegionName)
                    {
                        UILocalNotification notification = new UILocalNotification()
                        {
                            AlertBody = "Shark Warning! No Swimming!"
                        };
                        UIApplication.SharedApplication.PresentLocationNotificationNow(notification);
                    }
                };
                locationMgr.RegionLeft += (object sender, CLRegionEventArgs e) => {
                    if (e.Region.Identifier == beaconRegionName)
                    {
                        UILocalNotification notification = new UILocalNotification()
                        {
                            AlertBody = "Looks like it's safe to swim."
                        };
                        UIApplication.SharedApplication.PresentLocationNotificationNow(notification);
                    }
                };

                CLProximity previousProximity = CLProximity.Unknown;
                locationMgr.DidRangeBeacons += (object sender, CLRegionBeaconsRangedEventArgs e) => {
                    if (e.Beacons.Length > 0)
                    {
                        var beacon = e.Beacons[0];
                        if (beacon.Proximity == previousProximity)
                        {
                            return;
                        }
                        PlaySound(beacon.Proximity);
                        beacon.
                        switch (beacon.Proximity)
                        {
                        case CLProximity.Unknown:
                        case CLProximity.Far:
                            this.statusMessage.Text   = "Is it true that most people get attacked by sharks in three feet of water about ten feet from the beach?";
                            this.View.BackgroundColor = UIColor.FromRGB(238, 214, 175);
                            break;

                        case CLProximity.Near:
                            this.statusMessage.Text   = "You're gonna need a bigger boat.";
                            this.View.BackgroundColor = UIColor.FromRGB(206, 223, 239);
                            break;

                        case CLProximity.Immediate:
                            this.statusMessage.Text   = "It was nice to know ya.";
                            this.View.BackgroundColor = UIColor.FromRGB(138, 7, 7);
                            break;
                        }
                        previousProximity = beacon.Proximity;
                    }
                };

                locationMgr.StartMonitoring(beaconRegion);
                locationMgr.StartRangingBeacons(beaconRegion);
            }
        }
Esempio n. 17
0
        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 override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            var monkeyUUID = new NSUuid (uuid);
            var beaconRegion = new CLBeaconRegion (monkeyUUID, monkeyId);

            beaconRegion.NotifyEntryStateOnDisplay = true;
            beaconRegion.NotifyOnEntry = true;
            beaconRegion.NotifyOnExit = true;

            if (!UserInterfaceIdiomIsPhone) {

                //power - the received signal strength indicator (RSSI) value (measured in decibels) of the beacon from one meter away
                var power = new NSNumber (-59);
                NSMutableDictionary peripheralData = beaconRegion.GetPeripheralData (power);
                peripheralDelegate = new BTPeripheralDelegate ();
                peripheralMgr = new CBPeripheralManager (peripheralDelegate, DispatchQueue.DefaultGlobalQueue);

                peripheralMgr.StartAdvertising (peripheralData);

            } else {

                InitPitchAndVolume ();

                locationMgr = new CLLocationManager ();

                locationMgr.RegionEntered += (object sender, CLRegionEventArgs e) => {
                    if (e.Region.Identifier == monkeyId) {
                        UILocalNotification notification = new UILocalNotification () { AlertBody = "There's a monkey hiding nearby!" };
                        UIApplication.SharedApplication.PresentLocationNotificationNow (notification);
                    }
                };

                locationMgr.DidRangeBeacons += (object sender, CLRegionBeaconsRangedEventArgs e) => {
                    if (e.Beacons.Length > 0) {

                        CLBeacon beacon = e.Beacons [0];
                        string message = "";

                        switch (beacon.Proximity) {
                        case CLProximity.Immediate:
                            message = "You found the monkey!";
                            monkeyStatusLabel.Text = message;
                            View.BackgroundColor = UIColor.Green;
                            break;
                        case CLProximity.Near:
                            message = "You're getting warmer";
                            monkeyStatusLabel.Text = message;
                            View.BackgroundColor = UIColor.Yellow;
                            break;
                        case CLProximity.Far:
                            message = "You're freezing cold";
                            monkeyStatusLabel.Text = message;
                            View.BackgroundColor = UIColor.Blue;
                            break;
                        case CLProximity.Unknown:
                            message = "I'm not sure how close you are to the monkey";;
                            monkeyStatusLabel.Text = message;
                            View.BackgroundColor = UIColor.Gray;
                            break;
                        }

                        if(previousProximity != beacon.Proximity){
                            Speak (message);
                        }
                        previousProximity = beacon.Proximity;
                    }
                };

                locationMgr.StartMonitoring (beaconRegion);
                locationMgr.StartRangingBeacons (beaconRegion);
            }
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            if (!UserInterfaceIdiomIsPhone)
            {
                openMultipeerBrowser.TouchUpInside += (sender, e) => {
                    StartMultipeerBrowser();
                };
            }
            else
            {
                StartMultipeerAdvertiser();
            }

            var monkeyUUID   = new NSUuid(uuid);
            var beaconRegion = new CLBeaconRegion(monkeyUUID, monkeyId);

            beaconRegion.NotifyEntryStateOnDisplay = true;
            beaconRegion.NotifyOnEntry             = true;
            beaconRegion.NotifyOnExit = true;

            if (!UserInterfaceIdiomIsPhone)
            {
                //power - the received signal strength indicator (RSSI) value (measured in decibels) of the beacon from one meter away
                var power = new NSNumber(-59);
                NSMutableDictionary peripheralData = beaconRegion.GetPeripheralData(power);
                peripheralDelegate = new BTPeripheralDelegate();
                peripheralMgr      = new CBPeripheralManager(peripheralDelegate, DispatchQueue.DefaultGlobalQueue);

                peripheralMgr.StartAdvertising(peripheralData);
            }
            else
            {
                InitPitchAndVolume();

                locationMgr = new CLLocationManager();

                locationMgr.RegionEntered += (object sender, CLRegionEventArgs e) => {
                    if (e.Region.Identifier == monkeyId)
                    {
                        UILocalNotification notification = new UILocalNotification()
                        {
                            AlertBody = "There's a monkey hiding nearby!"
                        };
                        UIApplication.SharedApplication.PresentLocationNotificationNow(notification);
                    }
                };

                locationMgr.DidRangeBeacons += (object sender, CLRegionBeaconsRangedEventArgs e) => {
                    if (e.Beacons.Length > 0)
                    {
                        CLBeacon beacon  = e.Beacons [0];
                        string   message = "";

                        switch (beacon.Proximity)
                        {
                        case CLProximity.Immediate:
                            message = "You found the monkey!";
                            monkeyStatusLabel.Text = message;
                            View.BackgroundColor   = UIColor.Green;
                            break;

                        case CLProximity.Near:
                            message = "You're getting warmer";
                            monkeyStatusLabel.Text = message;
                            View.BackgroundColor   = UIColor.Yellow;
                            break;

                        case CLProximity.Far:
                            message = "You're freezing cold";
                            monkeyStatusLabel.Text = message;
                            View.BackgroundColor   = UIColor.Blue;
                            break;

                        case CLProximity.Unknown:
                            message = "I'm not sure how close you are to the monkey";
                            monkeyStatusLabel.Text = message;
                            View.BackgroundColor   = UIColor.Gray;
                            break;
                        }

                        if (previousProximity != beacon.Proximity)
                        {
                            Speak(message);

                            // demo send message using multipeer connectivity
                            if (beacon.Proximity == CLProximity.Immediate)
                            {
                                SendMessage();
                            }
                        }
                        previousProximity = beacon.Proximity;
                    }
                };

                locationMgr.StartMonitoring(beaconRegion);
                locationMgr.StartRangingBeacons(beaconRegion);
            }
        }