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.