From 68bc200aa97edc0871454e005a95cd11d1c02ffe Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Mon, 7 Oct 2024 21:13:07 -0700 Subject: [PATCH] fix(objc): Workaround for Swift/ObjC template issues This uses "non-standard" Swift annotations, but they've been supported by the past few versions of Xcode and are in the process of being standardized. Most importantly, they work for what we need. Closes GH-1487. --- templates/project/App/AppDelegate.h | 13 +++++++------ templates/project/App/AppDelegate.swift | 7 +++---- templates/project/App/Bridging-Header.h | 5 +++++ templates/project/App/MainViewController.h | 13 +++++++------ templates/project/App/ViewController.swift | 6 ++++-- 5 files changed, 26 insertions(+), 18 deletions(-) diff --git a/templates/project/App/AppDelegate.h b/templates/project/App/AppDelegate.h index 99e6a3e5ec..62a77631fe 100644 --- a/templates/project/App/AppDelegate.h +++ b/templates/project/App/AppDelegate.h @@ -19,10 +19,11 @@ #import -#warning It is unsafe to rely on the AppDelegate class as an extension point. \ - Update your code to extend CDVAppDelegate instead -- \ - This code will stop working in Cordova iOS 9! +#ifndef __CORDOVA_SILENCE_HEADER_DEPRECATIONS + #warning It is unsafe to rely on the AppDelegate class as an extension point. \ + Update your code to extend CDVAppDelegate instead -- \ + This code will stop working in Cordova iOS 9! +#endif -@class AppDelegate; - -#import "App-Swift.h" +@interface AppDelegate : CDVAppDelegate +@end diff --git a/templates/project/App/AppDelegate.swift b/templates/project/App/AppDelegate.swift index aa50cfe95f..e6ef28ff13 100644 --- a/templates/project/App/AppDelegate.swift +++ b/templates/project/App/AppDelegate.swift @@ -18,12 +18,11 @@ */ import UIKit -import Cordova @main -@objc // Remove compat hack in Cordova iOS 9 -class AppDelegate: CDVAppDelegate { - override func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { +@_objcImplementation +extension AppDelegate { + open override func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) } } diff --git a/templates/project/App/Bridging-Header.h b/templates/project/App/Bridging-Header.h index 2644cdb122..9dec529553 100644 --- a/templates/project/App/Bridging-Header.h +++ b/templates/project/App/Bridging-Header.h @@ -18,3 +18,8 @@ */ #import + +#define __CORDOVA_SILENCE_HEADER_DEPRECATIONS +#import "AppDelegate.h" +#import "MainViewController.h" +#undef __CORDOVA_SILENCE_HEADER_DEPRECATIONS diff --git a/templates/project/App/MainViewController.h b/templates/project/App/MainViewController.h index 22c0cb26ce..ddb37c4a7b 100644 --- a/templates/project/App/MainViewController.h +++ b/templates/project/App/MainViewController.h @@ -19,10 +19,11 @@ #import -#warning It is unsafe to rely on the MainViewController class as an extension point. \ - Update your code to extend CDVViewController instead -- \ - This code will stop working in Cordova iOS 9! +#ifndef __CORDOVA_SILENCE_HEADER_DEPRECATIONS + #warning It is unsafe to rely on the MainViewController class as an extension point. \ + Update your code to extend CDVViewController instead -- \ + This code will stop working in Cordova iOS 9! +#endif -@class MainViewController; - -#import "App-Swift.h" +@interface MainViewController : CDVViewController +@end diff --git a/templates/project/App/ViewController.swift b/templates/project/App/ViewController.swift index f72f1f3e05..8783703210 100644 --- a/templates/project/App/ViewController.swift +++ b/templates/project/App/ViewController.swift @@ -19,7 +19,9 @@ import Cordova -@objc(MainViewController) // Remove compat hack in Cordova iOS 9 -class ViewController: CDVViewController { +@_objcImplementation +extension MainViewController { } +class ViewController: MainViewController { +}