This is an automated email from the ASF dual-hosted git repository. dpogue pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/cordova-ios.git
The following commit(s) were added to refs/heads/master by this push: new 92df3b77 fix(compat): Set the app delegate viewController for plugins (#1493) 92df3b77 is described below commit 92df3b773c541eafaac640aa0b31bfde4790484a Author: Darryl Pogue <dar...@dpogue.ca> AuthorDate: Tue Oct 8 00:06:34 2024 -0700 fix(compat): Set the app delegate viewController for plugins (#1493) 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. --- CordovaLib/Classes/Public/CDVViewController.m | 12 ++++++++++++ CordovaLib/include/Cordova/CDVAppDelegate.h | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CordovaLib/Classes/Public/CDVViewController.m b/CordovaLib/Classes/Public/CDVViewController.m index af4944d4..8cf9f248 100644 --- a/CordovaLib/Classes/Public/CDVViewController.m +++ b/CordovaLib/Classes/Public/CDVViewController.m @@ -22,6 +22,7 @@ #import <WebKit/WebKit.h> #import <objc/message.h> +#import <Cordova/CDVAppDelegate.h> #import <Cordova/CDVPlugin.h> #import "CDVPlugin+Private.h" #import <Cordova/CDVConfigParser.h> @@ -295,6 +296,17 @@ static UIColor* defaultBackgroundColor(void) { { [super viewDidLoad]; + // TODO: Remove in Cordova iOS 9 + if ([UIApplication.sharedApplication.delegate isKindOfClass:[CDVAppDelegate class]]) { + CDVAppDelegate *appDelegate = (CDVAppDelegate *)UIApplication.sharedApplication.delegate; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + if (appDelegate.viewController == nil) { + appDelegate.viewController = self; + } +#pragma clang diagnostic pop + } + // Load settings [self loadSettings]; diff --git a/CordovaLib/include/Cordova/CDVAppDelegate.h b/CordovaLib/include/Cordova/CDVAppDelegate.h index 6b267043..162b9379 100644 --- a/CordovaLib/include/Cordova/CDVAppDelegate.h +++ b/CordovaLib/include/Cordova/CDVAppDelegate.h @@ -41,7 +41,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nullable, nonatomic, strong) IBOutlet UIWindow *window API_DEPRECATED_WITH_REPLACEMENT("SceneDelegate:window", ios(2.0, 13.0)); // TODO: Remove in Cordova iOS 9 -@property (nullable, nonatomic, strong) IBOutlet CDVViewController *viewController CDV_DEPRECATED(8, "This will always be nil."); +@property (nullable, nonatomic, strong) IBOutlet CDVViewController *viewController CDV_DEPRECATED(8, ""); @end --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cordova.apache.org For additional commands, e-mail: commits-h...@cordova.apache.org