Skip to content
This repository has been archived by the owner on Oct 1, 2018. It is now read-only.

Updates do not auto-install: loadURL does not work correctly with cordova-plugin-wkwebview-engine #140

Closed
gareth-ferneyhough opened this issue Apr 25, 2016 · 19 comments
Labels

Comments

@gareth-ferneyhough
Copy link

gareth-ferneyhough commented Apr 25, 2016

Love the plugin. However, it seems that loadURL in HCPPlugin.m does not reload the page when I have the cordova-plugin-wkwebview-engine plugin installed. I do not get any errors after installation, but I must restart the app before I see any changes to index.html.

If I remove cordova-plugin-wkwebview-engine and rely on UIWebView, everything works as expected and the page is refreshed after chcp update installation.

This is occurring during the local development workflow.
My versions:

  • cordova-hot-code-push-local-dev-addon 0.1.2
  • cordova-hot-code-push-plugin 1.3.1
  • cordova-plugin-wkwebview-engine 1.0.3
  • ios platform 4.0.1
@nikDemyankov
Copy link
Member

Tried your setup with different emulators and on real device - works fine. Can you provide step-by-step guide on how to reproduce it?

This is how I did it:

  1. Create and app and add plugins:

    cordova create TestApp
    cd ./TestApp
    cordova platform add [email protected]
    cordova plugin add [email protected]
    cordova plugin add [email protected]
    cordova plugin add [email protected]
    
  2. In the ./TestApp directory run local server:

    cordova-hcp server
    
  3. Run the app:

    cordova run ios
    
  4. Change something in the TestApp/www/index.html and wait for development plugin to capture them. Page reloads.

@gareth-ferneyhough
Copy link
Author

Thanks for your help. I have some interesting results.

  1. After deploying TestApp to an IPad Air 2 using cordova run ios, the page still did not reload after installing the chcp update. However it did work in the emulator and the page reloaded fine.
  2. Next, I realized that if I deploy TestApp to an iPad from inside XCode, everything works and the page is reloaded after installing the chcp update. This is true when I have cordova-plugin-wkwebview-engine installed, as well as without it installed.
  3. I confirmed that TestApp deployed via cordova run ios does not reload, but only if cordova-plugin-wkwebview-engine is installed.

In summary, there may be an issue with my version of ios-deploy (1.8.6). Interesting that I am only affected when I try to use WKWebView. What version are you using?

For now I can continue to deploy manually from XCode.

@nikDemyankov
Copy link
Member

Thank you for investigation.

After deploying TestApp to an IPad Air 2 using cordova run ios, the page still did not reload after installing the chcp update.

Next, I realized that if I deploy TestApp to an iPad from inside XCode, everything works and the page is reloaded after installing the chcp update.

Probably that's why I missed it: I was running app on the device from Xcode, not console. I use cordova run to test on emulators, for devices I usually use Xcode directly. Really weird behaviour. Not sure, that much can be done here, but will see...

Currently I'm using ios-deploy of version 1.8.6, so now should be able to reproduce it.

@eneskaya
Copy link

I have this problem, too. And for me it did not work building it with XCode

[Log] Update is loaded (main.js, line 1676)
[Log] chcp_updateIsReadyToInstall (main.js, line 1651)
[Log] Update installed! (main.js, line 1659)
[Error] file:///var/mobile/Containers/Data/Application/527289D8-4166-4FC2-959F-5DDA6453CEBF/Library/Application%20Support/de.example.app/cordova-hot-code-push-plugin/2016.06.17-14.29.20/www//index.html
[Error] Failed to load resource (index.html, line 0)

It's with the WKWebview plugin installed (cordova-plugin-wkwebview-engine). What's wrong there?

@nikDemyankov
Copy link
Member

@eneskaya tried to reproduce it and couldn't . Again, can you give me a step-by-step on how to get the same error?

@eneskaya
Copy link

It's hard to give you a step by step reproduction, it's just that I installed the plugin and used it 😄 Of course with WKWebView installed

@nikDemyankov
Copy link
Member

@eneskaya I do love bugs that I can't reproduce :) Okey, let's try another approach.

  1. Create new project. My guess is that you are using Ionic.

    ionic start Test blank
    cd Test
    ionic platform add ios
    ionic plugin add cordova-hot-code-push-plugin
    ionic plugin add cordova-hot-code-push-local-dev-addon
    cordova-hcp server
    ionic emulate ios
    
  2. Open Test/www/index.html and change something in it. Check, that this results in app update.

If not - go to Test/platforms/ios/ and open .xcodeproj file in Xcode. In it go to Test -> Build Settings and search for WK_WEBVIEW_ENGINE_IS_USED. It should be there and set to 1. If it's not - then try to add it manually to Preprocessor Macros and run the app again from Xcode. If it is set to 1 - then go to CDVWKWebViewEngine+HCPPlugin_ReadAccessURL.m and set a breakpoint on line 19. Launch the app again from Xcode and see if it's hits the breakpoint. It should.

