ionic-team / ionic-team/cordova-plugin-ionic-webview

persistServerBasePath behaves differently on iOS / Android

Open
#288 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Objective-C
Stars
493
Forks
410
PR merge metrics
No merged PRs in 30d

Description

I'm using this plugin in conjunction with a hot code update so I download the code to a path on local storage, and then set the server base path to this new location. That part is working great, but I was having an issue with the app loading to the old version for a bit before the path gets set so I thought I'd fix that using `persistServerBasePath`. However, it seems to be broken for iOS (or I'm misunderstanding something).

**iOS**

Stores the result of `[self.basePath lastPathComponent]` which as just stores the last segment of the path.

For example, `/the/path/to/my/files` becomes `files`

https://github.com/ionic-team/cordova-plugin-ionic-webview/blob/3d1bcddc79f5f81d4e4610c550a687b7a4a867f5/src/ios/CDVWKWebViewEngine.m#L766

Additionally, `lastPathComponent` is called on the path AGAIN after it is recovered from storage here

https://github.com/ionic-team/cordova-plugin-ionic-webview/blob/3d1bcddc79f5f81d4e4610c550a687b7a4a867f5/src/ios/CDVWKWebViewEngine.m#L147

**Android**

Seems to store the path as it was set with no modification which is working great for my purposes

https://github.com/ionic-team/cordova-plugin-ionic-webview/blob/56f2032e488206b0097b827de6a71b39d11e05db/src/android/com/ionicframework/cordova/webview/IonicWebView.java#L33

**Useful log data from iOS**

What I called `persistServerBasePath` with:

```
/var/mobile/Containers/Data/Application/8C0C07CC-0FD3-4FD4-B7DF-90A88E123/Library/Application Support/com.myappname.redacted/cordova-hot-code-push-plugin/2019.01.29-21.34.53/www
```

What was persisted:

```
www
```

After I removed `lastPathComponent` from the persist code this is what was persisted / loaded in `getStartPath`:

```
/var/mobile/Containers/Data/Application/8C0C07CC-0FD3-4FD4-B7DF-90A88E123/Library/Application Support/com.myappname.redacted/cordova-hot-code-push-plugin/2019.01.29-21.34.53/www
```

Which is run through `[snapshots stringByAppendingPathComponent:[persistedPath lastPathComponent]]` resulting in this:

```
/var/mobile/Containers/Data/Application/8C0C07BE-0FD3-4FD4-B7DF-90A88E12B8C3/Library/NoCloud/ionic_built_snapshots/www
```

**Solution**

I'm not sure if this is intentional for some reason I don't understand, but for my use case it is causing problems. My only guess is this is meant for moving to a sub folder, but I need to go to an entirely different path. Also, android seems to allow this without issue, but iOS doesn't so at the very least this should have consistent behavior.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.