2017-11-13 9 views
-1

私はビーコンインテグレーションを初めて利用しています。コードを使ってiPhoneビーコン(トランスミッタ)のUUIDを取得します。検出されたビーコンを取得するために、デリゲートメソッドを使用してF2830580-4E97-4098-B01A-99D49BB69EF1iOSでiBeaconとしてiOSデバイスを使用するにはどうすればよいですか?

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() 

} 

: は当初、私はiPhoneのUUIDがビーコン

let uuidString = UIDevice.current.identifierForVendor?.uuidString 
print("UUID == \(uuidString)") 

UUIDとして動作するように取得するためのコードの下に書きました

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 

} 

CLBeacon iPhoneデバイスが検出されません。

でも試してみましたが、 https://developer.apple.com/documentation/corelocation/turning_an_ios_device_into_an_ibeaconとしましたが、結果はありません。 uは送信機としてお使いのデバイスを作るために任意のiOSデバイスで推定ビーコンを作成することができます

+0

最後に私はビーコンとしてコードを1行書く必要はありません。アプリケーション(Gemtot Sdk)ituneリンクがあります。 https://itunes.apple.com/in/app/gemtot-sdk/id967907684?mt=8このアプリケーションを1台のiPhoneデバイスにインストールすると、今インストールされているアプリがトランスミッタとして動作し、実際のコードが別のiPhoneで実行されます。ちょうど今魔法をチェックしてください。 –

+0

iPhoneデバイスは、インストールされているアプリケーションが開いた状態で、ビーコンタブで選択されている必要がある場合にのみ、信号を送信します。私はこれが役に立つと思っています。 –

答えて

0

任意の助けが理解されるであろう

.. ..ビーコンシミュレータアプリの

メイク使用して、手動でビーコンを作成します。 今あなたのアプリケーションを実行し、ビーコンの範囲を監視します。私はテスト用のコードで同じビーコンを持っています。

+0

ありがとうございます。あなたのデバイスを送信機にするためにどのiOSデバイスでも推定ビーコンを作成する方法のサンプルコードを提供してください。私はこのリンクをたどってhttps://www.brightec.co.uk/ideas/turning-iphone-ibeaconを送信し、トランスミッタ用のiphoneデバイスとレシーバ用の別のiphoneデバイスを作成しましたが、検出されませんでした。 –

関連する問題