Skip to content

CB-14187: (ios) Change the InAppBrowser to allow custom schemes#274

Closed
wvengen wants to merge 2 commits into
apache:masterfrom
q-m:feature/allowedschemes-ios
Closed

CB-14187: (ios) Change the InAppBrowser to allow custom schemes#274
wvengen wants to merge 2 commits into
apache:masterfrom
q-m:feature/allowedschemes-ios

Conversation

@wvengen

@wvengen wvengen commented Jul 3, 2018

Copy link
Copy Markdown
Contributor

Platforms affected

  • iOS

What does this PR do?

Implements CB-14187, which adds support for the AllowedSchemes preference and customscheme event for iOS.

What testing has been done on this change?

Tested on an iPhone 5SE running iOS 11.4.

Checklist

@brody2consult

Copy link
Copy Markdown

The proposed changes definitely seem to be consistent with the corresponding functionality for Android from GH-263 (CB-14013). A couple more things that could help:

  • a quick and easy app that I or someone else could use to test on both iOS and Android
  • document the custom scheme support for both Android and iOS

@wvengen

wvengen commented Jul 18, 2018

Copy link
Copy Markdown
Contributor Author

Thanks for your review, @brodybits! I've added a test and some documentation.
I opted for a manual test only, since this needs a config.xml preference (even though I added that to the CONTRIBUTING document). It might be useful to add the preference to the regular Cordova documentation at some point in the future (not sure if that is desirable or not).

@brody2consult

Copy link
Copy Markdown

Thanks @wvengen. Unfortunately I had some real trouble getting a test demo to work on iOS. A quick demo project that shows this functionality working the same way on both Android and iOS (as closely as possible) would be really helpful.

@wvengen

wvengen commented Jul 19, 2018

Copy link
Copy Markdown
Contributor Author

Thanks for testing. Apparently I didn't test it enough, sorry. Still, for me it works on iOS, except that sometimes the alert Result verified is shown twice. That is because, apparently, the loadstop event is being fired for customscheme as well. I don't see how that can be avoided, as in webViewDidFinishLoad (nor the originating method) there is no context about the URL that caused it.

My proposal:

  1. Mention loadstop being called for customscheme in the documentation (an extra iOS quirks in addEventListener).
  2. In the test, only navigate to the custom URL at the first time it happens.

@brody2consult

Copy link
Copy Markdown

I gotta say that I am still not able to get it to work on either Android or iOS in my test project at https://github.com/brodybits/cordova-iab-custom-scheme-test-wip (with 1 test link and 3 button tests). I suspect that I am doing something wrong; it would be best if you can issue a PR to correct me.

If I would add the proposed version of this plugin using the following command:

cordova plugin add https://github.com/q-m/cordova-plugin-inappbrowser#feature/allowedschemes-ios

then add iOS platform and then run from Xcode, I would get the following console log message on iOS when I click the test link or any test button:

2018-07-20 17:35:38.166670-0400 HelloCordova[12282:282185] Failed to load webpage with error: The URL can’t be shown

I get the following console log output if I click the test 3 button:

2018-07-20 18:05:31.146655-0400 HelloCordova[12987:301089] NSURLConnection finished with error - code -1002
2018-07-20 18:05:31.155721-0400 HelloCordova[12987:299914] Failed to load webpage with error: The URL can’t be shown

Test does not work for me on Android either.

If another Cordova member with more experience with this plugin can review and test I would be grateful.

@wvengen

wvengen commented Jul 31, 2018

Copy link
Copy Markdown
Contributor Author

It took me some experimentation to find the cause, but the page you load in the whitelist (local page), it is loaded in the Cordova WebView instead of InAppBrowser. Make it cordova.InAppBrowser.open('iabpage.html', '_blank') and the example should work.

Some small corrections in: wvengen/cordova-iab-custom-scheme-test-wip@5917542 (should work without) and wvengen/cordova-iab-custom-scheme-test-wip@821652d (makes link work).

@brody2consult

Copy link
Copy Markdown

Thanks @wvengen I will take another look today.

