Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在iOS中将iOS设备用作iBeacon?_Ios_Iphone_Swift_Ibeacon - Fatal编程技术网

如何在iOS中将iOS设备用作iBeacon?

如何在iOS中将iOS设备用作iBeacon?,ios,iphone,swift,ibeacon,Ios,Iphone,Swift,Ibeacon,我是新来的灯塔集成。使用代码获取iPhone信标(发射机)的UUID。 最初,我编写了下面的代码,让iPhone的UUID充当一个灯塔 let uuidString = UIDevice.current.identifierForVendor?.uuidString print("UUID == \(uuidString)") UUID:F2830580-4E97-4098-B01A-99D49BB69EF1 var locationManager: CLLocationManager?

我是新来的灯塔集成。使用代码获取iPhone信标(发射机)的UUID。 最初,我编写了下面的代码,让iPhone的UUID充当一个灯塔

let uuidString = UIDevice.current.identifierForVendor?.uuidString  
print("UUID == \(uuidString)")
UUID:F2830580-4E97-4098-B01A-99D49BB69EF1

var locationManager: CLLocationManager?
var myBeaconRegion: CLBeaconRegion?
var peripheral: CBPeripheral?
var manager: CBCentralManager?
var peripheralManager: CBPeripheralManager?

override func viewDidLoad(){

    super.viewDidLoad()
    locationManager = CLLocationManager()
    locationManager?.delegate = self
    locationManager?.distanceFilter = kCLDistanceFilterNone
    locationManager?.desiredAccuracy = kCLLocationAccuracyBest
    locationManager?.requestAlwaysAuthorization()
    locationManager?.requestWhenInUseAuthorization()
    peripheralManager = CBPeripheralManager(delegate: self as 
    CBPeripheralManagerDelegate, queue: nil, options: nil)

    let uuid = UUID(uuidString: "F2830580-4E97-4098-B01A-99D49BB69EF1")

    myBeaconRegion = CLBeaconRegion(proximityUUID: uuid!,identifier: "iBeacon")

    myBeaconRegion?.notifyOnEntry = true
    myBeaconRegion?.notifyOnExit = true
    myBeaconRegion?.notifyEntryStateOnDisplay = true
    manager = CBCentralManager(delegate: self as? CBCentralManagerDelegate, queue: nil)
    locationManager?.startMonitoring(for: myBeaconRegion!)
    locationManager?.startRangingBeacons(in: myBeaconRegion!)
    locationManager?.pausesLocationUpdatesAutomatically = false
    locationManager?.startUpdatingLocation()

}
使用委托方法获取检测到的信标

func locationManager(_ manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], in region: CLBeaconRegion)
{

  //  let value = region.major  as? NSNumber
   beaconLabel.text = "Beacon not found!"
    let foundBeacon = beacons.first as? CLBeacon
    print("foundBeacon == \(foundBeacon)")
 guard let  discoveredBeacon = beacons.first?.proximity else {
 print("beacon not found")
 return
 }


    let proxyValue = foundBeacon?.accuracy
    beaconDistanceLabel.text = String(describing: proxyValue!)
 let background:UIColor = {

 switch discoveredBeacon {
 case .immediate:
    beaconLabel.text = "Immediate!"
    return  UIColor.green
 case .near:
    beaconLabel.text = "Near!"
    return  UIColor.orange
 case .far:
    beaconLabel.text = "Far!"
    return  UIColor.red
 case .unknown:
    beaconLabel.text = "Unknown!"
    return  UIColor.magenta
 }
 }()
 view.backgroundColor = background

}
委托方法正在调用,但未检测到iPhone设备

连我都试过了 但没有结果


感谢您的帮助。

您可以在任何iOS设备中创建估算信标,使您的设备成为发射机

使用信标模拟器应用程序并手动创建信标。
现在运行应用程序并监控信标范围..硬编码与我在测试代码中使用的信标相同..

谢谢,您能否提供示例代码,说明如何在任何iOS设备中创建估算信标,使您的设备成为发射机。我按照这个链接创建了一个用于发射机的iphone设备和另一个用于接收机但未被检测到的iphone设备。最后我得到了如何将iphone设备作为信标的解决方案,无需编写一行代码。有一个应用程序(Gemtot Sdk)iTunes链接。在一台iPhone设备中安装该应用程序,现在安装的应用程序充当发送器,现在在另一台iPhone中运行实际代码。只需检查magic now.iPhone设备就可以仅在安装的应用程序处于打开状态且必须处于选中的Beacon选项卡时发送信号。我希望这可能是有用的,这些都是搜索这个。