Ionic学习笔记2016-06

  • 问题:How to run cordova plugins in the background?


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)

  • 问题:How can I change the back button title in ionic framework?

答案:

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.

  • 问题:using ion-nav-title makes the back button title doesn't show previous page title

答案: 没有解决,用上面的方法临时救场。
  • 问题: IOS Swipe to go back with nested states shows blank screen

答案: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);

你可能感兴趣的:(Ionic学习笔记2016-06)