@eneskaya
Copy link

eneskaya commented Jun 21, 2016

Alright, I will check it and report back :) thanks so far

Edit: I don't know if this is relevant, but I'm using an nginx server to serve the new files and the cordova-hot-code-push-local-dev-addon is not installed

@alexbuijs
Copy link
Contributor

I also have this issue with

  • cordova-ios 4.1.1
  • cordova-plugin-wkwebview-engine 1.0.3
  • cordova-hot-code-push-plugin 1.4.0
  • cordova-hot-code-push-local-dev-addon 0.2.2

My steps to reproduce:

  • run chcp server
  • run the app with above plugins on device using cordova cli (cordova run ios --device)
  • wait until app is running
  • trigger reload by changing file in www directory

The result:

  • Failed to load resource file:///var/mobile/Containers/Data/Application/4DA367F6-1DB9-45D8-88C5-A16FC38306C9/Library/Application%20Support/app.id/cordova-hot-code-push-plugin/2016.06.21-17.09.06/www//index.html

It looks like #85 still isn't resolved for this scenario...

@eneskaya
Copy link

Mache WKWebView can't handle the double slashes? It's like ...www//index.html but rather should be www/index.html

Am 21.06.2016 um 17:12 schrieb Alex Buijs [email protected]:

I also have this issue with

cordova-ios 4.1.1
cordova-plugin-wkwebview-engine 1.0.3
cordova-hot-code-push-plugin 1.4.0
cordova-hot-code-push-local-dev-addon 0.2.2
My steps to reproduce:

run chcp server
run the app with above plugins on device using cordova cli (cordova run ios --device)
wait until app is running
trigger reload by changing file in www directory
The result:

Failed to load resource file:///var/mobile/Containers/Data/Application/4DA367F6-1DB9-45D8-88C5-A16FC38306C9/Library/Application%20Support/app.id/cordova-hot-code-push-plugin/2016.06.21-17.09.06/www//index.html
It looks like #85 still isn't resolved for this scenario...


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

@nikDemyankov
Copy link
Member

@alexbuijs okey, will check it out, thanks.

@nikDemyankov
Copy link
Member

@eneskaya no, that should not be the problem: WKWebView should handle double slashes.

@eneskaya
Copy link

@nikDemyankov Just a guess. Debugging this problem seems really hard, what steps do you take? Would be interesting to know.

@gareth-ferneyhough
Copy link
Author

Just to reiterate, the update process works fine for me when I deploy to the device using Xcode. Is this the case with you as well @alexbuijs?

@nikDemyankov
Copy link
Member

Sorry, been swamped with my main work...

@eneskaya well, previously the problem with WKWebView was in it's security policy. Right now for each release plugin creates a separate folder. And when it is installed - plugin reloads webview to the index page in the new folder. And WKWebView restricts that: if you started to display content from folder A - you can't then move to folder B (unless it's a subfolder for A, of course). But you can point WKWebView to some root folder. So, the solution was to swizzle it's loadRequest method and set as a root folder some directory, that is above the index page and all future release folders. And it worked. But feels like not always, since the problem remains.

Also, since not everyone is using WKWebView - I added a JS hook that sets a preprocess macro WK_WEBVIEW_ENGINE_IS_USED. this hook is executed when you run cordova prepare/build/run. If it's defined and set to 1 - that swizzling hack should be working. If not - then webview behaves by default. So, another problem why this is not working can be that the hook is failing or not executed at all. That's why I asked you to check it in Xcode directly :)

@alexbuijs
Copy link
Contributor

@gareth-ferneyhough I checked, and it indeed works when I deploy through XCode instead of via Cordova CLI. In both instances the WK_WEBVIEW_ENGINE_IS_USED variable is set to 1, though.

@ben-x9
Copy link

ben-x9 commented Jul 17, 2016

I can confirm this. Just started using Cordova and this plugin today. IOS with wkwebview auto-updates without needing restarting the app when launched from XCode, but when launched via cordova run ios --device restarting the app is required to see changes.

@gareth-ferneyhough
Copy link
Author

I will try to take a look this week, probably by comparing the two app containers after they have been installed via XCode and iOSDeploy.

@nordnet-deprecation-bot
Copy link
Contributor

👋 Hi! Thank you for your interest in this repo.

😢 We are not using nordnet/cordova-hot-code-push anymore, and we lack the manpower and the experience needed to maintain it. We are aware of the inconveniece that this may cause you. Feel free to use it as is, or create your own fork.

🔒 This will now be closed & locked.

ℹ️ Please see #371 for more information.

@nordnet nordnet locked and limited conversation to collaborators Sep 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants