我正在设计一个phonegap ios应用程序,其中从相机捕获的图像保存在设备中,图像名称保存在sqlite DB中 . 然后通过获取图像的名称在应用程序中显示保存的图像 .

我的情况是,图像由相机捕获(使用cordova插件),捕获的图像通过使用自定义插件保存在sqlite db中的设备和图像名称中 . 之后,通过使用自定义插件中的函数从sqlite db中获取图像来显示图像 . 捕获图像,将其保存到sqlite DB并在应用程序中显示它的过程是一个序列过程(通过回调逐步执行) . 问题是本机函数不会向js返回回调(成功或错误) . 我已经使用相同的本机函数来获取其他地方的图像,并且它正在那里工作 . 使用cordova插件捕获图像后,该函数无法返回回调 .

cordova相机插件有这样的错误吗? P.S我正在测试ios 8.1,我的相机插件是最新的 .

Link for CDVCamera.m

-(void)ActionSelectQuery:(CDVInvokedUrlCommand*)command{
    @try{
        CDVPluginResult *pluginResult = nil;
        NSDictionary *pluginParams = [command.arguments objectAtIndex:0];
        NSString *query = [pluginParams objectForKey:@"message"];  //"SELECT * FROM Attachments WHERE FileName NOT like '%Images%' AND Type = 'AttachmentFile' AND Id = 2";
        SqliteHelper *sqlitehelper = [[SqliteHelper alloc]init];
        NSMutableArray * returnedArray = [sqlitehelper selectQueryRaw:query];
        if ([returnedArray count] > 0) {
            NSString * jsonValue = @"[";
            int count = [returnedArray count];
            for (int i = 0; i < count ; i++) {
                if (i == (count - 1)) {
                    jsonValue = [jsonValue stringByAppendingFormat:@"%@]", [returnedArray objectAtIndex:i]];
                }else{
                    jsonValue = [jsonValue stringByAppendingFormat:@"%@,", [returnedArray objectAtIndex:i]];
                }
            }
            pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:jsonValue];
        }
        else{
            pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"[]"]; // error callback
        }
        [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
    }
    @catch (NSException *exception) {
        NSLog(@"sqlite exception reason:%@",[exception reason]);
    }
 }

selectQueryRaw函数:

-(NSMutableArray *)selectQueryRaw: (NSString*)selectQuery{
    NSMutableDictionary *storedValues = [[NSMutableDictionary alloc]init];
    NSMutableArray *arrayToReturn = [[NSMutableArray alloc]init];
    @try {
        dbpath = [dbFullPath UTF8String];
        if (sqlite3_open(dbpath, &testDb) == SQLITE_OK) {
            sqlite3_stmt *selectStatement;
            if(sqlite3_prepare_v2(testDb, [selectQuery UTF8String], -1, &selectStatement, NULL) == SQLITE_OK){

                while (sqlite3_step(selectStatement) == SQLITE_ROW) {
                    NSInteger dataCount =  sqlite3_data_count(selectStatement);
                    for (int i = 0; i < dataCount; i++) {
                        char *key = "";
                        char *value = "";
                        key = (char *)sqlite3_column_name(selectStatement, i);
                        value = (char *)sqlite3_column_text(selectStatement, i);
                        NSString *testValue = [NSString stringWithFormat:@"%s", value];
                        if ([testValue isEqualToString:@"(null)"]) {
                            testValue=@"";
                        }
                        [storedValues setObject:testValue forKey:[NSString stringWithFormat:@"%s", key]];
                    }
                    NSData *dataFromDict = [NSJSONSerialization dataWithJSONObject:storedValues
                                                                       options:0
                                                                         error:nil];
                    NSString *eachRowValue = [[NSString alloc]initWithData:dataFromDict encoding:NSUTF8StringEncoding];
                    [arrayToReturn addObject:eachRowValue];
                }
                return arrayToReturn;
            }
        }else{
            NSLog(@"error");
            return NULL;
        }
    }
    @catch (NSException *exception) {
        NSLog(@"%@", [exception reason]);
        return NULL;
    }
}

js部分:

obj.executeSelectQuery(query, function (attachmentObj) {
      //this plugin call doesn't get any callbacks from native
},function(){
    alert("fail");
});

插件通话:

executeSelectQuery: function(query, successCallback, errorCallback){

   cordova.exec(
                successCallback, // success callback function
                errorCallback, // error callback function
                'TestClass', // mapped to our native class
                'ActionSelectQuery', // with this action name
                [{                  // and this array of custom arguments to create our entry
                 "message": query
                 }]
        );
   }