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...@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
>
>

Reply via email to