Nativescript + Bluetooth

ios

#1

Hello ,
I was thinking to develop an utility with bluetooth, where I have a use-case to
subscribe or wait till new Bluetooth connection is made and start from there … I explored
’nativescript-bluetooth’ library , but they dont have API to subscribe for notification until new bluetooth connection happens ( as far as I understood ). With ‘nativescript-bluetooth’ , we can scan and connect to a device but not wait in the background till phone connects to a device.

I feel only way is to call the native API ? Am I correct ?


#2

Hey @sasi,

Off the top of my head I think that this is something you’re going to have to write using native code as it’s a pretty custom use case. We have some samples out there for how to write NativeScript apps that run in the background — see https://github.com/NativeScript/sample-ios-background-execution and https://github.com/NativeScript/sample-android-background-services — that you can probably use to help get you started.

One problem you might run into: by default iOS doesn’t allow general purpose applications to run in the background for more than about 3 minutes. You can set a flag in your Info.plist to override this though, and there are even certain modes intended for bluetooth interaction https://developer.apple.com/library/content/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html#//apple_ref/doc/uid/TP40007072-CH4-SW23.

One thing you might want to try is finding a native plugin that does what you’re looking for, and to wrap that library in a NativeScript plugin of your own: https://docs.nativescript.org/plugins/building-plugins.

Best of luck, and if anyone else on this forum with a bit of bluetooth experience sees this feel free to chime in :smile:

TJ


#3

Thank you TJ :slight_smile: