When I open my app and brings the phone near to any iBeacon, it crashes. This is the error log -
java.lang.RuntimeException: java.lang.IllegalArgumentException: app.example.com: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
Plugin used-
npm install @ionic-native/ibeacon@5.36.0
Here is the code:
import { IBeacon, Beacon } from '@ionic-native/ibeacon/ngx';
constructor(public ibeacon:IBeacon) {
startscanning() {
// Request permission to use location on iOS
this.ibeacon.requestAlwaysAuthorization();
// create a new delegate and register it with the native layer
let delegate = this.ibeacon.Delegate();
// Subscribe to some of the delegate's event handlers
delegate.didRangeBeaconsInRegion()
.subscribe(
data => {
// Check beacon in range
},
error => console.log("error: " + error)
);
delegate.didStartMonitoringForRegion()
.subscribe(
data => {console.log('didStartMonitoringForRegion: ' + JSON.stringify(data));
console.log("didStartMonitoringForRegion");
},
error => {console.log(error)}
);
delegate.didEnterRegion()
.subscribe(
data => {
// this.testscanstatus += ' didenetregion ';
console.log("Did Enter region");
console.log('didEnterRegion: ' + JSON.stringify(data));
}
);
delegate.didDetermineStateForRegion()
.subscribe(
data => {
console.log('dididDetermineStateForRegion: '+ JSON.stringify(data.state));
if (data.state == "CLRegionStateInside") {
this.searching = true;
console.log(this.searching, "SEARCH NOW");
this.popData();
this.ibeacon.startRangingBeaconsInRegion(beaconRegion)
.then(
() => {
console.log("Start ranging - CLRegionStateInside");
},
error => console.log('ranging start error: ' + error)
);
} else if (data.state == "CLRegionStateOutside") {
this.ibeacon.stopRangingBeaconsInRegion(beaconRegion)
.then(
() => {
this.searching = false;
//this.beacons = this.GlobalServ.validBeacons;
this.beacons = [];
console.log("Stop ranging - CLRegionStateOutside");
},
error => console.log('ranging stop error: ' + error)
);
}
}
);
console.log(this.filtermajor, "FILTERMAJOR");
let beaconRegion = this.ibeacon.BeaconRegion('Beacon_nomachine', '********-****-****-****-************');
this.ibeacon.startMonitoringForRegion(beaconRegion)
.then(
() => {
//alert("monitoring started");
//this.popData();
console.log("startMonitoringForRegion");
},
error => console.log('Native layer failed to begin monitoring: ' + error)
);
this.ibeacon.isBluetoothEnabled().then((isEnabled) => {
if (isEnabled) {
return true;
} else {
this.ibeacon.enableBluetooth();
return false;
}
}
);
}
}