我正在实现Cordova本机插件,我希望将本机实现中的事件暴露给JS
我已经看到apache/cordova-plugin-geolocation通过重复调用成功回调来实现watchPosition
,直到调用clearWatch
为止。
我还发现有一种方法cordova.fireDocumentEvent
,但没有找到关于它的好文档。
每种方法的优缺点是什么?
答案 0 :(得分:1)
我发现我能多次称之为成功 我已修改此"hello world plugin" for Cordova以回拨两次(当然可以扩展):
#import "HWPHello.h"
@implementation HWPHello
- (void)greet:(CDVInvokedUrlCommand*)command
{
NSString* name = [[command arguments] objectAtIndex:0];
NSString* msg = [NSString stringWithFormat: @"Welcome Mr. %@", name];
CDVPluginResult* result = [CDVPluginResult
resultWithStatus:CDVCommandStatus_OK
messageAsString:msg];
// Set the KeepCallback before sending the result will keep the callback id for further callbacks
[result setKeepCallbackAsBool:YES];
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
msg = [NSString stringWithFormat: @"Hi Mr. %@", name];
result = [CDVPluginResult
resultWithStatus:CDVCommandStatus_OK
messageAsString:msg];
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
}
@end