Bluetooth LE app, how to build it cross-plaftorm (iOS-Android)? - android

I am working on an app that talks to a Bluetooth LE device. I would like some way to avoid developing it twice, for iOS and for Android. Is there a cross-platform app framework that has good support for Bluetooth LE?
I have had a quick look at frameworks like Cordova (PhoneGap), Appcelerator, Xamarin etc (the usual suspects: for example this list) but I can't figure out if they (a) support Bluetooth LE on each platform at all, and (b) if they do, whether it is via native calls (accessed how?) or some kind of wrapper to the native API (what does the wrapper look like?), and (c) if it is a wrapper, how complete it is, and how stable it is.
If you have experience with these, could you summarize the status of Bluetooth LE support in different frameworks?
EDIT A bit of info from digging into various options and from the answers below:
Cordova: several open-source plugins, for example https://github.com/evothings/cordova-ble https://github.com/don/cordova-plugin-ble-central https://github.com/randdusing/BluetoothLE (not a complete list). Evothings is a nice Cordova + bluetooth setup. Do these work in other Cordova-based app frameworks like Appery.io, Telerik AppBuilder, Ionic Creator?
Xamarin: this just uses the native APIs via MonoTouch.CoreBluetooth and Android.Bluetooth. This means the code using them is not actually cross-platform, but they are likely to work the same as the native API (because they essentially are the native API).
Appcelerator has third-party commercial plugins for Bluetooth (https://marketplace.appcelerator.com/apps/3834 and
https://marketplace.appcelerator.com/apps/6611), no built-in support. Do these work?
P.S. Besides Bluetooth my needs are pretty minimal: this app will have a lot of UI elements but not of a complicated kind, just a bunch of buttons/checkboxes/sliders on a bunch of different screens (which would be very tedious to maintain on two platforms). I'd also need to make a few calls to a REST API. Speed is not super important, there isn't that much app logic (it is mostly written in C now), and native UI look is not that important. However working on older versions of the platforms is important, ideally back to Android 4.3 and iOS 7.0.

I have been using Randdusing's Cordova plugin for BluetoothLE and it works well for Android and iOS (Windows phone still under development). Being Cordova it's designed to work with an HTML5/JavaScript app, but the plugins themselves (as all Cordova plugins?) are written in native code .
Earlier in my project I tried Evothings which also has BLE plugin but I found some problems, and I don't know if these have been resolved yet.
My app sounds pretty similar to yours in terms of the UI requirements, and I can possibly help with integrating the BLE code if you like - but you'll need to rewrite your 'c' into javascript first.
BTW you ask for using with older Android but AFAIK BLE is only supported in Android 4.3 or higher.

I am using Qt framework developing cross-platform apps with BLE support:
http://doc.qt.io/qt-5/qtbluetooth-lowenergyscanner-example.html
Currently the supported platforms are Andriod, iOS, OSX, Linux. Windows platform is said to support BLE in the forthcoming version Qt 5.6 (really looking forward to it). The BLE related classes are easy to use and Qt provided two sample projects in examples/documentation. The thing I am not sure about is getting Manufacturer Specific Data during a scan. Right now I am making a connection to the devices to get certain information which wouldn't be needed if I can read the Manufacturer Specific Data. Qt's BLE currently only support central role.
Qt is based on C++, if that matters to you.

Related

Porting a Cordova plugin from Android to iOS

I am in the process of creating the iOS version of a hybrid Cordova app which uses one single in-house plugin. The plugin provides the app with a range of services.
an encrypted SQLite database via SQLCipher
geolocation tracking
watching for Wifi networks (not actually using them, I only care about their MAC ids)
asynchronous https POST to periodically transfer app status data to my servers. I originally used OKHTTP for this purpose but now rely solely on the native APIs provided by Android.
Websockets (I am using this implementation in Android largely because it is very well documented)
Android's CountDownTimer to reguarly update the app screen when it is in the foreground
The accelerometer sensor to keep track of linear acceleration changes and the number of steps since last reboot.
Storing some information in files
Mostly using Android SharedPreferences to keep track of the app state
I would rate myself as a fairly decent programmer and have coded in C/C#/Delphi/C++ at various times in the past though most of my current experience has been with Java/ES6 and PHP. I have taken a look at Cordova's instructions for creating iOS plugins. What surprises me slightly is that a good 3+ years after Swift was introduced the Cordova folk still say
An iOS plugin is implemented as an Objective-C class that extends the CDVPlugin class. For JavaScript's exec method's service parameter to map to an Objective-C class, each plugin class must be registered as a tag in the named application directory's config.xml file.
I have used Evothing's excellent guide to install the entire Cordova ecosystem on my Mac Mini and have tested out the "Echo" sample app in the Cordova documentation. Much to my surprise I was able to test the app on my local iOS device at just my second attempt. However, this is purely the result of copying and pasting the sample Cordova Echo app code. Much of the Objective C syntax makes little sense to me and I note that it appears to use pointers (lots of *s) from which I am inferring that there is no automated garbage collection.
My questions
Are there well documented iOS APIs for handling geolocation, wifi scanning, file i/o etc as I have listed above?
Am I obliged to do all of this in Objective C or is it now possible to create Cordova iOS plugins in Swift (which appears to have a flatter learning curve)
Is it possible to use Websockets in this environment? If so, is there a comprehensive native iOS implementation?
Are there any shortcut ways to convert my Android/Java plugin code for use on iOS?
Finally, in view of the capabilities that I need to port, are there any glaringly obvious gotchas that I need to be aware of before I start
I am assuming that the iOS webview is based on Safari and accepts most CSS3/HTML5/ES6 constructs so the process of porting the UI - which works without a hitch in the Android Webview which shares it codebase with Chrome.
I'd be much obliged to anyone who might be able to give me some pointers here.

Using JNI FOR IOS and Android

Is it Reccommended to use JNI and C++ Code to make a shared library code between IOS and Android ?
I'am asking this because i think it not just saves us plenty of wasted time for implementing same logic in both platforms but also we will have the speed of a C++ core Backing the logic-process of our modules.
Update :
I ask my question in another way :
is it recommended to share a C++ Library for core functions of Android And IOS versions of a similar app ? or it would be better to completely migrate the codes to a multiplatform language ?
Since I remember my needs back then, I know that hybrid apps were not an option, Also JNI is not used for making cross-platform apps but the best use is to drive hardware peripherals via native UNIX scripts for Android or run c++ code on Android. So if we omit PhoneGap, Appcelerator, Ionic etc we will be facing several cross-platform technologies that have attracted many developer attentions so far.
Xamarin:
The framework was founded by the same people who have created Mono, an Ecma standard-compliant, .NET Framework-compatible set of tools. Xamarin offers developers a single C# codebase that can be used to produce native apps for all major mobile operating systems.
Unlike many other frameworks, Xamarin has already been used by over 1.4 million developers from around the world. Thanks to Xamarin for Visual Studio, developers can take advantage of the power of Microsoft Visual Studio and all its advanced features, including code completion, IntelliSense, and debugging of apps on a simulator or a device. Xamarin Test Cloud makes it possible to instantly test apps on 2,000 real devices in the cloud. This is by far the best way how to deal with the heavy fragmentation of the Android ecosystem and released bug-free apps that work without any major issues.
But being honest I didn't enjoy my first time face-to-face meeting with Xamarin. There were so many bugs and also speed and performance problems were bothering.
React Native
React Native is developed by Facebook and used by Instagram, Airbnb, Walmart, Tesla, Baidu, and many other Fortune 500 companies. It is an open-source version of Facebook’s React JavaScript framework. Because React Native uses the same UI building blocks as regular iOS and Android apps, it’s impossible to distinguish a React Native app from an app built using Objective-C or Java. As soon as you update the source code, you can see the changes instantly manifest in an app preview window. Should you ever feel the urge to manually optimize certain parts of your application, React Native lets you combine native code with components written in Objective-C, Java, or Swift.
The ones I mentioned above are not the only options, but since now they are the most used frameworks between programmers. But beware that Flutter is being publicly announced by Google in Google IO and maybe it may be going to create a hit soon.

Native iOS/android application to Windows Phone

I have an iPhone application (with an android counterpart), developed in Xcode and written in Objective-C. It is a classical native iOS app, already working and uploaded in the App Store. Similarly, the android version is built with Java and linked with the android SDKs. It's uploaded to the market place.
I was asked to port the app to Windows Phone. Is this possible without modifying the code?
I am not familiar with Windows Phone dev, however it looks like that is a completely
separate ecosystem for developing apps (different programming language, different IDE, different app store etc).
Can I go from Android to Windows Phone or from iOS to Windows Phone?
PhoneGap - or similar platforms - are not options since the code is already written in Objective-C and Java.
Like iOS and Android, Windows Phone is a completely different operating system and currently requires a completely different development platform.
It is not possible to take the existing code and make it function on a Windows Phone.
iOS commonly uses Objective-C for application development . Even if there was a way to compile Objective-C onto a Windows Phone, it would be inherently tied to platform features, and UI controls. While you could write some code in C++ and share it, with an iOS application, you'll still need some in Objective-C.
Android applications use Java normally. Java is not available for the Windows Phone platform. So, the language is out. Further, like iOS, the platform features are not necessarily shared and the UI control and behaviors are different. Android applications can use C++ (if you happened to code using it), but it has limitations, and by using it, again, you'd be tying the code to the Android platform potentially. Some code may be portable.
Windows Phone applications are usually written in C#/C++ and XAML or DirectX. While there is some similarity in languages (Java and C#), you'll encounter far more platform differences that could need significant effort to convert. From the way network requests are made to handling threads will be different (and many many more). Objective-C is also very different from C++.
Unless you had used something like Xamarin and written the underlying business logic using a common platform (C#/.NET), you'll need to consider a port to Windows Phone a fresh start.
It's not possible to just reuse all of the code that's been written. With a careful effort, you could share some common code (if it were written in C++), but as the shared code will not directly work with UI (and other platform features), you'd still need to do the UI on each platform, work around limitations, and potentially customize the user experience for each platform.
Microsoft has provided some guidance on porting, and provided some links with an API equivalency table here.
Yes, you can use Microsoft's Windows bridge for iOS to convert your iOS application code to Windows mobile platform code.
You need to use WinObjC SDK provided by Microsoft for this purpose.
Follow this link for more details.
No, you can't, WP apps are build with c# or .net and in visual studio IDE. There is no automated way to port a previously coded ios or android native app built with objetive-c or java to WP.
In my opinion there is no way to directly port a iphone app to windows phone app. You need to develop windows phone app with its needed environment like Visual Studio , windows phone sdk and with windows os.
You can also use cross platform like phonegap if it may fit to your requirement.
It looks like you have an existing Obj-C codebase for iOS, and a Java codebase for Android. No matter how you cut it, you're looking at [re]writing code to get something on WP8.
I don't know how "UI heavy" your app is; in general the UI code is the most platform specific (unless you're willing to put up with "cross platform" stuff that might not have good UX).
You might consider keeping the non-UI code mostly plain C++ and using Obj-C, etc. only for the parts where you have to talk to the framework. It will be easier to support multiple platforms with C++.
I took this approach with an app I'm working on; it's targeted for iOS but it's about 80% C++ (including Open GL). If I decide to port to Android I just need to deal with the 20%, mostly UI-ish code.

What's the best way to develop a cross-mobile app with bluetooth support?

I've read about the native feature-support of Phonegap here. Clearly, it makes no mention of Bluetooth support. I've failed in finding or locating any other platform with cross-mobile platform development support. As a result, I'm currently faced with two choices.
Build independently for all the platforms (very painful option)
Find a suitable cross-platform development solution (which I've not found yet).
My question is; for mobile developers out there, which option would you suggest I take, one not listed here? If possible also help with details of pros and cons.
Thank you very much.
Build independently for all the platforms (very painful option)
In my experience, this is by far the least painful option, and not just for Bluetooth. The overhead of dealing with leaky cross-platform abstractions tends to outweigh the benefits by the time you get to a real, production product. Build an excellent iPhone app. Build an excellent Android app. You can share a lot of the UI design (though not all of it). You can share much of the data structure design. You can share some of the internal architecture. You can share any network protocols (particularly if you design them in JSON). But avoid code sharing and avoid shooting for the least-common-denominator. It's pretty far down....
For some kinds of projects it makes sense to share some C++ code between platforms. Trying to develop this stuff in JavaScript is a recipe for frustration the moment you go beyond the most basic of applications. It's easy to hack up something in mobile JavaScript that kind of works. It's very hard to get it to look and work great on all platforms; much harder than just writing them natively in the first place.
Some more discussions on this:
Mobile development - Native VS Cross Platform VS JavaScript
How to code sharing between Android and iOS (Where I discuss how to share large, established C++ code bases. But this isn't applicable for new development.)
You list iOS as one of your desired platform. On iOS, any generic Bluetooth communication (other than Bluetooth LE or communication via Gamekit, headset or keyboard) is available only to Apple MFi program licensees. To get any details about this license, you need to apply to Apple's MFi program first. AFAIK, no 3rd party or cross platform tool chain can help you with this for iOS.
I don't believe the OP is talking about iOS app to device communication but rather peer-to-peer bluetooth communication. Would the requirement for Apple MFi program licensing apply?
If so, are the peer-to-peer Bluetooth APIs (and hardware) on say, Android or Windows Phone 8 be compatible with the one from iOS? And if they were, shouldn't passing data around by JSON be fairly straight-forward for building cross-mobile apps?
IMHO, for simple business apps, building native apps for each platform is the way to go if you want to make full use of available resources on each platform and conform to their differing UI design principles.

Rhomobile vs. MoSync/Phonegap/HTML5

I am interested in supporting a few different platforms, like Android, iOS, Windows, and I was interested in Rhomobile might help? However, I am concerned about not being able to use any device specific syncing capabilities. Has anyone worked with PhoneGap/MoSync combo and what has been your experience?
I'm not sure I understand what you mean by "not being able to use any device specific syncing capabilities" with Rhomobile. You can always create your own syncing mechanism using the network libraries as described here:
Connecting Directly with Web Services
You can also create native extensions and use them inside your Rhodes project so no native capability is impossible to access. Of course you would have to replicate this extension for every platform you are targetting or manage the differences in implementation in your code in a platform specific way.
Regarding the comparisson with the other multi-platform frameworks, we evaluated using PhoneGap but ended up deciding for Rhodes because of the development tools. Having a development tool that has integrated step-by-step debugging and the Rhodes simulator that allows you to test and manipulate your style sheets and works 100 times faster than the android emulator is a major advantage.

Categories

Resources