2016-05-18 10 views
2

cordova/phonegapを使用してiOSデバイスをiBeaconとして宣伝するのに成功した人はいますか?私はネイティブのアプリケーションでそれをやった(airLocateはちょうどそれをする素晴らしいデモアプリケーションです)。私が探しているのは、phonegap/cordovaプラグインを使って宣伝することです。iOS - Phonegapを使用してiBeaconとして広告する

私は次のプラグインを持っています:https://github.com/petermetz/cordova-plugin-ibeacon このプラグインを使用して、ビーコンを正常に監視し、正常にビーコンを送信しましたが、広告できません。私はそのサイトから次のコードを使用しました:

var uuid = '00000000-0000-0000-0000-000000000000'; 
var identifier = 'advertisedBeacon'; 
var minor = 2000; 
var major = 5; 
var beaconRegion = new cordova.plugins.locationManager.BeaconRegion(identifier, uuid, major, minor); 

// The Delegate is optional 
var delegate = new cordova.plugins.locationManager.Delegate(); 

// Event when advertising starts (there may be a short delay after the request) 
// The property 'region' provides details of the broadcasting Beacon 
delegate.peripheralManagerDidStartAdvertising = function(pluginResult) { 
    console.log('peripheralManagerDidStartAdvertising: '+ JSON.stringify(pluginResult.region)); 
}; 
// Event when bluetooth transmission state changes 
// If 'state' is not set to BluetoothManagerStatePoweredOn when advertising cannot start 
delegate.peripheralManagerDidUpdateState = function(pluginResult) { 
    console.log('peripheralManagerDidUpdateState: '+ pluginResult.state); 
}; 

cordova.plugins.locationManager.setDelegate(delegate); 

// Verify the platform supports transmitting as a beacon 
cordova.plugins.locationManager.isAdvertisingAvailable() 
    .then(function(isSupported){ 

     if (isSupported) { 
      cordova.plugins.locationManager.startAdvertising(beaconRegion) 
       .fail(console.error) 
       .done(); 
     } else { 
      console.log("Advertising not supported"); 
     } 
    }) 
    .fail(function(e) { console.error(e); }) 
    .done(); 

このコードは正常に実行されますが、アドバタイズされません。私はビーコンスキャナを使用しましたが、それはそれを拾いません。私はそれが広告だかどうかを確認するためのコードを実行されますが、それは常にfalse戻ってくる:

cordova.plugins.locationManager.isAdvertising() 
.then(function(isAdvertising){ 
    console.log("isAdvertising: " + isAdvertising); 
}) 
.fail(function(e) { console.error(e); }) 
.done(); 

私はまた、次のような方法を介してユーザからの許可を求めています、

cordova.plugins.locationManager.requestWhenInUseAuthorization(); 

だから、誰が行っていますこれは正常にですか?私はアイデアがなく、そこにいる誰かがそれをして、それが可能であることを(少なくとも比較的簡単に)知らせることを望んでいます。 :)

ありがとう!

答えて

2

私は最終的にibeaconプラグインの問題のセクションの誰かから答えを得ました。

https://github.com/petermetz/cordova-plugin-ibeacon/issues/231

をしかし、基本的に、あなたは(あなたはコルドバでそれを構築した後で)Xcodeで「場所の更新」を有効にする必要があります。名声は答えをcgeweckeする - あなたはここで答えを見ることができます。プロジェクトに行き(一般的な設定は)、Capabilities-> Background Modes->「Location updates」をクリックしてください。

関連する問題