So, we’re close to the end — how about a few sage words of advice?
JavaScript API
- Promisify your API
- Pre-process arguments in JavaScript
- convert to appropriate types
- throw type-mismatch errors, etc.
- Transpile ES2015+ to ES5 (not all targets support ES2015 natively, and ES is continuing to evolve yearly, anyway)
- Stick to the
cordova.plugins
namespace- Unless creating a polyfill; window is crowded!
- Return useful error messages to error callbacks
Native
- Return useful error information
- Use background threads for processing
- Avoid init at app startup unless necessary
<param name="onload" value="false" /> <!-- false is the default -->
Android
- Override
pluginInitialize
for plugin initialization logic (code) - Runtime Permission Requests (Marshmallow) (docs)
- Don’t forget Android activity lifecycle (docs) (code)
iOS
- Use
pluginInitialize
for plugin initialization logic (eg) (code) - If memory is getting low,
onMemoryWarning
is called (code) - If app is going to be terminated,
onAppTerminate
is called (code) - You can respond to
pause
,resume
, etc. (code), but you have to register for notifications inpluginInitialize
- If you need to handle URLs, override
handleOpenURL
(code) - Never, ever call JavaScript that triggers blocking UI (e.g.
alert
)
Navigation: