1

As mentioned in git of BLE for IONIC 2 we can register for BLE enable or disable state : https://github.com/don/cordova-plugin-ble-central#startstatenotifications . But It gives me error Property startStateNotification does not exist on type of BLE. My code is :

ble.startStateNotifications(
function(state) {
    console.log("Bluetooth is " + state);
});

What I am missing here.I want success and failer both callbacks as well. Please provide solution..

Pooja Shah
  • 977
  • 16
  • 45
  • I would suggest to also post your issue directly at the github page. (At the top, there is an `Issues` tab) The author will be able to help you directly. Or you can search for similar issues there also – Huiting Feb 20 '17 at 03:07

1 Answers1

1

You are calling the plugin through

import {ble} from ionic-native is it?

If you take a look at the files in ionic-native>dist>plugins>ble.js, there are a list of commands provided. Check if there is a command called startStateNotifications.

Property startStateNotification does not exist on type of BLE

This would most likely mean ble does not have this function.

You have to check if ionic-native is using the latest version of cordova-plugin-ble-central.


UPDATE

Instead of importing through ionic-native, you can import the plugin by running this command in command prompt:

cordova plugin add cordova-plugin-ble-central

Afterwards, you will use this as a plugin. So just call ble.startStateNotification() You will not need to include import {ble} from ionic-native already.

I prefer directly importing cordova-plugin-ble-central from the main author instead of going through ionic-native to call cordova-plugin-ble-central. In the event of any updates from the plugin, you can update immediately. Else, you will have to wait on ionic-native

Huiting
  • 1,368
  • 7
  • 24
  • Yes I am importing from ionic-native.So how to check that ionic-native is using the latest version of cordova-lugin? – Pooja Shah Feb 21 '17 at 05:38
  • I have checked version and its showing 1.1.4. Is it ok? or need to update? If need to update then do u know how to update only ble plugin? – Pooja Shah Feb 21 '17 at 06:30
  • Also I have checked ble.js there is no command called startStateNotifications. – Pooja Shah Feb 21 '17 at 06:45
  • I have updated my answer after you confirm there is no startStateNotifications command – Huiting Feb 21 '17 at 07:42
  • Its saying : Plugin "cordova-plugin-ble-central" already installed on android. Plugin "cordova-plugin-ble-central" already installed on ios. So now how to import and use directly from that? If I remove that native import statement it gives me error and also writing this: ble.startStateNotification() is giving me error. – Pooja Shah Feb 21 '17 at 11:02
  • You can try removing the plugin first: `cordova plugin rm cordova-plugin-ble-central` then add it again. What version of ionic 2 are you using? – Huiting Feb 22 '17 at 08:12
  • I did all you have suggested but no luck – Pooja Shah Mar 05 '17 at 07:13
  • Check version: Cordova CLI: 6.5.0 , Ionic Framework Version: 2.0.0-rc.5, Ionic CLI Version: 2.2.1, Ionic App Lib Version: 2.2.0, Ionic App Scripts Version: 1.0.0 , ios-deploy version: 1.9.0 , ios-sim version: 5.0.13 , OS: OS X El Capitan , Node Version: v7.3.0. – Pooja Shah Mar 05 '17 at 07:15