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

iOS codeSync rollback after relaunch app #611

Open
mOOnIrsama opened this issue Apr 23, 2020 · 31 comments
Open

iOS codeSync rollback after relaunch app #611

mOOnIrsama opened this issue Apr 23, 2020 · 31 comments

Comments

@mOOnIrsama
Copy link

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.
@amjadyahya1
Copy link

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

@szh
Copy link

szh commented Jul 23, 2020

I'm having this issue on iOS only. I'm using cordova-ios 6.10 (with the code from PR #513 for compatibility).
I'm also using WKWebView, and the error occurs both on the simulator and on test devices.

@szh
Copy link

szh commented Jul 27, 2020

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.

@ermik
Copy link
Contributor

ermik commented Jul 27, 2020

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.

@szh
Copy link

szh commented Jul 27, 2020

@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
Copy link

szh commented Jul 28, 2020

Still happens with v1.13.0, see #624

@szh
Copy link

szh commented Jul 28, 2020

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.

@ludufre
Copy link

ludufre commented Jul 28, 2020

@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.

@szh
Copy link

szh commented Jul 28, 2020

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

@szh
Copy link

szh commented Jul 28, 2020

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:
szh@41e1a79

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.

@ludufre
Copy link

ludufre commented Jul 28, 2020

@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

@szh
Copy link

szh commented Jul 28, 2020

@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.

@sithwarrior
Copy link

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

@szh
Copy link

szh commented Jul 29, 2020

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

Yes

@sithwarrior
Copy link

sithwarrior commented Aug 10, 2020

Any chance of getting this reviewed/merged in?

@geekz-reno
Copy link

Any chance of getting this reviewed/merged in?

Need this updated version to, thank you,

@alexandergoncharov-zz
Copy link
Contributor

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.

@bugragenc
Copy link

@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

@Krasavinigor
Copy link
Contributor

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?

@alexandergoncharov-zz
Copy link
Contributor

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?

@daisito
Copy link

daisito commented Aug 30, 2020

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)

@Krasavinigor
Copy link
Contributor

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.

@adancarrasco
Copy link

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

@ludufre
Copy link

ludufre commented Oct 22, 2020

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

@ankitjainOfficial
Copy link

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

@sithwarrior
Copy link

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

@ankitjainOfficial
Copy link

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

@runlong-yao
Copy link

@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

@veneliniliev
Copy link

does anyone have a solution?

@ankitjainOfficial
Copy link

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

@veneliniliev
Copy link

i found a solution in my case.
when i use cordova-plugin-ionic-webview and set <preference name="iosScheme" value="app" /> for example,
broke loading of updated version data. (reload and stay in white page with response status from app 404)

when remove preference, everything works fine!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.