diff --git a/addons/ofxiOS/src/app/ofAppiOSWindow.mm b/addons/ofxiOS/src/app/ofAppiOSWindow.mm index 53a3856e6d4..698e7960863 100644 --- a/addons/ofxiOS/src/app/ofAppiOSWindow.mm +++ b/addons/ofxiOS/src/app/ofAppiOSWindow.mm @@ -46,6 +46,69 @@ #include "ofxiOSGLKView.h" #include "ofxiOSEAGLView.h" +@interface ofxiOSSceneDelegate : UIResponder +@property (strong, nonatomic) UIWindow * window; +@end + +@implementation ofxiOSSceneDelegate + +- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions { + if (![scene isKindOfClass:[UIWindowScene class]]) return; + id appDelegate = [UIApplication sharedApplication].delegate; + if ([appDelegate respondsToSelector:@selector(window)]) { + self.window = appDelegate.window; + } + if (self.window) { + self.window.windowScene = (UIWindowScene *)scene; + [self.window makeKeyAndVisible]; + } + [self scene:scene openURLContexts:connectionOptions.URLContexts]; +} + +- (void)sceneDidBecomeActive:(UIScene *)scene { + [self forward:@selector(applicationDidBecomeActive:)]; +} + +- (void)sceneWillResignActive:(UIScene *)scene { + [self forward:@selector(applicationWillResignActive:)]; +} + +- (void)sceneWillEnterForeground:(UIScene *)scene { + [self forward:@selector(applicationWillEnterForeground:)]; +} + +- (void)sceneDidEnterBackground:(UIScene *)scene { + [self forward:@selector(applicationDidEnterBackground:)]; +} + +- (void)scene:(UIScene *)scene openURLContexts:(NSSet *)URLContexts { + id appDelegate = [UIApplication sharedApplication].delegate; + for (UIOpenURLContext * context in URLContexts) { + if ([appDelegate respondsToSelector:@selector(application:openURL:options:)]) { + [appDelegate application:[UIApplication sharedApplication] openURL:context.URL options:@{}]; + } + else if ([appDelegate respondsToSelector:@selector(application:handleOpenURL:)]) { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + [appDelegate application:[UIApplication sharedApplication] handleOpenURL:context.URL]; +#pragma clang diagnostic pop + } + } +} + +// calls the app delegate's application...: method for a scene event +- (void)forward:(SEL)selector { + id appDelegate = [UIApplication sharedApplication].delegate; + if ([appDelegate respondsToSelector:selector]) { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Warc-performSelector-leaks" + [appDelegate performSelector:selector withObject:[UIApplication sharedApplication]]; +#pragma clang diagnostic pop + } +} + +@end + //----------------------------------------------------------------------------------- instance. static ofAppiOSWindow * _instance = NULL; ofAppiOSWindow * ofAppiOSWindow::getInstance() { diff --git a/scripts/templates/ios/ofxiOS-Info.plist b/scripts/templates/ios/ofxiOS-Info.plist index 0c6c10119a2..5575d673b22 100644 --- a/scripts/templates/ios/ofxiOS-Info.plist +++ b/scripts/templates/ios/ofxiOS-Info.plist @@ -45,5 +45,22 @@ UIViewControllerBasedStatusBarAppearance + UIApplicationSceneManifest + + UIApplicationSupportsMultipleScenes + + UISceneConfigurations + + UIWindowSceneSessionRoleApplication + + + UISceneConfigurationName + Default + UISceneDelegateClassName + ofxiOSSceneDelegate + + + + diff --git a/scripts/templates/tvOS/ofxtvOS-Info.plist b/scripts/templates/tvOS/ofxtvOS-Info.plist index 4aa5d31f9ca..69b3a79e592 100644 --- a/scripts/templates/tvOS/ofxtvOS-Info.plist +++ b/scripts/templates/tvOS/ofxtvOS-Info.plist @@ -26,5 +26,22 @@ arm64 + UIApplicationSceneManifest + + UIApplicationSupportsMultipleScenes + + UISceneConfigurations + + UIWindowSceneSessionRoleApplication + + + UISceneConfigurationName + Default + UISceneDelegateClassName + ofxiOSSceneDelegate + + + +