I'm following Apple's Sample project for Playing Media in a Client-Server App.
func executeRemoteMethod(_ methodName: String, completion: @escaping (Bool) -> Void) {
appController?.evaluate(inJavaScriptContext: { (context: JSContext) in
let appObject : JSValue = context.objectForKeyedSubscript("App")
if appObject.hasProperty(methodName) {
appObject.invokeMethod(methodName, withArguments: [])
}
}, completion: completion)
}
The method is getting called during Application lifecycle events like this:
func applicationWillEnterForeground(_ application: UIApplication) {
executeRemoteMethod("onWillEnterForeground", completion: { (success: Bool) in
// ...
})
}
I'm wondering how it's working. Is this so that the native iOS codebase can communicate the lifecycle event to the Javascript code? When I put a breakpoint I see executeRemoteMethod function getting called. But I don't think it's actually doing anything. How can I map it to a js function? Do I have to create a new js file or just create a new function in my application.js file?
Thanks to reading this tutorial. I learned:
In its tutorial the
application.jslooks like this:As a result I just have to add the following inside
application.jsthen it will get called upon AppDelegates'sWillEnterForeGroundcallback.