线程警告:["相机"] 占用"290.006104"毫秒。插件应使用后台线程



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

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

当我点击那个特定的按钮时我收到了警告作为

THREAD WARNING: ['Camera'] took '290.006104' ms. Plugin should use a background thread.

它正在阻止我的应用程序。谁能建议如何解决这个问题?

我不确定您是否应该关注290ms,但如果您是,您可以执行以下操作:

由于Camera.js中的navigator.camera.getPicture()CDVCamera.m中调用-(void)takePicture:(CDVInvokeUrlCommand*)command方法,您必须在那里添加线程

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

[self.commandDelegate runInBackground:^{
}];

应该是这样的

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

这是一个使用后台模式构建Cordova插件的参考,查找THREADING:

最新更新