Comment thread tests/tests.js Outdated
}
});
ref.addEventListener('customscheme', function (e) {
if (e && e.url === "custom://test") {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just discovered today that npm run eslint has a few failures:

/Users/brodybits/Documents/cordova/cordova-plugin-inappbrowser/tests/tests.js
  714:32  error  Strings must use singlequote                    quotes
  715:1   error  Expected indentation of 16 spaces but found 14  indent
  715:15  error  'alert' is not defined                          no-undef
  717:1   error  Expected indentation of 16 spaces but found 14  indent
  717:15  error  'alert' is not defined                          no-undef
  722:13  error  'alert' is not defined                          no-undef

✖ 6 problems (6 errors, 0 warnings)
  3 errors, 0 warnings potentially fixable with the `--fix` option.

I can think of 2 possible solutions for 'alert' is not defined:

  • use // eslint-disable-line no-undef
  • preferred: use window.alert (less ugly, more likely to work on Windows platform)

A nice bonus would be to fix alert --> window.alert throughout tests.js.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I went for the bonus in 93077ef (hoping it will help motivate you to complete the review ;) ). Tested it still works (Android).

@brody2consult

Copy link
Copy Markdown

I pulled the changes from wvengen/cordova-iab-custom-scheme-test-wip@821652d (master branch) into my master branch, doesn't seem to help on either Android or iOS. Gotta say I am getting ready to give up on this one. I just pushed one more change to https://github.com/brodybits/cordova-iab-custom-scheme-test-wip to use your q-m:feature/allowedschemes-ios branch for now, it would be great if you could fix the sample for the sake of the user community.

If you want another expert to take a look I suggest you send a request to: mailto:dev@cordova.apache.org

@wvengen

wvengen commented Aug 1, 2018

Copy link
Copy Markdown
Contributor Author

@brodybits thanks for checking again. The important change is adding _blank to window.open, which was not present on my fork's master yet (but added to the docs in this PR). I'll create a PR for your test app with all changes needed to make it work.

Also, I'll look into the eslint output.

@brody2consult

Copy link
Copy Markdown

Thanks @wvengen for the update, fixing the eslint warnings, and fixing the alert calls. I will probably need 1-2 weeks to take another look. Apologies for the extra delays.

@wvengen

wvengen commented Aug 3, 2018

Copy link
Copy Markdown
Contributor Author

No problem, looking forward to getting this merged, somewhere in the coming weeks if all works out. :)

@wvengen

wvengen commented Aug 29, 2018

Copy link
Copy Markdown
Contributor Author

Hi @brodybits just a reminder, if you see an opportunity to take another look, please don't forget :)

@janpio

janpio commented Oct 2, 2018

Copy link
Copy Markdown
Member

And passing :) (context: #307 (comment))

@brody2consult brody2consult left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks OK to me, merging

@brody2consult

Copy link
Copy Markdown

@wvengen can you help resolve the conflicts?

@wvengen

wvengen commented Oct 5, 2018

Copy link
Copy Markdown
Contributor Author

Thanks! I'll be happy to rebase on master once #276 is sorted out.

@janpio

janpio commented Oct 30, 2018

Copy link
Copy Markdown
Member

#276 is merged, so this can be taken care of now I think.

@wvengen

wvengen commented Oct 31, 2018

Copy link
Copy Markdown
Contributor Author

I will look at it, thanks.

@wvengen wvengen force-pushed the feature/allowedschemes-ios branch from 238693b to 0ca4dd7 Compare October 31, 2018 09:06
@wvengen

wvengen commented Oct 31, 2018

Copy link
Copy Markdown
Contributor Author

Rebased. Tested on Android (7) and iOS (iPhone 8) emulator.

@jonathanli2

Copy link
Copy Markdown
Contributor

it looks like this change is only for uiwebview.
Currently wkwebiew does not handle customer url scheme, except for the app store url. Please refer to CDVWKInappbrowser.m's below method

  • (BOOL)webView:(WKWebView*)theWebView decidePolicyForNavigationAction:(NSURLRequest*)request;

Should the change also handle custom url for wkwebview?

Thanks
Jonathan

@timbru31

Copy link
Copy Markdown
Member

@wvengen could you possibly rebase your change, resolve the conflicts and see if the code has to be migrated/copied to the UIWebView and WKWebView? Thanks a lot!

@janpio

janpio commented Apr 24, 2019

Copy link
Copy Markdown
Member

We can take care of (trivial) merge conflicts as this ourselves @timbru31 via the GitHub UI, no need to put the work on the original committer. Just did so.

@timbru31

timbru31 commented Apr 24, 2019 via email

Copy link
Copy Markdown
Member

@janpio

janpio commented Apr 24, 2019

Copy link
Copy Markdown
Member

Yes, that part of course has to be evaluated by @wvengen.
(Maybe @dpa99c can help out there as well?)

@wvengen

wvengen commented Jun 13, 2019

Copy link
Copy Markdown
Contributor Author

Any help is appreciated here, as I'm not at all familiar with WKWebView, and I don't have that much time currently to look into that.

@timbru31 timbru31 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like I've already said, WKWebView is currently missing. - to prevent any accidental merge (since there is already one approval) I'm adding a "request changes".


No worries @wvengen - maybe someone else can finish this PR. Thanks a lot for your contributions!

return NO;
}

- (BOOL)isAllowedScheme:(NSString*)scheme

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This need to be added to the WKWebView, too.

GitToTheHub pushed a commit that referenced this pull request Feb 10, 2026
- Add support for the `AllowedSchemes` preference and `customscheme` event for iOS like on Android.
- Token from PR #274 which was implementing it in `UIWebView`
- JIRA-Ticket: https://issues.apache.org/jira/browse/CB-14187
@GitToTheHub

Copy link
Copy Markdown
Contributor

Implemented in WKWebView through #1112

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants