【问题标题】:Cordova shows an warning as " THREAD WARNING: [Your function] took [n] ms. " in iOSCordova 在 iOS 中显示警告为“线程警告:[您的函数] 花费了 [n] 毫秒。”
【发布时间】:2015-08-06 13:20:41
【问题描述】:
 "THREAD WARNING: ['Console'] took '81.661865' ms. Plugin should use a  background thread."

在运行 iOS Phonegap 项目时。其余的一些插件也是如此,例如地理定位和文件系统。

由于我是 Phonegap 的新手,请谁能告诉我如何在后台线程上运行插件。

我也检查了this

我们可以忽略这个线程警告还是它与 iOS Phone-gap 中的内存问题有关

谢谢

【问题讨论】:

  • @Callodacity,我的问题是关于在后台使用插件时解决警告消息,而不是如何在后台运行科尔多瓦插件
  • 好吧,别担心,我只是在检查????

标签: ios thread-safety cordova-plugins background-thread cordova-3.8.0


【解决方案1】:

根据this。解决了我的警告问题

我发现警告可以忽略。但这可以通过使用此循环添加后台线程来解决:(在 CDVLogger.m 中)

 [self.commandDelegate runInBackground:^{

    //add your code here
 }

现在控制台警告如下所示:

- (void)logLevel:(CDVInvokedUrlCommand*)command
 {
   [self.commandDelegate runInBackground:^{
   id level = [command argumentAtIndex:0];
   id message = [command argumentAtIndex:1];

  if ([level isEqualToString:@"LOG"]) {
    NSLog(@"%@", message);
  } else {
      NSLog(@"%@: %@", level, message);
   }
 }];
}

【讨论】:

  • 同样可以解决相机、地理位置、pushplugin等的警告 "[self.commandDelegate runInBackground:^{//code here }"
  • 这只会限制日志在主线程上打印。这个只是将消息拉到后台线程,并没有解决延迟的实际问题。
【解决方案2】:

还要补充,

如果有人正在寻找一种方法来将 Geolocation 插件作为 iOS Cordova 的后台线程运行,那么 GitHub 上有一个修复程序。

它删除了 Xcode 输出警告:“线程警告:['Geolocation'] 花费了 'X' 毫秒。插件应该使用后台线程。”

从这里下载插件: https://github.com/guillaumedev/cordova-plugin-geolocation

这里有什么变化(添加了 runInBackground): https://github.com/guillaumedev/cordova-plugin-geolocation/commit/8fbceca845441f4f421548f243d2f05573d11225

有关 Cordova 线程的更多信息: https://cordova.apache.org/docs/en/dev/guide/platforms/ios/plugin.html#threading

【讨论】:

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