2929 *
3030 * ***********************************************************************/
3131
32- #include " ofxiOSAppDelegate.h"
32+ #import " ofxiOSAppDelegate.h"
3333
3434#if TARGET_OS_IOS || (TARGET_OS_IPHONE && !TARGET_OS_TV)
3535
36- #include " ofxiOSViewController.h"
37- #include " ofxiOSExternalDisplay.h"
36+ #import " ofxiOSViewController.h"
37+ #import " ofxiOSGLKViewController.h"
38+ #import " ofxiOSExternalDisplay.h"
3839#include " ofxiOSExtras.h"
3940#include " ofxiOSAlerts.h"
4041#include " ofxiOSEAGLView.h"
4546
4647@implementation ofxiOSAppDelegate
4748
48- @synthesize window;
49- @synthesize externalWindow;
5049@synthesize currentScreenIndex;
5150
52- @synthesize uiViewController;
53-
5451- (void )dealloc {
5552 self.window = nil ;
5653 self.externalWindow = nil ;
5754 self.uiViewController = nil ;
58- [super dealloc ];
5955}
6056
6157- (void )applicationDidFinishLaunching : (UIApplication *)application {
6258
63- self.window = [[[ UIWindow alloc ] initWithFrame: [[UIScreen mainScreen ] bounds ]] autorelease ];
59+ self.window = [[UIWindow alloc ] initWithFrame: [[UIScreen mainScreen ] bounds ]];
6460 [self .window makeKeyAndVisible ];
6561
6662 currentScreenIndex = 0 ;
@@ -145,11 +141,11 @@ - (void)applicationDidFinishLaunching:(UIApplication *)application {
145141 case METAL_KIT:
146142 NSLog (@" No MetalKit yet supported for openFrameworks: Falling back to GLKit" );
147143 case GL_KIT:
148- self.uiViewController = (UIViewController*)[[[ ofxiOSGLKViewController alloc ] initWithFrame: frame app: (ofxiOSApp *)ofGetAppPtr () sharegroup: nil ] autorelease ];
144+ self.uiViewController = (UIViewController *)[[ofxiOSGLKViewController alloc ] initWithFrame: frame app: (ofxiOSApp *)ofGetAppPtr () sharegroup: nil ];
149145 break ;
150146 case CORE_ANIMATION:
151147 default :
152- self.uiViewController = [[[ ofxiOSViewController alloc ] initWithFrame: frame app: (ofxiOSApp *)ofGetAppPtr () sharegroup: nil ] autorelease ];
148+ self.uiViewController = [[ofxiOSViewController alloc ] initWithFrame: frame app: (ofxiOSApp *)ofGetAppPtr () sharegroup: nil ];
153149 break ;
154150
155151 }
@@ -172,14 +168,22 @@ - (void)applicationDidFinishLaunching:(UIApplication *)application {
172168 }
173169
174170 if (!bDoesHWOrientation) {
175- if ([self .uiViewController respondsToSelector: @selector (rotateToInterfaceOrientation:animated: )]) {
176- [self .uiViewController rotateToInterfaceOrientation: UIInterfaceOrientationPortrait animated: false ];
177- }
171+ if ([self .uiViewController isKindOfClass: ofxiOSViewController.class ]) {
172+ ofxiOSViewController *controller = (ofxiOSViewController*)self.uiViewController ;
173+ [controller rotateToInterfaceOrientation: UIInterfaceOrientationPortrait animated: false ];
174+ } else if ([self .uiViewController isKindOfClass: ofxiOSGLKViewController.class ]) {
175+ ofxiOSGLKViewController *controller = (ofxiOSGLKViewController *)self.uiViewController ;
176+ [controller rotateToInterfaceOrientation: UIInterfaceOrientationPortrait animated: false ];
177+ }
178178 } else {
179179 [[UIApplication sharedApplication ] setStatusBarOrientation: interfaceOrientation animated: NO ];
180- if ([self .uiViewController respondsToSelector: @selector (rotateToInterfaceOrientation:animated: )]) {
181- [self .uiViewController rotateToInterfaceOrientation: interfaceOrientation animated: false ];
182- }
180+ if ([self .uiViewController isKindOfClass: ofxiOSViewController.class ]) {
181+ ofxiOSViewController *controller = (ofxiOSViewController*)self.uiViewController ;
182+ [controller rotateToInterfaceOrientation: UIInterfaceOrientationPortrait animated: false ];
183+ } else if ([self .uiViewController isKindOfClass: ofxiOSGLKViewController.class ]) {
184+ ofxiOSGLKViewController *controller = (ofxiOSGLKViewController *)self.uiViewController ;
185+ [controller rotateToInterfaceOrientation: UIInterfaceOrientationPortrait animated: false ];
186+ }
183187 ofSetOrientation (requested);
184188 }
185189
@@ -239,11 +243,17 @@ - (void)receivedRotate:(NSNotification*)notification {
239243 if ( [[[UIDevice currentDevice ] systemVersion ] compare: @" 8.0" options: NSNumericSearch] == NSOrderedAscending ) {
240244 // iOS7-
241245 if (deviceOrientation != UIDeviceOrientationUnknown && deviceOrientation != UIDeviceOrientationFaceUp && deviceOrientation != UIDeviceOrientationFaceDown ) {
242- if ([self .uiViewController respondsToSelector: @selector (isReadyToRotate )]) {
243- if ([self .uiViewController isReadyToRotate ]) {
244- ofxiOSAlerts.deviceOrientationChanged ( deviceOrientation );
245- }
246- }
246+ if ([self .uiViewController isKindOfClass: ofxiOSViewController.class ]) {
247+ ofxiOSViewController *controller = (ofxiOSViewController*)self.uiViewController ;
248+ if ([controller isReadyToRotate ]) {
249+ ofxiOSAlerts.deviceOrientationChanged ( deviceOrientation );
250+ }
251+ } else if ([self .uiViewController isKindOfClass: ofxiOSGLKViewController.class ]) {
252+ ofxiOSGLKViewController *controller = (ofxiOSGLKViewController *)self.uiViewController ;
253+ if ([controller isReadyToRotate ]) {
254+ ofxiOSAlerts.deviceOrientationChanged ( deviceOrientation );
255+ }
256+ }
247257 }
248258 }else {
249259 ofxiOSAlerts.deviceOrientationChanged ( deviceOrientation );
@@ -293,7 +303,7 @@ - (BOOL)createExternalWindowWithPreferredMode {
293303 externalScreenFrame = CGRectZero;
294304 externalScreenFrame.size = CGSizeMake (w, h);
295305
296- self.externalWindow = [[[ UIWindow alloc ] initWithFrame: externalScreenFrame] autorelease ];
306+ self.externalWindow = [[UIWindow alloc ] initWithFrame: externalScreenFrame];
297307 self.externalWindow .screen = externalScreen;
298308 self.externalWindow .clipsToBounds = YES ;
299309 self.externalWindow .hidden = NO ;
@@ -331,7 +341,7 @@ - (BOOL)createExternalWindowWithScreenModeIndex:(NSInteger)screenModeIndex {
331341 externalScreenFrame = CGRectZero;
332342 externalScreenFrame.size = CGSizeMake (w, h);
333343
334- self.externalWindow = [[[ UIWindow alloc ] initWithFrame: externalScreenFrame] autorelease ];
344+ self.externalWindow = [[UIWindow alloc ] initWithFrame: externalScreenFrame];
335345 self.externalWindow .screen = externalScreen;
336346 self.externalWindow .clipsToBounds = YES ;
337347 self.externalWindow .hidden = NO ;
0 commit comments