Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go Back Action? #79

Open
gustter opened this issue Jun 12, 2015 · 1 comment
Open

Go Back Action? #79

gustter opened this issue Jun 12, 2015 · 1 comment
Labels

Comments

@gustter
Copy link

gustter commented Jun 12, 2015

Hi.

How can I implement a go back action on iOS? I've an wizViewManager with a site but when I click a link then i can't go back.

Thanks.

@jrouault
Copy link
Member

Hello,

Implementing a back action should be pretty straight-forward.

According to the actual style of this plugin I would go for something like this:

  • in wizViewManager.js:
View.prototype.goBack = function (success, failure) {
    cordova.exec(success, failure, "WizViewManagerPlugin", "goBack", [this.name]);                      
};

WizViewManager.prototype.goBack = function (name, success, failure) {
    if (!this.views[name]) {
        return this.throwError(failure, new Error('Show Error with view name: ' + name + '. View does not exist'));
    }

    this.views[name].goBack(success, failure);
};
  • in WizViewManagerPlugin.m:
- (void)goBack:(CDVInvokedUrlCommand *)command {
    NSString *viewName = [command.arguments objectAtIndex:0];
    if ([wizViewList objectForKey:viewName]) {
        UIWebView *targetWebView = [wizViewList objectForKey:viewName];
        if ([targetWebView canGoBack]) {
            [targetWebView goBack];
            CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
            [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
        } else {
            CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:
                    [self throwError:1 description:@"View not found"]];
            [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];            
        }
    } else {
        CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:
                [self throwError:1 description:@"View not found"]];
        [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
    }
}

⚠️ I wrote this quickly so you will probably have to adapt/correct it and clean it a bit in order to make it works.

Feel free to comment here if you have any difficulty implementing it.
Once it's done and tested, it would be really nice if you could make a PR with this feature.

You can find more information on UIWebView here:
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIWebView_Class/#//apple_ref/occ/instm/UIWebView/goBack

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants