Im making an application based on phonegap (cordova). I have tested it some times, and lately I saw a message in xcode that said "Plugin should use a background thread." So is it possible to make cordova plugins run in the background of the app? if so, please tell how. Thanks!
回答:A background thread isn't the same that executing code while the app is in background, a background thread is used to don't block the UI while you execute a long task.
Example of background thread on iOS
- (void)myPluginMethod:(CDVInvokedUrlCommand*)command
{
// Check command.arguments here.
[self.commandDelegate runInBackground:^{
NSString* payload = nil;
// Some blocking logic...
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:payload];
// The sendPluginResult method is thread-safe.
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}
Example of background thread on android
@Override
public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException {
if ("beep".equals(action)) {
final long duration = args.getLong(0);
cordova.getThreadPool().execute(new Runnable() {
public void run() {
...
callbackContext.success(); // Thread-safe.
}
});
return true;
}
return false;
}
补充:
you can just edit code of the plugin to make it work. But be aware that on the plugin update your changes will be cleared. So for saving this code you need to do like jcesarmobile said (ask plugin owner to make those changes or fork)
答案:
You should use the $ionicConfigProvider
var myApp = angular.module('reallyCoolApp', ['ionic']);
myApp.config(function($ionicConfigProvider) {
// note that you can also chain configs
$ionicConfigProvider.views.maxCache(5);
$ionicConfigProvider.backButton.text('Go Back');
});
This example is from the official Ionic docs.
To control the behaviour of the "last view text on back button" you could set backButton.previousTitleText(value)
to false.
答案: 没有解决,用上面的方法临时救场。
答案:https://github.com/driftyco/ionic/issues/3317
I think that "swipe to go back" on should be disabled on pages that are not cached. Blank screens is in no way a good user experience!
Fixed with:
$ionicConfigProvider.views.swipeBackEnabled(false);
网友评论