I’m new in Ionic so I’m just testing what’s possible. I’m trying just to check if bluetooth is enabled/disabled in iphone 8. I did everything by documentation Ionic Bluetooth-Serial but I can’t get it work. It always says bluetooth is disabled.
I put module & register provider in app.modules.ts Then in my home.ts I have following:
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { BluetoothSerial } from '@ionic-native/bluetooth-serial';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(public navCtrl: NavController, private bluetoothSerial: BluetoothSerial) {
let TIME_IN_MS = 2000;
let hideFooterTimeout = setTimeout( () => {
this.bluetoothSerial.isEnabled().then(function () {
alert('Bluetooth enabled');
}, function () {
alert('Bluetooth disabled');
});
}, TIME_IN_MS);
}
}
I tried to put there timeout but it didn’t help. I’m running it on iPhone by xCode… Any advice what’s wrong?
@svkmedia isEnabled() in bluetooth serial only reports you if your device bluetooth is enabled or not. If you want to check and if it’s disabled and you want to enable it, then you should try first isEnabled() then you should check device settings to enable it using enable(). This will enable Bluetooth on the device.
As in your question you’ve mentioned that it always says bluetooth is disabled. have you tried turning on your device bluetooth manually and then check if it’s enabled or not?
@Heenavora thank you for your answer. Yes I just want to know if bluetooth is enabled. But even when it’s enabled in iPhone settings my app says it’s disabled… So really don’t know what’s wrong.
can you check what error it throws?
let hideFooterTimeout = setTimeout( () => {
this.bluetoothSerial.isEnabled().then(success => {
alert('Bluetooth enabled');
}, error => {
alert(error);// or alert(JSON.stringify(error));
});
}, TIME_IN_MS);
I think this will help you know the root for error.
@Heenavora I did and I’m getting alert with number 4. Nothing else. I don’t know what this mean.
Hi, @svkmedia
This code put in your app.component file when platform is ready.
this.bluetoothSerial.isEnabled().subscribe(() => {
alert('Bluetooth enabled');
});
Thank you.