Keep callback context in PhoneGap plugin?

ぃ、小莉子 提交于 2019-12-01 05:55:32
Tony Hursh

You'll want to have something like:

NSString *myCallbackId;

as an instance-level variable (outside of any method, so it retains its value). Set it when you first come in to the plugin code:

myCallbackId = command.callbackId;

Then, right after you instantiate a PluginResult, but before using it, do something like:

[pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];

That will tell it to keep the callback valid for future use.

Then do something like:

[self.commandDelegate sendPluginResult:pluginResult callbackId:myCallbackId];

hi for getting many callback to js you can use setKeepCallback(true)

eg

 PluginResult p3=   new PluginResult(PluginResult.Status.OK, "0");
 p3.setKeepCallback(true);

Just if it helps somebody, in Android I am not using PluginResult and I am still able to keep a reference to the CallbackContext and call it anytime. I am not sure if this is the right way, but I can confirm that it worked for me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!