线程警告:['Camera']花了'290.006104'ms.插件应该使用后台线程

Esw*_*ddy 2 camera ios phonegap-plugins cordova cordova-plugins

我正在Phonegap为IOS 构建一个应用程序.我用Cordova相机plugin进行个人资料图片上传.我的示例代码是:

navigator.camera.getPicture(that.imageDataSuccessCallback, that.imageDataErrorCallback, { quality: 10, destinationType: 1, encodingType: 0, allowEdit: true, correctOrientation: true, sourceType:0 });
Run Code Online (Sandbox Code Playgroud)

当我点击该特定按钮时,我收到警告

THREAD WARNING: ['Camera'] took '290.006104' ms. Plugin should use a background thread.
Run Code Online (Sandbox Code Playgroud)

它阻止了我的应用.任何人都可以建议如何解决这个问题?

ben*_*nka 7

我不确定你应该关注,290ms但如果你是,你可以做以下事情:

因为navigator.camera.getPicture()Camera.js调用-(void)takePicture:(CDVInvokeUrlCommand*)command方法时CDVCamera.m你必须在那里添加线程.

CDVCamera.m在第一行takePicture方法之前打开并添加以下内容:

[self.commandDelegate runInBackground:^{
Run Code Online (Sandbox Code Playgroud)

结束在最后一行之后添加:

}];
Run Code Online (Sandbox Code Playgroud)

所以看起来应该是这样的:

- (void)takePicture:(CDVInvokedUrlCommand*)command
{
    [self.commandDelegate runInBackground:^{
        NSString* callbackId = command.callbackId;
        NSArray* arguments = command.arguments;

        ...
        ...
        ...

        self.hasPendingOperation = YES;
    }];
}
Run Code Online (Sandbox Code Playgroud)

以下是使用后台模式查找THREADING构建Cordova插件的参考: