测试内容:
1,单独的 index.html 页面,js部分如下:
checkTester:function(refunc){
var success, failure;
if(typeof refunc == 'function'){
success = function(val){
alert('succ---------')
refunc({type:"success", value:val});
}
failure = function(val){
alert('fail--------')
refunc({type:"fail", value:val});
}
}
callbackId = bridge.callbackId(success, failure);
alert('callbackId: '+callbackId);
bridge.exec(pluginName, "checkTester", [callbackId]);
},
2 ,在iOS端代码如下:
-(void)checkTester:(PGMethod*)command{
if (command){
checkID = [command.arguments objectAtIndex:0];
if(dFeature == nil){
dFeature=[[DomindFeature alloc] init];
}
[dFeature setChanger:self];
[dFeature timerTest];
}
}
注: timerTest 为一个每隔5秒钏调用一次回调方法
-(void)change:(NSString)value{
PDRPluginResult result = [PDRPluginResult resultWithStatus:PDRCommandStatusOK messageAsString:value];
NSLog(@"%@ %@",[result toJSONString], checkID);
[self toCallback:checkID withReslut:[result toJSONString]];
}
结果:
1, 调用时弹出 ‘callbackId: XXXX’
2, IOS端持续输出
{"status":1,"message":"timer test ","keepCallback":false} plus101432018415220
3, 页面没有出现期待的弹出窗 “succ---------”
3 个回复
lqdsj (作者)
附上 timer 的测试代码 (swift的):
func timerTest(){
var timer:NSTimer=NSTimer.scheduledTimerWithTimeInterval(5, target: self, selector: "updateTimers", userInfo: nil, repeats: true);
}
func updateTimers() {
plugin.change("timer test ");
}
DCloud_IOS_XTY
默认回调调用了就会移除,可以通过keepCallback属性控制是否移除true为不移除
lqdsj (作者)
好, 我试一下
2015-05-19 16:29
lqdsj (作者)
OK, 搞定
2015-05-19 16:31
黄小昆
回复 lqdsj:keepCallback这个属性 是在哪里设置的啊 新手不懂
2016-02-23 09:02
anke
keepCallback 为 ture
有时切换到其它页面后再回到插件的页面,callback还没有进来