我正在为 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()
正在调用 -(void)takePicture:(CDVInvokeUrlCommand*)command
CDVCamera.m
中的方法,您必须在那里添加threading。
打开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 插件的引用 look for THREADING :
关于ios - 线程警告 : ['Camera' ] took '290.006104' ms. 插件应使用后台线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23799116/