Cordova shows an warning as " THREAD WARNING: [Your function] took [n] ms. " in iOS
Asked Answered
O

2

13
 "THREAD WARNING: ['Console'] took '81.661865' ms. Plugin should use a  background thread."

While running iOS Phonegap project. Similarly for some of the remaining plugins like geolocation and filesystem.

As I am new to Phonegap ,can please anyone tell me how can I run the plugin on background thread.

I have checked this also.

Can we ignore this thread warning or is it related to memory issue in iOS Phone-gap

thanks

Outwear answered 25/5, 2015 at 5:47 Comment(3)
Possible duplicate of How to run cordova plugins in the background? – Thurmanthurmann
@Callodacity, My question regarding to solve the warning message while using plugins in background, but not how to run cordova plugins in background – Outwear
okay no worries, I was just checking 😊 – Thurmanthurmann
O
5

As per this. solved my warning issue

I found warning can be ignored .But this can be solved by adding background thread using this loop:(In CDVLogger.m)

 [self.commandDelegate runInBackground:^{

    //add your code here
 }

Now this looks as below for console warning:

- (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);
   }
 }];
}
Outwear answered 25/5, 2015 at 7:45 Comment(2)
Similarly the warning can be solved for camera ,geolocation,pushplugin etc "[self.commandDelegate runInBackground:^{//code here }" – Outwear
this only restricts log from being printed on main thread. This one just pulls the message to background thread, but does not solve the actual problem of the delay. – Sepulveda
I
1

Also to add,

If someone is looking for a way to run sepcifically the Geolocation plugin as a background thread with iOS Cordova there is a fix on GitHub.

It removes the Xcode output warning: "THREAD WARNING: ['Geolocation'] took 'X' ms. Plugin should use a background thread."

Download the plugin from here: https://github.com/guillaumedev/cordova-plugin-geolocation

Heres whats changed (runInBackground added): https://github.com/guillaumedev/cordova-plugin-geolocation/commit/8fbceca845441f4f421548f243d2f05573d11225

More information about Cordova Threading: https://cordova.apache.org/docs/en/dev/guide/platforms/ios/plugin.html#threading

Indusium answered 17/4, 2016 at 13:25 Comment(0)

© 2022 - 2024 β€” McMap. All rights reserved.