cordova-plugin-code-push icon indicating copy to clipboard operation
cordova-plugin-code-push copied to clipboard

iOS codeSync rollback after relaunch app

Open mOOnIrsama opened this issue 4 years ago • 31 comments

in iOS Simulator the app is updated and after its auto restarted, all of the cordova plugins no longer works and whenever I relaunch the apps rollbacked to previous version. Below is the logs and my project details

Project: plain cordova code-push: 1.12.2 iOS: 13.4.1 WebVIew: WKWebView

Javascript:

  initialize: function () {
    document.addEventListener("resume", function () {
        codePush.sync();
    });
  },
  onDeviceReady: function () {
    codePush.sync();
  }

app.initialize();

Config: <preference name="WKWebViewOnly" value="true" />

Logs:

2020-04-24 06:23:26.371705+0800 Evenz Merchant[70524:6036478] Received Event: deviceready
2020-04-24 06:23:26.691340+0800 Evenz Merchant[70524:6036478] [CodePush] Checking for update.
2020-04-24 06:23:27.876676+0800 Evenz Merchant[70524:6036478] [CodePush] Reported status: {"status":0,"appVersion":"1.0.0","deploymentKey":"ZVGoZRrJGHxpWpTQxGUsVIbiHfJ8ZFpGaxgl9","previousLabelOrAppVersion":null,"previousDeploymentKey":null}
2020-04-24 06:23:27.964797+0800 Evenz Merchant[70524:6036478] [CodePush] An update is available. {"appVersion":"1.0.0","deploymentKey":"ZVGoZRrJGHxpWpTQxGUsVIbiHfJ8ZFpGaxgl9","downloadUrl":"https://codepushupdates.azureedge.net/storagev2/rpSibhMndLYFULAhu2Gfp87Wju2128cec040-63f4-456f-bae0-4a7a6477f7ea","isMandatory":true,"label":"v26","packageHash":"ef5af9e09ce75e7eddf3e2c35006116c24743cda96c63cb6a9cd76f09498cc3c","packageSize":7129798,"failedInstall":false}
2020-04-24 06:23:27.965389+0800 Evenz Merchant[70524:6036478] [CodePush] Downloading update
2020-04-24 06:23:27.965842+0800 Evenz Merchant[70524:6036478] -[CDVFileTransfer download:] [Line 423] File Transfer downloading file...
2020-04-24 06:23:28.793431+0800 Evenz Merchant[70524:6036599] -[CDVFileTransferDelegate connection:didReceiveResponse:] [Line 771] Streaming to file /Users/munirishak/Library/Developer/CoreSimulator/Devices/D40EC6F8-DB3B-4B83-A550-7BA920535492/data/Containers/Data/Application/B39AA08A-0AD7-4544-9F22-6403A937B6CB/Library/NoCloud/codepush/download/update.zip
2020-04-24 06:23:33.707522+0800 Evenz Merchant[70524:6036596] File Transfer Finished with response code 200
2020-04-24 06:23:33.709184+0800 Evenz Merchant[70524:6036596] -[CDVFileTransferDelegate connectionDidFinishLoading:] [Line 637] File Transfer Download success
2020-04-24 06:23:33.714640+0800 Evenz Merchant[70524:6036478] [CodePush] Package download success: {"deploymentKey":"ZVGoZRrJGHxpWpTQxGUsVIbiHfJ8ZFpGaxgl9","label":"v26","appVersion":"1.0.0","isMandatory":true,"packageHash":"ef5af9e09ce75e7eddf3e2c35006116c24743cda96c63cb6a9cd76f09498cc3c","isFirstRun":false,"failedInstall":false,"localPath":"cdvfile://localhost/library-nosync/codepush/download/update.zip"}
2020-04-24 06:23:33.714825+0800 Evenz Merchant[70524:6036478] [CodePush] Installing update
2020-04-24 06:23:34.366113+0800 Evenz Merchant[70524:6036478] [CodePush] Applying full update
2020-04-24 06:23:34.391079+0800 Evenz Merchant[70524:6036478] [CodePush] Install succeeded.
=================================================================
Main Thread Checker: UI API called on a background thread: -[WKWebView loadFileURL:allowingReadAccessToURL:]
PID: 70524, TID: 6036596, Thread name: (none), Queue name: com.apple.root.default-qos, QoS: 0
Backtrace:
4   Evenz Merchant                      0x0000000109d063cc -[CDVWKWebViewEngine(CodePush) loadRequest:] + 1468
5   Evenz Merchant                      0x0000000109cff792 -[CodePush loadURL:] + 130
6   Evenz Merchant                      0x0000000109cff6be -[CodePush loadPackage:] + 110
7   Evenz Merchant                      0x0000000109cfd9f7 __20-[CodePush install:]_block_invoke + 551
8   libdispatch.dylib                   0x000000010a08ef11 _dispatch_call_block_and_release + 12
9   libdispatch.dylib                   0x000000010a08fe8e _dispatch_client_callout + 8
10  libdispatch.dylib                   0x000000010a0922d8 _dispatch_queue_override_invoke + 1022
11  libdispatch.dylib                   0x000000010a0a1399 _dispatch_root_queue_drain + 351
12  libdispatch.dylib                   0x000000010a0a1ca6 _dispatch_worker_thread2 + 135
13  libsystem_pthread.dylib             0x00007fff51b386b6 _pthread_wqthread + 220
14  libsystem_pthread.dylib             0x00007fff51b37827 start_wqthread + 15
2020-04-24 06:23:34.393163+0800 Evenz Merchant[70524:6036596] [reports] Main Thread Checker: UI API called on a background thread: -[WKWebView loadFileURL:allowingReadAccessToURL:]
PID: 70524, TID: 6036596, Thread name: (none), Queue name: com.apple.root.default-qos, QoS: 0
Backtrace:
4   Evenz Merchant                      0x0000000109d063cc -[CDVWKWebViewEngine(CodePush) loadRequest:] + 1468
5   Evenz Merchant                      0x0000000109cff792 -[CodePush loadURL:] + 130
6   Evenz Merchant                      0x0000000109cff6be -[CodePush loadPackage:] + 110
7   Evenz Merchant                      0x0000000109cfd9f7 __20-[CodePush install:]_block_invoke + 551
8   libdispatch.dylib                   0x000000010a08ef11 _dispatch_call_block_and_release + 12
9   libdispatch.dylib                   0x000000010a08fe8e _dispatch_client_callout + 8
10  libdispatch.dylib                   0x000000010a0922d8 _dispatch_queue_override_invoke + 1022
11  libdispatch.dylib                   0x000000010a0a1399 _dispatch_root_queue_drain + 351
12  libdispatch.dylib                   0x000000010a0a1ca6 _dispatch_worker_thread2 + 135
13  libsystem_pthread.dylib             0x00007fff51b386b6 _pthread_wqthread + 220
14  libsystem_pthread.dylib             0x00007fff51b37827 start_wqthread + 15
2020-04-24 06:23:34.438684+0800 Evenz Merchant[70524:6036478] IAB.close() called but it was already closed.

