【问题标题】:THREAD WARNING: ['Camera'] took '290.006104' ms. Plugin should use a background thread线程警告:['Camera'] 花费了 '290.006104' 毫秒。插件应该使用后台线程
【发布时间】:2014-05-22 06:16:30
【问题描述】:

我正在为 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.

它阻止了我的应用程序。有人可以建议如何解决这个问题吗?

【问题讨论】:

    标签: ios cordova camera phonegap-plugins cordova-plugins


    【解决方案1】:

    我不确定您是否应该担心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 插件的参考look for THREADING

    【讨论】:

      猜你喜欢
      • 2018-02-24
      • 2015-08-06
      • 1970-01-01
      • 1970-01-01
      • 2014-04-23
      • 1970-01-01
      • 1970-01-01
      • 2022-06-17
      • 1970-01-01
      相关资源
      最近更新 更多