-
Notifications
You must be signed in to change notification settings - Fork 340
Fixed issue for iOS when package folder was not cleared properly #211
Conversation
…pdating app version This changes should fix #207. Tried to use more robust solution for determining correct build time for the app, Also add logic to also verify if the app version was changed before clearing deployments. Also moved repeated code for getting the app version to utility function.
|
Hi @max-mironov, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!
TTYL, MSBOT; |
|
Hi @max-mironov, Please fix 3 calls from: [Utilities getAppVersion] to [Utilities getApplicationVersion] |
|
@tatatananana, thank you so much for pointing at this, changes are committed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @max-mironov, the fix for getting the application build time looks good, but are you sure we need to add the app version check here? I may have misunderstood completely, but I'm confused about two things:
- Assuming that the native timestamps are now correct, the logic before this PR was made should be correct. We are checking the updates we have on disk, and comparing the binary timestamp of the client when the package was downloaded to the binary timestamp of the client now. In other words, we're checking to see if the binary has been overwritten since we installed this package. If it has been overwritten, then we don't want this package, because the javascript that got deployed with the binary is probably newer. Note that, if the binary has not been updated, there is no possible way for the app version to mismatch (the package would not be installed in the first place).
- I don't think checking the app version is robust here. Firstly, the app version can be the same even if the binary has been updated (the dev is testing new builds being published to the simulator without updating the app version for now). Secondly, the app version can be different even if the binary has not been updated. This is because the version on the downloaded update can be a range, e.g.
>= 1.0.0, whereas the version on the binary is always a fixed semver, e.g.1.0.0.
Does this make sense, or have I misunderstood something? Also, are the native timestamps coming through correctly?
src/ios/Utilities.m
Outdated
| NSString *appPath = [[NSBundle mainBundle] bundlePath]; | ||
| NSDictionary *executableAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:appPath error:nil]; | ||
| return [executableAttributes objectForKey:@"NSFileModificationDate"]; | ||
| + (NSDate*)getApplicationBuildTime{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible that this change fixed the problem, without the need for the appVersion check in CodePush.m?
|
@Silhouettes I agree that it looks reasonable because in this way we will have some inconsistency in implementation this logic for iOS and Android (because we do not check for app version change on Android). Check for appVersion is needed because the timestamp will not be updated unless we have some changes in native code, so if we bump app version in plist and rebuild than the timestamp won't be updated. I imagine this can be a problem because this way the app will not clear old deployments. So you said that
I've double checked and it looks like app version is written to metadata here: https://github.com/Microsoft/cordova-plugin-code-push/blob/master/www/localPackage.ts#L177 (writeNewPackageMetadata function) and is acquired from native side by calling the same getAppVersion method so the app version couldn't be a range and check for appVersion will always make sense. Please correct me if I'm wrong. |
|
Thanks for the explanation @max-mironov, what you said makes sense. I'm sorry to be so nitpicky, but it seems like this fix doesn't fully cover the problem - if the dev makes a script-only change and deploys it to the simulator or device without bumping their app version, then it won't apply to them. Hopefully my understanding is correct here? It seems a bit much to ask people to bump their app version every time they make a script change to their app just so that they're able to test it. It seems to me that the real issue here is, as you said, https://github.com/Microsoft/react-native-code-push/blob/e42485243d9466fb6c00937bd9f67cee0d96de53/ios/CodePush/CodePush.m#L172 Or is there something being done differently there? This is not just for the sake of robustly addressing this issue, but also because it would be good to try and converge the behavior of the Cordova and React Native plugins as we will be attempting to unify the native codebase in the future. Alternatively, could we somehow copy the mechanism of the React Native Android plugin? https://github.com/Microsoft/react-native-code-push/pull/683/files Will that work? It may be that your current approach is the only way to address the issue, but I just want to make sure we exhaust other options first. |
|
(Updated the above comment) |
|
@Silhouettes thank you, I've got your point! We can add Cordova "after_plugin_install" hook for ios in config.xml and it will execute script that will modify pbxproj file and insert BuildPhase run script section to it. Please let me know what do you think about this solution? |
|
@max-mironov That's a good idea! Will that cause a re-compilation of the binary, and will it be a significant time cost? Also, would it work the same way if we just touched the binary after it's already been built? |
|
Okay, so I've been looking at this again, and I feel like there are two parts here that I didn't sort through clearly before:
Also, if the timestamp is not updating correctly here, it is likely also not updating correctly in the React Native plugin. Probably the reason we haven't seen any issues on that is because it is mostly masked by the app version check (to repro this, they'd have to be developing against a real device on 10.2 or up). So, once there is a solution for (2), it might be good to copy and paste the same fix there. |
|
Oh! I have another idea. I don't know whether or not it is better than your idea of touching native files, I'll leave it up to your judgement. What if we did all three of the following:
In other words, I think that the The only case where this will fail: If a dev deploys binary A to the simulator, and then update B is synced to the app. Then, without making any changes, they deploy binary A to the simulator again. When they boot the app, it will still be running binary B. I can't think of a way around this, unless we can actually get the timestamp of the JS bundle :( But maybe this is acceptable. |
…e it should be updated on each rebuild
|
@Silhouettes, ok finally tested the latest solution for getting correct build time by looking at NSModificationDate of plist file in main bundle. Verified it is working on iOS10.2.1 and iOS8.1 devices and is updated each time on native build and through cordova run ios deployment. Also tested this is working with TestFlight deployment. This should also cover the latest case you described above. |
richardhuaaa
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect :) Merging this for you seeing as you'll be out for a few days.
This changes should fix #207. Tried to use more robust solution for determining correct build time for the app, Also add logic to also verify if the app version was changed before clearing deployments. Also moved repeated code for getting the app version to utility function.