apache / cordova-ios

Apache Cordova iOS
https://cordova.apache.org/
Apache License 2.0
2.16k stars 986 forks source link

fix(compat): Set the app delegate viewController for plugins #1493

Closed dpogue closed 1 month ago

dpogue commented 1 month ago

Platforms affected

iOS

Motivation and Context

Some plugins expect to be able to access the applications's CDVViewController via the AppDelegate. While previously we guaranteed that the viewController property was set to a non-nil CDVViewController, there was never any guarantee that it was set to the CDVViewController that is actually displaying the app (particularly in cases such as apps using CordovaLib only for a few pages as part of a larger app).

We've attempted to deprecate the property here, but some plugins still rely on the assumption that it will be non-nil, so we are trying to maintain compatibility in the common case here by assigning to it when a CDVViewController is loaded. This means there are still times in the app lifecycle where the viewController property is nil, but the deprecation warning will hopefully spur plugin developers to move away from that pattern.

[!NOTE] CDVPlugin always has a non-nil viewController property of its own, which is set to the CDVViewController instance the plugin was loaded into. This is almost always the better choice for plugins to use.

Testing

Existing unit tests pass.

Checklist

codecov-commenter commented 1 month ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 81.56%. Comparing base (98a3bcd) to head (1ca5bcb).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #1493 +/- ## ======================================= Coverage 81.56% 81.56% ======================================= Files 16 16 Lines 1888 1888 ======================================= Hits 1540 1540 Misses 348 348 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.