mOOnIrsama avatar Apr 23 '20 22:04 mOOnIrsama

This also happens on Android, is there any fix for this. Working environment is exactly the same as with @mOOnIrsama

amjadyahya1 avatar Jul 09 '20 07:07 amjadyahya1

I'm having this issue on iOS only. I'm using cordova-ios 6.10 (with the code from PR https://github.com/microsoft/cordova-plugin-code-push/pull/513 for compatibility). I'm also using WKWebView, and the error occurs both on the simulator and on test devices.

szh avatar Jul 23 '20 21:07 szh

I suspect this is related to WKWebView and this code: https://github.com/microsoft/cordova-plugin-code-push/blob/master/src/ios/CodePush.m#L409

@amjadyahya1 what is your stack trace on Android? I'm guessing it's a different issue.

szh avatar Jul 27 '20 15:07 szh

UIKit unsafe thread warning is unlikely to affect the success of CodePush installation. It does not halt code execution. Thread safety violations which would affect your app are implemented by Apple to immediately crash it.

ermik avatar Jul 27 '20 15:07 ermik

@ermik Thanks for the insight. I took a look at the JS console from Safari, connected to the simulator, and this is what I see. Maybe this will shed some more light on what's actually causing the issue.

app://localhost/Users/<username>/Library/Developer/CoreSimulator/Devices/<id>/data/Containers/Data/Application/<id>/Library/NoCloud/codepush/deploy/versions/<id>/www/index.html
Failed to load resource: the server responded with a status of 404 ()

Seems like it's still trying to load the new version from the file system url.

szh avatar Jul 27 '20 16:07 szh

Still happens with v1.13.0, see #624

szh avatar Jul 28 '20 14:07 szh

This project and issue are critical to my team, so I'm spending some time debugging even though I'm not very experienced with native iOS development or Objective-C. I'm chronicling my findings here in semi-real time in he hope that someone will have a helpful insight to speed this process along. So here goes:

loadPackage() in CodePush.m calls getStartPageURLForLocalPackage() which takes the url and adds 'file://' to the beginning (which doesn't work in WKWebView which doesn't use file:// urls). This is passed to loadUrl() which runs [self.webViewEngine loadRequest:[NSURLRequest requestWithURL:url]];.

There's also a file named 'CDVWKWebViewEngine+CodePush.m' and I'm not sure what it does. My guess is that it's supposed to extend the 'CDVWKWebViewEngine' class from the wkwebview-engine plugin that was used before cordova-ios v6. Now that plugin is no longer used - see https://cordova.apache.org/howto/2020/07/18/uiwebview-warning.html:

The official Apache WKWebView plugin is no longer needed with these cordova-ios versions since WKWebView has been integrated and UIWebView is removed.

So it seems like CDVWKWebViewEngine+CodePush.m just isn't loaded becuase of #if __has_include("CDVWKWebViewEngine.h") and therefore there's nothing to catch file:// urls and convert them to the app://localhost scheme that WKWebView needs.

szh avatar Jul 28 '20 17:07 szh

@szh This plugin is critical to my project too. I'm using with [email protected] without issues. I define the Keys via TypeScript side (not config.xml). And I don't use <preference name="WKWebViewOnly" value="true" /> and have no warnings when submitting do Itunes Connect.

Create a simple test project just to see if the problem happens. It could be something in your project.

ludufre avatar Jul 28 '20 17:07 ludufre

@ludufre Do you also use cordova-plugin-wkwebview-engine?

szh avatar Jul 28 '20 18:07 szh

Continuing my debugging... Using my previous findings, I moved some code from 'CDVWKWebViewEngine+CodePush.m' to 'CodePush.m' and that fixed the issue immediately after install. Here's my commit: https://github.com/szh/cordova-plugin-code-push/commit/41e1a79c3b58f39388b672e480aa06adf874de19

However after closing the app and reopening it doesn't load. I assume it's still trying to load from a file:// url but I'm not sure where that code is.

szh avatar Jul 28 '20 18:07 szh

@szh No. I use cordova-plugin-ionic-webview because Ionic. If you are using cordova-ios@6 you don't need this plugin anymore. See: https://cordova.apache.org/announcements/2020/06/01/cordova-ios-release-6.0.0.html

ludufre avatar Jul 28 '20 18:07 ludufre

@ludufre Right, I'm not (look again at my earlier comment), just checking whether you were. There is code in this plugin to deal with ionic's webview differently which may be why you're not having this issue.

szh avatar Jul 28 '20 19:07 szh

@szh So everything is now working in your new PR?

sithwarrior avatar Jul 29 '20 07:07 sithwarrior

@szh So everything is now working in your new PR?

Yes

szh avatar Jul 29 '20 08:07 szh

Any chance of getting this reviewed/merged in?

sithwarrior avatar Aug 10 '20 07:08 sithwarrior

Any chance of getting this reviewed/merged in?

Need this updated version to, thank you,

geekz-reno avatar Aug 11 '20 00:08 geekz-reno

Hi all, Thanks for reporting and sorry for the delay!

Unfortunately, I can't reproduce this compatibility issue. Could you please provide some demo app with reproducing issue and reprosteps? I used the latest versions of Cordova and cordova-ios in my test app.

alexandergoncharov-zz avatar Aug 21 '20 13:08 alexandergoncharov-zz

@szh No. I use cordova-plugin-ionic-webview because Ionic. If you are using cordova-ios@6 you don't need this plugin anymore. See: https://cordova.apache.org/announcements/2020/06/01/cordova-ios-release-6.0.0.html

this is the right solution! thank you

bugragenc avatar Aug 22 '20 15:08 bugragenc

Hi there! We opened PR for fixing the issue with CDVUserAgentUtil: #642 Take a look if you have time. @szh, Could you please let me know if it was helpful for you?

Krasavinigor avatar Aug 25 '20 13:08 Krasavinigor

Hi all, We merged this PR https://github.com/microsoft/cordova-plugin-code-push/pull/642 and published new 1.13.1 version. Could you please test it and let us know if it fixed your issue?

alexandergoncharov-zz avatar Aug 28 '20 14:08 alexandergoncharov-zz

Hi all, We merged this PR #642 and published new 1.13.1 version. Could you please test it and let us know if it fixed your issue?

not working

The following build commands failed: CompileC /Users/user/Library/Developer/Xcode/DerivedData/Sendify_Conductor-acautfakroysqpdhgitjezmjczop/Build/Intermediates.noindex/Sendify\ Conductor.build/Debug-iphonesimulator/Sendify\ Conductor.build/Objects-normal/x86_64/CDVWKWebViewEngine+CodePush.o /Users/user/Downloads/ionic5/sendifydelivery/platforms/ios/Sendify\ Conductor/Plugins/cordova-plugin-code-push/CDVWKWebViewEngine+CodePush.m normal x86_64 objective-c com.apple.compilers.llvm.clang.1_0.compiler (1 failure) xcodebuild: Command failed with exit code 65

Ionic:

Ionic CLI : 6.10.1 (/usr/local/lib/node_modules/@ionic/cli) Ionic Framework : @ionic/angular 5.2.1 @angular-devkit/build-angular : 0.803.27 @angular-devkit/schematics : 8.3.27 @angular/cli : 8.3.27 @ionic/angular-toolkit : 2.2.0

Cordova:

Cordova CLI : 9.0.0 ([email protected]) Cordova Platforms : android 9.0.0, ios 6.1.0 Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 5.0.0, (and 25 other plugins)

daisito avatar Aug 30 '20 00:08 daisito

Hi all,

If you still have issues could you please provide some demo app with reproducing issue and reprosteps? Unfortunately, we can't reproduce any issues with it.

Krasavinigor avatar Aug 31 '20 07:08 Krasavinigor

Has anyone found the solution? Still happening in latest version: 2.0.0

adancarrasco avatar Oct 22 '20 23:10 adancarrasco

@adancarrasco , I think you should make some demo repo...

ludufre avatar Oct 22 '20 23:10 ludufre

Has anybody found the solution to this? I'm on the latest version (2.0.0) and I have no clue, where to start debugging.

   Cordova CLI       : 10.0.0
   Cordova Platforms : android 9.0.0, ios 6.1.1

ankitjainOfficial avatar Dec 14 '20 19:12 ankitjainOfficial

@ankitjainOfficial do you have a demo app? It works fine for me..

sithwarrior avatar Dec 14 '20 19:12 sithwarrior

@sithwarrior Unfortunately, don't have a demo handy. Is there any hint, where I can start my debugging?

ankitjainOfficial avatar Dec 15 '20 06:12 ankitjainOfficial

@ankitjainOfficial What you need? I also face the bug in cordova project.

In my project Vue create demo cd demo/src-cordova cordova platform add ios cordova plugin add cordova-plugin-code-push@latest

...config code push and testing

finally, you'll find the bug

runlong-yao avatar Apr 29 '21 13:04 runlong-yao

does anyone have a solution?

veneliniliev avatar Jun 01 '21 16:06 veneliniliev

@veneliniliev Rolling back to 1.8 solved for me. with v2, no solution worked for me.

ankitjainOfficial avatar Jun 02 '21 05:06 ankitjainOfficial