Skip to content

Commit

Permalink
feat(iOS): Remove GCDWebServer (#244)
Browse files Browse the repository at this point in the history
* feat(iOS): Remove GCDWebServer

Removes the GCDWebServer and simplifies code. It requires iOS 11+

BREAKING CHANGE: Sets deployment-target to 11, so will only work on iOS 11+

* Address changes
  • Loading branch information
jcesarmobile authored and mlynch committed Dec 19, 2018
1 parent 8ef0c30 commit 0dee0cf
Show file tree
Hide file tree
Showing 33 changed files with 88 additions and 7,128 deletions.
78 changes: 25 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@

A Web View plugin for Cordova, focused on providing the highest performance experience for Ionic apps (but can be used with any Cordova app).

This plugin defaults to using WKWebView on iOS and the latest evergreen webview on Android. Additionally, this plugin makes it easy to use HTML5 style routing
that web developers expect for building single-page apps.
This plugin uses WKWebView on iOS and the latest evergreen webview on Android. Additionally, this plugin makes it easy to use HTML5 style routing that web developers expect for building single-page apps.

Note: This repo and its documentation are for `cordova-plugin-ionic-webview` @ `2.x`, which uses the new features that may not work with all apps. See [Requirements](#requirements) and [Migrating to 2.x](#migrating-to-2x).
Note: This repo and its documentation are for `cordova-plugin-ionic-webview` @ `3.x`, which uses the new features that may not work with all apps. See [Requirements](#requirements) and [Migrating to 3.x](#migrating-to-3x).

:book: **Documentation**: [https://beta.ionicframework.com/docs/building/webview][ionic-webview-docs]

Expand All @@ -40,22 +39,28 @@ Note: This repo and its documentation are for `cordova-plugin-ionic-webview` @ `

## Configuration

This plugin has several configuration options that can be set in `config.xml`. Important: some configuration options should be adjusted for production apps, especially `WKPort`:
This plugin has several configuration options that can be set in `config.xml`.

### iOS and Android Preferences
### Android and iOS Preferences

Preferences available for both iOS and Android platforms
Preferences available for both iOS and Android

#### WKPort
#### Hostname

```xml
<preference name="WKPort" value="8080" />
```
`<preference name="Hostname" value="app" />`

The default port the server will listen on. _You should change this to a random port number!_
Default value is `localhost`.

#### MixedContentMode
Example `ionic://app` on iOS, `http://app` on Android.

If you change it, you'll need to add a new `allow-navigation` entry in the `config.xml` for the configured url (i.e `<allow-navigation href="http://app/*"/>` if `Hostname` is set to `app`).
This is only needed for the Android url as it uses `http://`, all `ionic://` urls are whitelisted by the plugin.

### Android Preferences

Preferences only available Android platform

#### MixedContentMode

```xml
<preference name="MixedContentMode" value="2" />
Expand All @@ -75,50 +80,13 @@ Other possible values are `1` (`MIXED_CONTENT_NEVER_ALLOW`) and `2` (`MIXED_CONT

Preferences only available for iOS platform

#### UseScheme

`<preference name="UseScheme" value="true" />`

Default value is `false`.

On iOS 11 and newer it will use a `WKURLSchemeHandler` that loads the app from `ionic://` scheme instead of using the local web server and `https://` scheme.

On iOS 10 and older will continue using the local web server even if the preference is set to `true`.

#### HostName

`<preference name="HostName" value="myHostName" />`

Default value is `app`.

If `UseScheme` is set to yes, it will use the `HostName` value as the host of the starting url.

Example `ionic://app`

#### WKSuspendInBackground

```xml
<preference name="WKSuspendInBackground" value="false" />
```

Whether to try to keep the server running when the app is backgrounded. Note: the server will likely be suspended by the OS after a few minutes. In particular, long-lived background tasks are not allowed on iOS outside of select audio and geolocation tasks.

#### WKBind

```xml
<preference name="WKBind" value="localhost" />
```

The hostname the server will bind to. There aren't a lot of other valid options, but some prefer binding to "127.0.0.1"

#### WKInternalConnectionsOnly (New in 2.2.0)

```xml
<preference name="WKInternalConnectionsOnly" value="true" />
```

Whether to restrict access to this server to the app itself. Previous versions of this plugin did not restrict access to the app itself. In 2.2.0 and above,
the plugin now restricts access to only the app itself.
Set to false to stop WKWebView suspending in background too eagerly.

#### KeyboardAppearanceDark

Expand All @@ -130,10 +98,10 @@ Whether to use a dark styled keyboard on iOS

## Plugin Requirements

* **iOS**: iOS 10+ and `cordova-ios` 4+
* **iOS**: iOS 11+ and `cordova-ios` 4+
* **Android**: Android 4.4+ and `cordova-android` 6.4+

## Migrating to 2.x
## Migrating to 3.x

1. Remove and re-add the Web View plugin:

Expand All @@ -144,7 +112,11 @@ Whether to use a dark styled keyboard on iOS

1. Apps are now served from HTTP on Android.

* The origin for requests from the Web View is `http://localhost:8080`.
* The default origin for requests from the Android WebView is `http://localhost`. If `Hostname` preference is set, then origin will be `http://HostnameValue`.

1. Apps are now served from `ionic://` scheme on iOS.

* The default origin for requests from the iOS WebView is `ionic://localhost`. If `Hostname` preference is set, then origin will be `ionic://HostnameValue`.

1. Replace any usages of `window.Ionic.normalizeURL()` with `window.Ionic.WebView.convertFileSrc()`.

Expand Down
41 changes: 2 additions & 39 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

<engines>
<engine name="cordova-ios" version=">=4.0.0-dev"/>
<engine name="apple-ios" version=">=9.0"/>
<engine name="apple-ios" version=">=11.0"/>
<engine name="cordova-android" version=">=6.4.0"/>
</engines>

Expand Down Expand Up @@ -60,9 +60,8 @@
</js-module>

<config-file target="config.xml" parent="/*">
<allow-navigation href="http://localhost:8080/*"/>
<allow-navigation href="http://127.0.0.1:8080/*"/>
<allow-navigation href="ionic://*"/>
<preference name="deployment-target" value="11.0" />
<feature name="IonicWebView">
<param name="ios-package" value="CDVWKWebViewEngine"/>
</feature>
Expand All @@ -80,42 +79,6 @@
<header-file src="src/ios/IONAssetHandler.h"/>
<source-file src="src/ios/IONAssetHandler.m"/>
<asset src="src/ios/wk-plugin.js" target="wk-plugin.js"/>

<!--GCDWebServer headers-->
<header-file src="src/ios/GCDWebServer/Core/GCDWebServer.h"/>
<header-file src="src/ios/GCDWebServer/Core/GCDWebServerConnection.h"/>
<header-file src="src/ios/GCDWebServer/Core/GCDWebServerFunctions.h"/>
<header-file src="src/ios/GCDWebServer/Core/GCDWebServerHTTPStatusCodes.h"/>
<header-file src="src/ios/GCDWebServer/Core/GCDWebServerPrivate.h"/>
<header-file src="src/ios/GCDWebServer/Core/GCDWebServerRequest.h"/>
<header-file src="src/ios/GCDWebServer/Core/GCDWebServerResponse.h"/>
<header-file src="src/ios/GCDWebServer/Requests/GCDWebServerDataRequest.h"/>
<header-file src="src/ios/GCDWebServer/Requests/GCDWebServerFileRequest.h"/>
<header-file src="src/ios/GCDWebServer/Requests/GCDWebServerMultiPartFormRequest.h"/>
<header-file src="src/ios/GCDWebServer/Requests/GCDWebServerURLEncodedFormRequest.h"/>
<header-file src="src/ios/GCDWebServer/Responses/GCDWebServerDataResponse.h"/>
<header-file src="src/ios/GCDWebServer/Responses/GCDWebServerErrorResponse.h"/>
<header-file src="src/ios/GCDWebServer/Responses/GCDWebServerFileResponse.h"/>
<header-file src="src/ios/GCDWebServer/Responses/GCDWebServerStreamedResponse.h"/>

<!--GCDWebServer source-->
<source-file src="src/ios/GCDWebServer/Core/GCDWebServer.m"/>
<source-file src="src/ios/GCDWebServer/Core/GCDWebServerConnection.m"/>
<source-file src="src/ios/GCDWebServer/Core/GCDWebServerFunctions.m"/>
<source-file src="src/ios/GCDWebServer/Core/GCDWebServerRequest.m"/>
<source-file src="src/ios/GCDWebServer/Core/GCDWebServerResponse.m"/>
<source-file src="src/ios/GCDWebServer/Requests/GCDWebServerDataRequest.m"/>
<source-file src="src/ios/GCDWebServer/Requests/GCDWebServerFileRequest.m"/>
<source-file src="src/ios/GCDWebServer/Requests/GCDWebServerMultiPartFormRequest.m"/>
<source-file src="src/ios/GCDWebServer/Requests/GCDWebServerURLEncodedFormRequest.m"/>
<source-file src="src/ios/GCDWebServer/Responses/GCDWebServerDataResponse.m"/>
<source-file src="src/ios/GCDWebServer/Responses/GCDWebServerErrorResponse.m"/>
<source-file src="src/ios/GCDWebServer/Responses/GCDWebServerFileResponse.m"/>
<source-file src="src/ios/GCDWebServer/Responses/GCDWebServerStreamedResponse.m"/>

<!--GCDWebServer dependencies-->
<framework src="libz.tbd"/>

</platform>
<issue>https://github.com/ionic-team/cordova-plugin-ionic-webview/issues</issue>
<author>Ionic Team</author>
Expand Down
3 changes: 3 additions & 0 deletions src/ios/CDVWKWebViewEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
@property (nonatomic, strong, readonly) id <WKUIDelegate> uiDelegate;
@property (nonatomic, strong) NSString * basePath;

extern NSString * const IONIC_SCHEME;
extern NSString * const IONIC_FILE_SCHEME;

-(void)setServerPath:(NSString *) path;
-(void)setServerBasePath:(CDVInvokedUrlCommand*)command;
-(void)getServerBasePath:(CDVInvokedUrlCommand*)command;
Expand Down
Loading

0 comments on commit 0dee0cf

Please sign in to comment.