2016-09-16 8 views
1

私のプロジェクトでIonic2とAngular2を使っています。私がcordova-plugin-geofence(https://github.com/cowbell/cordova-plugin-geofence)をインストールすると次のようにジオフェンスが設定されています。Cordova-plugin-geofence onTransitionReceived()メソッドが動作しません。

App.ts

platform.ready().then(() => { 

    if (window.geofence === undefined) { 
    console.log('Geofence Plugin not found'); 
    }else{ 
    console.log('Geofence plugin found'); 
    window.geofence.initialize(); 
    const geofence = this.geofenceService.create({ 
     longitude: -8.404015, 
     latitude: 43.339147, 
    }); 

    this.geofenceService.addOrUpdate(geofence).then(function() { 
     console.log('Geofence successfully added'); 
    }, function (reason) { 
     console.log('Adding geofence failed', reason); 
     }); 
    } 
    }); 

HomePage.ts

window.geofence.onTransitionReceived = function (geofences) { 
    geofences.forEach(function (geo) { 
    console.log('Geofence transition detected', geo); 
    }); 
} 

それはtsubikのように構成されたサービスgeofence.service.tsイオン2ジオフェンスの例:https://github.com/tsubik/ionic2-geofence/blob/master/app/services/geofence-service.ts

すべてのジオフェンス設定プロセスでコンソールにエラーは表示されませんが、window.geofence.onTransitionReceived()メソッドはジオフェンストランジションが発生したときに何も記録しません。

どういうところが間違っていますか?ありがとう!

+0

半径とトランジションタイプを定義する必要があります。半径を閉じるのではなく、1000または3000mのようなものを取ってください。 – Joerg

+0

@Samuel Fraga Mateos、あなたは通知を受けていますか?私はこのプラグインで問題に直面しています。 – AishApp

+0

@Joergデフォルトのジオフェンスで半径とトランジションタイプを定義しました。新しいジオフェンスを作成するときは、緯度と経度のパラメータだけをオーバーライドします。 –

答えて

1

ドキュメントが間違っている、あなたが購読する必要があります。

Geofence.onTransitionReceived().subscribe(res =>{ 

      res.forEach(function(geo) { 
      console.log(geo); 
      }); 

     }, 
     (err) => console.log(err), 
     () => console.log("done !") 
    ); 

をそして、あなたは目的球「getWatched」を使用したい場合は、あなたが迅速なサポートを持っている必要があります。..ちょうど追加:

コルドバのプラグインを追加コルドバ - プラグインの追加-SWIFT-サポート--save

のConfig.xml

<preference name="UseLegacySwiftLanguageVersion" value="true"/> 
    <plugin name="cordova-plugin-add-swift-support" spec="~1.6.2"/> 

現在監視中のジオフェンスの配列が必要な場合:

Geofence.getWatched().then((geofencesJson) => { 

      const geofences = JSON.parse(geofencesJson); 

     this.sendLog("wathced "); 
     this.sendLog(geofencesJson); 

      return geofences; 
    }); 

これらの設定は私のために機能します。

関連する問題