【发布时间】:2013-09-12 08:04:42
【问题描述】:
我需要实现一些功能来触发间隔上的操作并将结果发送回 javascript。
为了简化事情,我将使用 PhoneGap 文档中的 echo 示例:
- (void)echo:(CDVInvokedUrlCommand*)command
{
[self.commandDelegate runInBackground:^{
CDVPluginResult* pluginResult = nil;
NSString* echo = [command.arguments objectAtIndex:0];
if (echo != nil && [echo length] > 0) {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:echo];
} else {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
}
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}
我想在调用stop 之前每秒使用回声使这个调用同一个回调。
我创建了一个每秒调用另一个函数的计时器,但我不知道如何保留回调的上下文以将结果发送到。
//Starts Timer
- (void)start:(CDVInvokedUrlCommand*)command
{
[NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(action:)
userInfo:nil
repeats:YES];
}
//Called Action
-(void)action:(CDVInvokedUrlCommand*)command
{
[self.commandDelegate runInBackground:^{
NSLog(@"TRIGGERED");
}];
}
在回调的上下文中保持它的任何帮助都会很棒。谢谢!
【问题讨论】:
标签: cordova phonegap-plugins cordova-3