Skip to content

Commit

Permalink
fix(objc): Workaround for Swift/ObjC template issues (#1494)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dpogue authored Oct 8, 2024
1 parent 92df3b7 commit ecac294
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 18 deletions.
13 changes: 7 additions & 6 deletions templates/project/App/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@

#import <Cordova/CDVAppDelegate.h>

#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
7 changes: 3 additions & 4 deletions templates/project/App/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
5 changes: 5 additions & 0 deletions templates/project/App/Bridging-Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@
*/

#import <Cordova/Cordova.h>

#define __CORDOVA_SILENCE_HEADER_DEPRECATIONS
#import "AppDelegate.h"
#import "MainViewController.h"
#undef __CORDOVA_SILENCE_HEADER_DEPRECATIONS
13 changes: 7 additions & 6 deletions templates/project/App/MainViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@

#import <Cordova/CDVViewController.h>

#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
6 changes: 4 additions & 2 deletions templates/project/App/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

import Cordova

@objc(MainViewController) // Remove compat hack in Cordova iOS 9
class ViewController: CDVViewController {
@_objcImplementation
extension MainViewController {
}

class ViewController: MainViewController {
}

0 comments on commit ecac294

Please sign in to comment.