-
-
Save douglashill/1bd6ba60b50315455ed2b2381bc355dc to your computer and use it in GitHub Desktop.
// A minimal iOS app set up entirely in code using Objective-C rather than using a storyboard and UIApplicationSceneManifest in the Info.plist. | |
// Last updated for iOS 18. | |
// Swift version: https://gist.github.com/douglashill/b8125f7e2336b6a47461df0d4898f64d | |
@import UIKit; | |
@interface SceneDelegate : UIResponder <UIWindowSceneDelegate> | |
@end | |
@implementation SceneDelegate | |
@synthesize window = _window; | |
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions { | |
self.window = [[UIWindow alloc] initWithWindowScene:(UIWindowScene *)scene]; | |
self.window.rootViewController = [[UIViewController alloc] init]; | |
[self.window makeKeyAndVisible]; | |
} | |
@end | |
@interface AppDelegate: UIResponder <UIApplicationDelegate> | |
@end | |
@implementation AppDelegate | |
- (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options { | |
UISceneConfiguration *configuration = [[UISceneConfiguration alloc] initWithName:nil sessionRole:connectingSceneSession.role]; | |
configuration.delegateClass = SceneDelegate.class; | |
return configuration; | |
} | |
@end | |
int main(int argc, char * argv[]) { | |
return UIApplicationMain(argc, argv, nil, NSStringFromClass(AppDelegate.class)); | |
} |
I haven’t tried this.
👋 Got it working. It seems you need to assign any window reference to its own property for it to show up in the view hierarchy.
Thanks
works for me. except view controller views are all disabled. this problem ONLY occurs on iOS 13.
how were you able to enable the view control views ? , I am new to IOS development and i have been struggling to get the view controller views enabled :(
Good sample I would just change:
self.window.rootViewController = [[UIViewController alloc] init];
to:
self.window.rootViewController = [[NameOfYourViewController alloc]init];
Also don't forget to import #import "NameOfYourViewController.h"
Thanks for the sample.
With iOS17.5 I receive this warning:
BUG IN CLIENT OF UIKIT: Attempting to define a mismatched UISceneSessionRole! This will be an assert in future UIKit releases! Assigning a UISceneConfiguration with role "UISceneSessionRoleNone" for a UISceneSession with role "UIWindowSceneSessionRoleApplication".
UISceneConfiguration should be created like:
UISceneConfiguration *configuration = [[UISceneConfiguration alloc] initWithName:NULL sessionRole:UIWindowSceneSessionRoleApplication];
Thanks @OLFDB. Updated to use the role of the connectingSceneSession
parameter.
Hey @douglashill 👋
Thanks for this code sample.
Do you know if it's possible to add more that one
UIWindow
to a scene at this point, so that you'd have twoUIWindow
objects in the view hierarchy?I've been trying to get this working but to no avail.
Thanks!