cordova-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jesse <purplecabb...@gmail.com>
Subject Re: optimizing ios inappbrowser plugin's open and openInSystem method s
Date Thu, 08 Sep 2016 16:15:03 GMT
Second call steals the callbackID of the first. 
On it. Thanks!

> On Sep 7, 2016, at 6:34 AM, Li, Jonathan <jonathan.li@sap.com> wrote:
> 
> Hi,
> 
> The problem with
> self.callbackId = command.callbackId;
> is it causes the current inappbrowser stopping work properly after user clicks a link
to open mobile safari using window.open method from the current inappbrowser html page.
> 
> In our application, the inappbrowser is opened in inappbrowser webivew controller, the
open method will set self.callbackId to the related value. In the html page loaded in the
inappbrowser, there is link using window.open with system target to open an external page
in mobile safari. When user clicks this link, the inappbrowser open method will be called
again, and set self.callbackid to a new vaule, as a result after the mobile safari is opened,
the original inappbrowser’s callback will not work anymore as its callback id is replaced
by the second open method.
> 
> Theoretically, the first inappbrowser’s function should still not be affected if it
opens another link in new system browser, as the callback id is not used by system browser
> 
> For the issue of when to use SASafarirViewController, it seems SASafariViewController
is more a replacement for mobile safari (for system target) instead of inappbrowser webviewcontroller
(for blank target). As SFSafariViewController is designed to replace the function of mobile
safari, so there are no backward compatible issues or losing functions by doing so, and application
will not have any major behavior difference with this change. On the other hand, SASafariViewController
does not provide all the functions provided by inappbrowser webviewcontroller, replacing inappbrowser
webview controller with SASafariViewController will have more risks.
> 
> Thanks
> Jonathan
> From: julio cesar sanchez <jcesarmobile@gmail.com>
> Date: Wednesday, September 7, 2016 at 3:25 AM
> To: "Li, Jonathan" <jonathan.li@sap.com>
> Cc: "dev@cordova.apache.org" <dev@cordova.apache.org>
> Subject: Re: optimizing ios inappbrowser plugin's open and openInSystem method s
> 
> What is the problem self.callbackId = command.callbackId; causes when used with _system
option?
> 
> I think _system option should open in safari app as it does now, and SFSafariViewController
should replace the ViewController we use when _blank is used.
> 
> 2016-09-07 6:41 GMT+02:00 Li, Jonathan <jonathan.li@sap.com<mailto:jonathan.li@sap.com>>:
> 
> Hi,
> Currently there are two issues in iOS inappbrowser’s open and  openInSystem methods.
> 
> First, in the inappbrowser open method, it sets the instance variable at below
>        self.callbackId = command.callbackId;
> this causes the problem when opening a _system targe from an inappbrowser viewController,
even if the callbackID are not applicable to system browser.
> 
> Second, the _system target will always be opened in external mobile safari browser, although
SFSafariViewController for iOS 9 device provides a better user experience. The major benefit
with SFSafariViewController is the application staying in foreground, so that the application
does not need to handle the application life cycle events triggered by opening the mobile
safari.
> 
> 
> The below code is a prototype handling the two issues. Just want to know your comment
about this change, and if it is fine, a pull request will be submitted for it.
> 
> - (void)open:(CDVInvokedUrlCommand*)command
> {
>    CDVPluginResult* pluginResult;
> 
>    NSString* url = [command argumentAtIndex:0];
>    NSString* target = [command argumentAtIndex:1 withDefault:kInAppBrowserTargetSelf];
>    NSString* options = [command argumentAtIndex:2 withDefault:@"" andClass:[NSString
class]];
> 
>   //**********the below line causes trouble to open system url from inappbrowser
>   //self.callbackId = command.callbackId;
> 
>    if (url != nil) {
> #ifdef __CORDOVA_4_0_0
>        NSURL* baseUrl = [self.webViewEngine URL];
> #else
>        NSURL* baseUrl = [self.webView.request URL];
> #endif
>        NSURL* absoluteUrl = [[NSURL URLWithString:url relativeToURL:baseUrl] absoluteURL];
> 
>        if ([self isSystemUrl:absoluteUrl]) {
>            target = kInAppBrowserTargetSystem;
>        }
> 
>        if ([target isEqualToString:kInAppBrowserTargetSelf]) {
>            [self openInCordovaWebView:absoluteUrl withOptions:options];
>        } else if ([target isEqualToString:kInAppBrowserTargetSystem]) {
>            [self openInSystem:absoluteUrl];
>        } else { // _blank or anything else
>            [self openInInAppBrowser:absoluteUrl withOptions:options];
>        }
> 
>        pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
>    } else {
>        pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"incorrect
number of arguments"];
>    }
> 
>    //***********new code
>    if (![target isEqualToString:kInAppBrowserTargetSystem]) {
>        [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
>        self.callbackId = command.callbackId;
>    }
> 
>    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
> }
> 
> 
> - (void)openInSystem:(NSURL*)url
> {
>    //************ customization: open _system web url in Safari view controller on ios
9 device
>    if (([[[UIDevice currentDevice] systemVersion] compare:@"9.0" options:NSNumericSearch]
!= NSOrderedAscending) &&
>          ([[url.scheme lowercaseString] isEqualToString:@"http"] || [[url.scheme lowercaseString]
isEqualToString:@"https"])) {
>        SFSafariViewController* sf = [[SFSafariViewController alloc] initWithURL:url];
>        sf.delegate = self;
>        //check whether inappbrowser is presented, if so, use it to present the safari
viewcontroller
>        if (self.viewController.presentedViewController != nil){
>            [self.viewController.presentedViewController presentViewController:sf animated:YES
completion:nil];
>        }
>        else{
>            [self.viewController presentViewController:sf animated:YES completion:nil];
>        }
>    }
>    else{
>        if ([[UIApplication sharedApplication] canOpenURL:url]) {
>            [[UIApplication sharedApplication] openURL:url];
>        } else { // handle any custom schemes to plugins
>            [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification
object:url]];
>        }
>    }
> }
> 
> - (void)safariViewControllerDidFinish:(SFSafariViewController *)controller{
>    [controller dismissViewControllerAnimated:YES completion:nil];
> }
> 
> 
> Thanks
> Jonathan
> 

Mime
  • Unnamed multipart/alternative (inline, 7-Bit, 0 bytes)
View raw message