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

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

wvengen
Copy link
Contributor

@wvengen wvengen commented Jul 3, 2018

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

@brodycj
Copy link

brodycj commented Jul 17, 2018

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
Copy link
Contributor Author

wvengen commented Jul 18, 2018

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

@brodycj
Copy link

brodycj commented Jul 19, 2018

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
Copy link
Contributor Author

wvengen commented Jul 19, 2018

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.

@brodycj
Copy link

brodycj commented Jul 20, 2018

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
Copy link
Contributor Author

wvengen commented Jul 31, 2018

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

@brodycj
Copy link

brodycj commented Jul 31, 2018

Thanks @wvengen I will take another look today.

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

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

@brodycj
Copy link

brodycj commented Jul 31, 2018

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
Copy link
Contributor Author

wvengen commented Aug 1, 2018

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

@brodycj
Copy link

brodycj commented Aug 3, 2018

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
Copy link
Contributor Author

wvengen commented Aug 3, 2018

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

@wvengen
Copy link
Contributor Author

wvengen commented Aug 29, 2018

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

@janpio
Copy link
Member

janpio commented Oct 2, 2018

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

Copy link

@brodycj brodycj left a comment

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

@brodycj
Copy link

brodycj commented Oct 3, 2018

@wvengen can you help resolve the conflicts?

@wvengen
Copy link
Contributor Author

wvengen commented Oct 5, 2018

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

@janpio
Copy link
Member

janpio commented Oct 30, 2018

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

@wvengen
Copy link
Contributor Author

wvengen commented Oct 31, 2018

I will look at it, thanks.

@wvengen
Copy link
Contributor Author

wvengen commented Oct 31, 2018

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

@jonathanli2
Copy link
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
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
Copy link
Member

janpio commented Apr 24, 2019

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
Copy link
Member

timbru31 commented Apr 24, 2019 via email

@janpio
Copy link
Member

janpio commented Apr 24, 2019

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

@wvengen
Copy link
Contributor Author

wvengen commented Jun 13, 2019

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.

Copy link
Member

@timbru31 timbru31 left a comment

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!

@@ -439,6 +439,21 @@ - (BOOL)isValidCallbackId:(NSString *)callbackId
return NO;
}

- (BOOL)isAllowedScheme:(NSString*)scheme
Copy link
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.

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.

5 participants