Skip to content

Commit

Permalink
Use the app’s top most controller’s rotation preferences due to an ap…
Browse files Browse the repository at this point in the history
…ple bug

Fixes #1250
  • Loading branch information
joeljfischer committed May 2, 2019
1 parent f9dd27e commit a691a2b
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
8 changes: 8 additions & 0 deletions SmartDeviceLink-iOS.xcodeproj/project.pbxproj
Expand Up @@ -481,6 +481,8 @@
5D339CF0207C08BA000CC364 /* SDLVoiceCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D339CEE207C08BA000CC364 /* SDLVoiceCommand.m */; };
5D339CF3207C0ACE000CC364 /* SDLMenuManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D339CF1207C0ACE000CC364 /* SDLMenuManager.h */; };
5D339CF4207C0ACE000CC364 /* SDLMenuManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D339CF2207C0ACE000CC364 /* SDLMenuManager.m */; };
5D39BAB7227B3EA8008BCE08 /* UIWindow+SDLExtensions.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D39BAB5227B3EA8008BCE08 /* UIWindow+SDLExtensions.h */; };
5D39BAB8227B3EA8008BCE08 /* UIWindow+SDLExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D39BAB6227B3EA8008BCE08 /* UIWindow+SDLExtensions.m */; };
5D3E420A20EAAD6500D8C622 /* SDLTPMS.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D3E420820EAAD6500D8C622 /* SDLTPMS.h */; settings = {ATTRIBUTES = (Public, ); }; };
5D3E420B20EAAD6500D8C622 /* SDLTPMS.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D3E420920EAAD6500D8C622 /* SDLTPMS.m */; };
5D3E48751D6F3B330000BFEF /* SDLAsynchronousOperation.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D3E48731D6F3B330000BFEF /* SDLAsynchronousOperation.h */; };
Expand Down Expand Up @@ -2093,6 +2095,8 @@
5D339CEE207C08BA000CC364 /* SDLVoiceCommand.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SDLVoiceCommand.m; sourceTree = "<group>"; };
5D339CF1207C0ACE000CC364 /* SDLMenuManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SDLMenuManager.h; sourceTree = "<group>"; };
5D339CF2207C0ACE000CC364 /* SDLMenuManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SDLMenuManager.m; sourceTree = "<group>"; };
5D39BAB5227B3EA8008BCE08 /* UIWindow+SDLExtensions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UIWindow+SDLExtensions.h"; sourceTree = "<group>"; };
5D39BAB6227B3EA8008BCE08 /* UIWindow+SDLExtensions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UIWindow+SDLExtensions.m"; sourceTree = "<group>"; };
5D3E420820EAAD6500D8C622 /* SDLTPMS.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SDLTPMS.h; sourceTree = "<group>"; };
5D3E420920EAAD6500D8C622 /* SDLTPMS.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SDLTPMS.m; sourceTree = "<group>"; };
5D3E48731D6F3B330000BFEF /* SDLAsynchronousOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDLAsynchronousOperation.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -6016,6 +6020,8 @@
E9C32B9B1AB20C5900F283AF /* EAAccessoryManager+SDLProtocols.m */,
DA318C1D1DD0F06C00C035AC /* NSMutableDictionary+Store.h */,
DA318C1E1DD0F06C00C035AC /* NSMutableDictionary+Store.m */,
5D39BAB5227B3EA8008BCE08 /* UIWindow+SDLExtensions.h */,
5D39BAB6227B3EA8008BCE08 /* UIWindow+SDLExtensions.m */,
);
name = "@categories";
sourceTree = "<group>";
Expand Down Expand Up @@ -6127,6 +6133,7 @@
5D8A09811F54B4E5002502A2 /* SDLStreamingMediaManagerDataSource.h in Headers */,
5D61FC9C1A84238C00846EE7 /* SDLEmergencyEventType.h in Headers */,
5D61FD131A84238C00846EE7 /* SDLOnLanguageChange.h in Headers */,
5D39BAB7227B3EA8008BCE08 /* UIWindow+SDLExtensions.h in Headers */,
5D61FDE71A84238C00846EE7 /* SDLUnsubscribeButton.h in Headers */,
5DD8406220FCD6C10082CE04 /* SDLElectronicParkBrakeStatus.h in Headers */,
5D61FCAB1A84238C00846EE7 /* SDLFuelCutoffStatus.h in Headers */,
Expand Down Expand Up @@ -6943,6 +6950,7 @@
5D61FC681A84238C00846EE7 /* SDLComponentVolumeStatus.m in Sources */,
5D61FDB61A84238C00846EE7 /* SDLSyncMsgVersion.m in Sources */,
5D61FC501A84238C00846EE7 /* SDLBodyInformation.m in Sources */,
5D39BAB8227B3EA8008BCE08 /* UIWindow+SDLExtensions.m in Sources */,
88665B6A220B771A00D9DA77 /* SDLPerformAppServiceInteractionResponse.m in Sources */,
5D79A03C1CE36F030035797B /* SDLUploadFileOperation.m in Sources */,
5D61FD901A84238C00846EE7 /* SDLShow.m in Sources */,
Expand Down
24 changes: 24 additions & 0 deletions SmartDeviceLink/SDLScreenshotViewController.m
Expand Up @@ -8,6 +8,8 @@

#import "SDLScreenshotViewController.h"

#import "UIWindow+SDLExtensions.h"

@interface SDLScreenshotViewController ()

@property (nonatomic, strong) UIImageView *imageView;
Expand All @@ -30,6 +32,28 @@ - (instancetype)init {
return self;
}

// HAX: https://github.com/smartdevicelink/sdl_ios/issues/1250
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
UIViewController *viewController = [UIApplication sharedApplication].windows[0].sdl_topMostController;

if (viewController != nil) {
return viewController.supportedInterfaceOrientations;
}

return super.supportedInterfaceOrientations;
}

// HAX: https://github.com/smartdevicelink/sdl_ios/issues/1250
- (BOOL)shouldAutorotate {
UIViewController *viewController = [UIApplication sharedApplication].windows[0].sdl_topMostController;

if (viewController != nil) {
return viewController.shouldAutorotate;
}

return super.shouldAutorotate;
}

- (void)layoutSubviews {
self.imageView.frame = self.view.bounds;
}
Expand Down
19 changes: 19 additions & 0 deletions SmartDeviceLink/UIWindow+SDLExtensions.h
@@ -0,0 +1,19 @@
//
// UIWindow+SDLExtensions.h
// SmartDeviceLink
//
// Created by Joel Fischer on 5/2/19.
// Copyright © 2019 smartdevicelink. All rights reserved.
//

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface UIWindow (SDLExtensions)

@property (strong, nonatomic) UIViewController *sdl_topMostController;

@end

NS_ASSUME_NONNULL_END
23 changes: 23 additions & 0 deletions SmartDeviceLink/UIWindow+SDLExtensions.m
@@ -0,0 +1,23 @@
//
// UIWindow+SDLExtensions.m
// SmartDeviceLink
//
// Created by Joel Fischer on 5/2/19.
// Copyright © 2019 smartdevicelink. All rights reserved.
//

#import "UIWindow+SDLExtensions.h"

@implementation UIWindow (SDLExtensions)

- (UIViewController *)sdl_topMostController {
UIViewController *topController = self.rootViewController;

while (topController.presentedViewController) {
topController = topController.presentedViewController;
}

return topController;
}

@end

0 comments on commit a691a2b

Please sign in to comment.