demetrio812 / nativescript-ibeacon

iBeacon library for Nativescript (supporting iOS and Android)
Other
13 stars 9 forks source link

Not working on iOS with angular #7

Closed circa94 closed 6 years ago

circa94 commented 7 years ago

Hey there!

I have some problems in getting the plugin to run on iOS. I am using NativeScript with Angular. On Android everything is working fine. Also the demo is running fine on iOS.

I setup my angular project like here: https://docs.nativescript.org/tutorial/ng-chapter-1

This is my code for a very simple test:

import { Component } from "@angular/core";
import {
  BeaconRegion, Beacon, BeaconCallback, BeaconLocationOptions, BeaconLocationOptionsIOSAuthType, BeaconLocationOptionsAndroidAuthType
} from "nativescript-ibeacon/nativescript-ibeacon.common";
import { NativescriptIbeacon } from "nativescript-ibeacon";

@Component({
  selector: "my-app",
  template: `
    <ActionBar title="My App" class="action-bar"></ActionBar>
    <Button text="START" (tap)="start()"></Button>
  `
})
export class AppComponent implements BeaconCallback {

  private nativescriptIbeacon: NativescriptIbeacon;

  constructor() {
    let options: BeaconLocationOptions = {
      iOSAuthorisationType: BeaconLocationOptionsIOSAuthType.Always,
      androidAuthorisationType: BeaconLocationOptionsAndroidAuthType.Coarse,
      androidAuthorisationDescription: "Location permission needed"
    };

    this.nativescriptIbeacon = new NativescriptIbeacon(this, options);
  }

  onBeaconManagerReady(): void {
    console.log("onBeaconManagerReady");
  }
  didRangeBeaconsInRegion(region: BeaconRegion, beacons: Beacon[]): void {
    console.log("didRangeBeaconsInRegion");
  }
  didFailRangingBeaconsInRegion(region: BeaconRegion, errorCode: number, errorDescription: string): void {
    console.log("didFailRangingBeaconsInRegion");
  }
  didEnterRegion?(region: BeaconRegion): void {
    console.log("didEnterRegion");
  }
  didExitRegion?(region: BeaconRegion): void {
    console.log("didExitRegion");
  }

  start() {
    if (!this.nativescriptIbeacon.isAuthorised()) {
      console.log("NOT Authorised");
      this.nativescriptIbeacon.requestAuthorization()
        .then(() => {
          console.log("Authorised by the user");
          this.nativescriptIbeacon.bind();

        }, (e) => {
          console.log("Authorisation denied by the user");
        })
    } else {
      console.log("Already authorised");
      this.nativescriptIbeacon.bind();
    }
  }
}

If I press the button, i am getting not asked for permissions. I also made sure, I entered the key in the .plist file

plist

The output of the console when I press the button is:

console

demetrio812 commented 7 years ago

Hello, it looks like you neve call startRanging(region) or startMonitoring(region)

You should start ranging or monitoring inside the onBeaconManagerReady() callback method, check the readme and let me know...

Cheers, Dem

demetrio812 commented 6 years ago

Closing this issue as no response and it works for me

Dem