apache / cordova-ios

Apache Cordova iOS
https://cordova.apache.org/
Apache License 2.0
2.16k stars 987 forks source link

refactor: default to file scheme #866

Closed erisu closed 4 years ago

erisu commented 4 years ago

Motivation and Context

Use file as default scheme to avoid break in current apps/

Description

  1. defaults to file if preference scheme is not set.
  2. continue to uses file if preference scheme is set to file.
  3. use what ever value the user defines in as preference scheme as a custom scheme handler, excluding file which was defined in the above case 2.
  4. preference hostname is only used when scheme is not file.
  5. CDV_ASSETS_URL is set to <scheme>://<hostname> -> if file, hostname = “”. -> if !file, hostname = "localhost" or user define value for preference hostname.
  6. Extension of above case 3, if scheme is set and is not file, it will also validate against WKWebView handlesURLScheme, if it is not valid, it will default to app

Testing

Checklist

codecov-commenter commented 4 years ago

Codecov Report

Merging #866 into master will not change coverage. The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #866   +/-   ##
=======================================
  Coverage   74.40%   74.40%           
=======================================
  Files          13       13           
  Lines        1676     1676           
=======================================
  Hits         1247     1247           
  Misses        429      429           

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 7460737...653cbf9. Read the comment docs.

ghost commented 4 years ago

I have a hard time understanding how to use custom scheme with cordova-ios 6, specifically the behaviour introduced here :

In the description of the behaviour by erisu, it says :

it will also validate against WKWebView handlesURLScheme, if it is not valid, it will default to app

But in the code, the actual condition is :

if(scheme == nil || [WKWebView handlesURLScheme:scheme]){
     scheme = @"app";
}

which, to my understanding of Objective-C, means that if it IS valid, it will default to app, cf. WKWebView handlesURLScheme documentation here

Could someone clarify this to me ?

breautek commented 4 years ago

During the course of development, defaulting to custom scheme was changed to default to the file url.

The reasoning is because changing protocols will cause users to be missing their web storage data. So we wanted to make schemes an opt-in feature instead.

I don't think this feature is documented yet, but an example config to use schemes can be found at https://github.com/apache/cordova-ios/pull/781#pullrequestreview-357408875

jcesarmobile commented 4 years ago

handlesURLScheme returns true if the webview already handles the scheme, if the webview already handles that scheme, it means we can't use that scheme for serving the app content, so if you set the scheme to http, https, file or a few others, handlesURLScheme is true and we default to app, if it returns false, it means whatever you configured is safe to use.

lovelyelfpop commented 4 years ago

Cordova-ios@6.1.0 says 'refactor: default to file scheme', why the url of my app is still myscheme:// not 'file://'? How to open file:// url while still remain <preference name="scheme" value="myscheme" />?