iPad simulator and external screen
i have an application that i wish to show on external screen.
The problem is that when i go Hardware -> External displays and select one of them - the events aren't triggered. Why?
This also doesn't get entered:
if ([[UIScreen screens] count] > 1)
So i have added next code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//SOME CODE ...
[self checkForExistingScreenAndInitializeIfPresent];
[self setUpScreenConnectionNotificationHandlers];
return YES:
}
- (void)checkForExistingScreenAndInitializeIfPresent
{
if ([[UIScreen screens] count] > 1)
{
// Get the screen object that represents the external display.
UIScreen *secondScreen = [[UIScreen screens] objectAtIndex:1];
// Get the screen's bounds so that you can create a window of the correct size.
CGRect screenBounds = secondScreen.bounds;
self.secondWindow = [[UIWindow alloc] initWithFrame:screenBounds];
self.secondWindow.screen = secondScreen;
self.externalWindow=[[ExternalDisplayViewController alloc]initWithNibName:@"ExternalDisplayViewController" bundle:nil];
self.externalWindow.view.frame=screenBounds;
self.secondWindow.rootViewController=self.externalWindow;
// Set up initial content to display...
// Show the window.
self.secondWindow.hidden = NO;
}
}
- (void)setUpScreenConnectionNotificationHandlers
{
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self selector:@selector(handleScreenDidConnectNotification:)
name:UIScreenDidConnectNotification object:nil];
[center addObserver:self selector:@selector(handleScreenDidDisconnectNotification:)
name:UIScreenDidDisconnectNotification object:nil];
}
ADDITION:
Just tried to add code in ViewDidLoad
Added this:
// Check for external screen.
if ([[UIScreen screens] count] > 1)
{
}
else {
}
Have the opened external display and simulator - does't enter the IF block
ios ipad ios-simulator external-display
|
show 3 more comments
i have an application that i wish to show on external screen.
The problem is that when i go Hardware -> External displays and select one of them - the events aren't triggered. Why?
This also doesn't get entered:
if ([[UIScreen screens] count] > 1)
So i have added next code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//SOME CODE ...
[self checkForExistingScreenAndInitializeIfPresent];
[self setUpScreenConnectionNotificationHandlers];
return YES:
}
- (void)checkForExistingScreenAndInitializeIfPresent
{
if ([[UIScreen screens] count] > 1)
{
// Get the screen object that represents the external display.
UIScreen *secondScreen = [[UIScreen screens] objectAtIndex:1];
// Get the screen's bounds so that you can create a window of the correct size.
CGRect screenBounds = secondScreen.bounds;
self.secondWindow = [[UIWindow alloc] initWithFrame:screenBounds];
self.secondWindow.screen = secondScreen;
self.externalWindow=[[ExternalDisplayViewController alloc]initWithNibName:@"ExternalDisplayViewController" bundle:nil];
self.externalWindow.view.frame=screenBounds;
self.secondWindow.rootViewController=self.externalWindow;
// Set up initial content to display...
// Show the window.
self.secondWindow.hidden = NO;
}
}
- (void)setUpScreenConnectionNotificationHandlers
{
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self selector:@selector(handleScreenDidConnectNotification:)
name:UIScreenDidConnectNotification object:nil];
[center addObserver:self selector:@selector(handleScreenDidDisconnectNotification:)
name:UIScreenDidDisconnectNotification object:nil];
}
ADDITION:
Just tried to add code in ViewDidLoad
Added this:
// Check for external screen.
if ([[UIScreen screens] count] > 1)
{
}
else {
}
Have the opened external display and simulator - does't enter the IF block
ios ipad ios-simulator external-display
1
I think you should have this code in the view controller, not in the app delegate. I have similar code to yours and it works perfectly.
– Marko Nikolovski
Jun 27 '14 at 8:57
Downloaded source code from here: mattgemmell.com/ipad-vga-output also doesn't work. Maybe i have to enable something IN the simulator?
– Cheese
Jun 27 '14 at 9:02
I'm almost sure you have to have this code in aUIViewController
subclass. The view controller "owns" all of the views, internal & external.
– Marko Nikolovski
Jun 27 '14 at 9:13
I just checked my old code, which is very similar to what you have (just contained in a view controller), and it works as expected.
– Marko Nikolovski
Jun 27 '14 at 9:13
This line of code[self checkForExistingScreenAndInitializeIfPresent];
should be present in theviewDidLoad:
and notification handlers.
– Marko Nikolovski
Jun 27 '14 at 9:14
|
show 3 more comments
i have an application that i wish to show on external screen.
The problem is that when i go Hardware -> External displays and select one of them - the events aren't triggered. Why?
This also doesn't get entered:
if ([[UIScreen screens] count] > 1)
So i have added next code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//SOME CODE ...
[self checkForExistingScreenAndInitializeIfPresent];
[self setUpScreenConnectionNotificationHandlers];
return YES:
}
- (void)checkForExistingScreenAndInitializeIfPresent
{
if ([[UIScreen screens] count] > 1)
{
// Get the screen object that represents the external display.
UIScreen *secondScreen = [[UIScreen screens] objectAtIndex:1];
// Get the screen's bounds so that you can create a window of the correct size.
CGRect screenBounds = secondScreen.bounds;
self.secondWindow = [[UIWindow alloc] initWithFrame:screenBounds];
self.secondWindow.screen = secondScreen;
self.externalWindow=[[ExternalDisplayViewController alloc]initWithNibName:@"ExternalDisplayViewController" bundle:nil];
self.externalWindow.view.frame=screenBounds;
self.secondWindow.rootViewController=self.externalWindow;
// Set up initial content to display...
// Show the window.
self.secondWindow.hidden = NO;
}
}
- (void)setUpScreenConnectionNotificationHandlers
{
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self selector:@selector(handleScreenDidConnectNotification:)
name:UIScreenDidConnectNotification object:nil];
[center addObserver:self selector:@selector(handleScreenDidDisconnectNotification:)
name:UIScreenDidDisconnectNotification object:nil];
}
ADDITION:
Just tried to add code in ViewDidLoad
Added this:
// Check for external screen.
if ([[UIScreen screens] count] > 1)
{
}
else {
}
Have the opened external display and simulator - does't enter the IF block
ios ipad ios-simulator external-display
i have an application that i wish to show on external screen.
The problem is that when i go Hardware -> External displays and select one of them - the events aren't triggered. Why?
This also doesn't get entered:
if ([[UIScreen screens] count] > 1)
So i have added next code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//SOME CODE ...
[self checkForExistingScreenAndInitializeIfPresent];
[self setUpScreenConnectionNotificationHandlers];
return YES:
}
- (void)checkForExistingScreenAndInitializeIfPresent
{
if ([[UIScreen screens] count] > 1)
{
// Get the screen object that represents the external display.
UIScreen *secondScreen = [[UIScreen screens] objectAtIndex:1];
// Get the screen's bounds so that you can create a window of the correct size.
CGRect screenBounds = secondScreen.bounds;
self.secondWindow = [[UIWindow alloc] initWithFrame:screenBounds];
self.secondWindow.screen = secondScreen;
self.externalWindow=[[ExternalDisplayViewController alloc]initWithNibName:@"ExternalDisplayViewController" bundle:nil];
self.externalWindow.view.frame=screenBounds;
self.secondWindow.rootViewController=self.externalWindow;
// Set up initial content to display...
// Show the window.
self.secondWindow.hidden = NO;
}
}
- (void)setUpScreenConnectionNotificationHandlers
{
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self selector:@selector(handleScreenDidConnectNotification:)
name:UIScreenDidConnectNotification object:nil];
[center addObserver:self selector:@selector(handleScreenDidDisconnectNotification:)
name:UIScreenDidDisconnectNotification object:nil];
}
ADDITION:
Just tried to add code in ViewDidLoad
Added this:
// Check for external screen.
if ([[UIScreen screens] count] > 1)
{
}
else {
}
Have the opened external display and simulator - does't enter the IF block
ios ipad ios-simulator external-display
ios ipad ios-simulator external-display
edited Jun 27 '14 at 9:23
Cheese
asked Jun 27 '14 at 8:36
CheeseCheese
1,96852355
1,96852355
1
I think you should have this code in the view controller, not in the app delegate. I have similar code to yours and it works perfectly.
– Marko Nikolovski
Jun 27 '14 at 8:57
Downloaded source code from here: mattgemmell.com/ipad-vga-output also doesn't work. Maybe i have to enable something IN the simulator?
– Cheese
Jun 27 '14 at 9:02
I'm almost sure you have to have this code in aUIViewController
subclass. The view controller "owns" all of the views, internal & external.
– Marko Nikolovski
Jun 27 '14 at 9:13
I just checked my old code, which is very similar to what you have (just contained in a view controller), and it works as expected.
– Marko Nikolovski
Jun 27 '14 at 9:13
This line of code[self checkForExistingScreenAndInitializeIfPresent];
should be present in theviewDidLoad:
and notification handlers.
– Marko Nikolovski
Jun 27 '14 at 9:14
|
show 3 more comments
1
I think you should have this code in the view controller, not in the app delegate. I have similar code to yours and it works perfectly.
– Marko Nikolovski
Jun 27 '14 at 8:57
Downloaded source code from here: mattgemmell.com/ipad-vga-output also doesn't work. Maybe i have to enable something IN the simulator?
– Cheese
Jun 27 '14 at 9:02
I'm almost sure you have to have this code in aUIViewController
subclass. The view controller "owns" all of the views, internal & external.
– Marko Nikolovski
Jun 27 '14 at 9:13
I just checked my old code, which is very similar to what you have (just contained in a view controller), and it works as expected.
– Marko Nikolovski
Jun 27 '14 at 9:13
This line of code[self checkForExistingScreenAndInitializeIfPresent];
should be present in theviewDidLoad:
and notification handlers.
– Marko Nikolovski
Jun 27 '14 at 9:14
1
1
I think you should have this code in the view controller, not in the app delegate. I have similar code to yours and it works perfectly.
– Marko Nikolovski
Jun 27 '14 at 8:57
I think you should have this code in the view controller, not in the app delegate. I have similar code to yours and it works perfectly.
– Marko Nikolovski
Jun 27 '14 at 8:57
Downloaded source code from here: mattgemmell.com/ipad-vga-output also doesn't work. Maybe i have to enable something IN the simulator?
– Cheese
Jun 27 '14 at 9:02
Downloaded source code from here: mattgemmell.com/ipad-vga-output also doesn't work. Maybe i have to enable something IN the simulator?
– Cheese
Jun 27 '14 at 9:02
I'm almost sure you have to have this code in a
UIViewController
subclass. The view controller "owns" all of the views, internal & external.– Marko Nikolovski
Jun 27 '14 at 9:13
I'm almost sure you have to have this code in a
UIViewController
subclass. The view controller "owns" all of the views, internal & external.– Marko Nikolovski
Jun 27 '14 at 9:13
I just checked my old code, which is very similar to what you have (just contained in a view controller), and it works as expected.
– Marko Nikolovski
Jun 27 '14 at 9:13
I just checked my old code, which is very similar to what you have (just contained in a view controller), and it works as expected.
– Marko Nikolovski
Jun 27 '14 at 9:13
This line of code
[self checkForExistingScreenAndInitializeIfPresent];
should be present in the viewDidLoad:
and notification handlers.– Marko Nikolovski
Jun 27 '14 at 9:14
This line of code
[self checkForExistingScreenAndInitializeIfPresent];
should be present in the viewDidLoad:
and notification handlers.– Marko Nikolovski
Jun 27 '14 at 9:14
|
show 3 more comments
4 Answers
4
active
oldest
votes
The problem might with the initialisation of the ExternalDisplayViewController :
self.externalWindow=[[ExternalDisplayViewController alloc]initWithNibName:@"ExternalDisplayViewController" bundle:nil];
Try this :
[[ExternalDisplayViewController alloc]initWithNibName:@"ExternalDisplayViewController" bundle:nil];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
self.externalWindow= = [storyboard instantiateViewControllerWithIdentifier:@"ExternalDisplayView"];
and also, you need to override this handleScreenDidConnectNotification
-(void)handleScreenDidConnectNotification : (NSNotification *)aNotification{
UIScreen *newScreen = [aNotification object];
CGRect screenBounds = newScreen.bounds;
self.alertForNotifyDisplay = [[UIAlertView alloc] initWithTitle:@"External Display Connected." message:Nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[self.alertForNotifyDisplay show];
if (!self.extWindow) {
self.extWindow = [[UIWindow alloc] initWithFrame:screenBounds];
self.extWindow.screen = newScreen;
[self checkForExistingScreenAndInitializeIfPresent];
}
}
You didn't get it - the problem is that it does't enter IF block - doesn't detect simulated external display
– Cheese
Jun 27 '14 at 8:49
Check the edited one. You need to handle the connection and need to callcheckForExistingScreenAndInitializeIfPresent
– Kumar KL
Jun 27 '14 at 8:50
I have the written handlers, just didn't paste them here. The problem is that, that code doesn't enter them if i disable or enable external display
– Cheese
Jun 27 '14 at 8:51
Downloaded source code from here: mattgemmell.com/ipad-vga-output also doesn't work. Maybe i have to enable something IN the simulator?
– Cheese
Jun 27 '14 at 9:03
There is nothing to do with the simulator, except enabling . Further all you need to do with the code .
– Kumar KL
Jun 28 '14 at 9:57
add a comment |
Here's my complete code in my UIViewController
subclass. I have checked it with the 7.1 simulator and it works for me (I start the app, and then initialize the external display once it's already running):
- (void)viewDidLoad {
// Other viewDidLoad code…
// Check and initialize big screen
[self checkForExistingScreenAndInitializeIfPresent];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// Register for second screen notifications
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self selector:@selector(handleScreenDidConnectNotification:)
name:UIScreenDidConnectNotification object:nil];
[center addObserver:self selector:@selector(handleScreenDidDisconnectNotification:)
name:UIScreenDidDisconnectNotification object:nil];
}
- (void)handleScreenDidConnectNotification:(NSNotification *)notification {
[self checkForExistingScreenAndInitializeIfPresent];
}
- (void)handleScreenDidDisconnectNotification:(NSNotification *)notification {
[self checkForExistingScreenAndInitializeIfPresent];
}
- (void)checkForExistingScreenAndInitializeIfPresent {
if ([[UIScreen screens] count] > 1) {
// Get the screen object that represents the external display.
UIScreen *secondScreen = [[UIScreen screens] objectAtIndex:1];
secondScreen.currentMode = secondScreen.preferredMode;
secondScreen.overscanCompensation = 3;
// Get the screen's bounds so that you can create a window of the correct size.
CGRect screenBounds = CGRectMake(secondScreen.bounds.origin.x,
secondScreen.bounds.origin.y,
secondScreen.currentMode.size.width,
secondScreen.currentMode.size.height);
UIWindow *secondWindow = [[UIWindow alloc] initWithFrame:screenBounds];
secondWindow.screen = secondScreen;
// Setup external VC
[ExternalScreenViewController sharedExternalScreen].window = secondWindow;
// Set VC for second window
secondWindow.rootViewController = [ExternalScreenViewController sharedExternalScreen];
// Show the window.
secondWindow.hidden = NO;
} else {
// What to do if disconnected
}
}
It should work with minor changes.
add a comment |
The problem was in beta versions of OS and Xcode. Downgraded back to Maverics - and all works like a charm
add a comment |
This was driving me nuts.
I'm on Version 10.0 (10A255) and it wasn't working. The reason why is I was looking at application:didFinishLaunchingWithOptions: for a UIScreen.screens.count > 1
This will always be 1
Instead try this
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let center = NotificationCenter.default
center.addObserver(self, selector: #selector(didConnect(notification:)), name: UIScreen.didConnectNotification, object: nil)
return true
}
@objc func didConnect(notification: Notification) {
if UIScreen.screens.count > 1 {
if let screen = UIScreen.screens.last {
let window = UIWindow(frame: screen.bounds)
window.screen = screen
let vc = UIViewController(nibName: nil, bundle: nil)
vc.view.backgroundColor = .red
window.isHidden = false
window.rootViewController = vc
self.secondWindow = window // Will not show unless window variable is retained.
}
}
}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f24447427%2fipad-simulator-and-external-screen%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
The problem might with the initialisation of the ExternalDisplayViewController :
self.externalWindow=[[ExternalDisplayViewController alloc]initWithNibName:@"ExternalDisplayViewController" bundle:nil];
Try this :
[[ExternalDisplayViewController alloc]initWithNibName:@"ExternalDisplayViewController" bundle:nil];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
self.externalWindow= = [storyboard instantiateViewControllerWithIdentifier:@"ExternalDisplayView"];
and also, you need to override this handleScreenDidConnectNotification
-(void)handleScreenDidConnectNotification : (NSNotification *)aNotification{
UIScreen *newScreen = [aNotification object];
CGRect screenBounds = newScreen.bounds;
self.alertForNotifyDisplay = [[UIAlertView alloc] initWithTitle:@"External Display Connected." message:Nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[self.alertForNotifyDisplay show];
if (!self.extWindow) {
self.extWindow = [[UIWindow alloc] initWithFrame:screenBounds];
self.extWindow.screen = newScreen;
[self checkForExistingScreenAndInitializeIfPresent];
}
}
You didn't get it - the problem is that it does't enter IF block - doesn't detect simulated external display
– Cheese
Jun 27 '14 at 8:49
Check the edited one. You need to handle the connection and need to callcheckForExistingScreenAndInitializeIfPresent
– Kumar KL
Jun 27 '14 at 8:50
I have the written handlers, just didn't paste them here. The problem is that, that code doesn't enter them if i disable or enable external display
– Cheese
Jun 27 '14 at 8:51
Downloaded source code from here: mattgemmell.com/ipad-vga-output also doesn't work. Maybe i have to enable something IN the simulator?
– Cheese
Jun 27 '14 at 9:03
There is nothing to do with the simulator, except enabling . Further all you need to do with the code .
– Kumar KL
Jun 28 '14 at 9:57
add a comment |
The problem might with the initialisation of the ExternalDisplayViewController :
self.externalWindow=[[ExternalDisplayViewController alloc]initWithNibName:@"ExternalDisplayViewController" bundle:nil];
Try this :
[[ExternalDisplayViewController alloc]initWithNibName:@"ExternalDisplayViewController" bundle:nil];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
self.externalWindow= = [storyboard instantiateViewControllerWithIdentifier:@"ExternalDisplayView"];
and also, you need to override this handleScreenDidConnectNotification
-(void)handleScreenDidConnectNotification : (NSNotification *)aNotification{
UIScreen *newScreen = [aNotification object];
CGRect screenBounds = newScreen.bounds;
self.alertForNotifyDisplay = [[UIAlertView alloc] initWithTitle:@"External Display Connected." message:Nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[self.alertForNotifyDisplay show];
if (!self.extWindow) {
self.extWindow = [[UIWindow alloc] initWithFrame:screenBounds];
self.extWindow.screen = newScreen;
[self checkForExistingScreenAndInitializeIfPresent];
}
}
You didn't get it - the problem is that it does't enter IF block - doesn't detect simulated external display
– Cheese
Jun 27 '14 at 8:49
Check the edited one. You need to handle the connection and need to callcheckForExistingScreenAndInitializeIfPresent
– Kumar KL
Jun 27 '14 at 8:50
I have the written handlers, just didn't paste them here. The problem is that, that code doesn't enter them if i disable or enable external display
– Cheese
Jun 27 '14 at 8:51
Downloaded source code from here: mattgemmell.com/ipad-vga-output also doesn't work. Maybe i have to enable something IN the simulator?
– Cheese
Jun 27 '14 at 9:03
There is nothing to do with the simulator, except enabling . Further all you need to do with the code .
– Kumar KL
Jun 28 '14 at 9:57
add a comment |
The problem might with the initialisation of the ExternalDisplayViewController :
self.externalWindow=[[ExternalDisplayViewController alloc]initWithNibName:@"ExternalDisplayViewController" bundle:nil];
Try this :
[[ExternalDisplayViewController alloc]initWithNibName:@"ExternalDisplayViewController" bundle:nil];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
self.externalWindow= = [storyboard instantiateViewControllerWithIdentifier:@"ExternalDisplayView"];
and also, you need to override this handleScreenDidConnectNotification
-(void)handleScreenDidConnectNotification : (NSNotification *)aNotification{
UIScreen *newScreen = [aNotification object];
CGRect screenBounds = newScreen.bounds;
self.alertForNotifyDisplay = [[UIAlertView alloc] initWithTitle:@"External Display Connected." message:Nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[self.alertForNotifyDisplay show];
if (!self.extWindow) {
self.extWindow = [[UIWindow alloc] initWithFrame:screenBounds];
self.extWindow.screen = newScreen;
[self checkForExistingScreenAndInitializeIfPresent];
}
}
The problem might with the initialisation of the ExternalDisplayViewController :
self.externalWindow=[[ExternalDisplayViewController alloc]initWithNibName:@"ExternalDisplayViewController" bundle:nil];
Try this :
[[ExternalDisplayViewController alloc]initWithNibName:@"ExternalDisplayViewController" bundle:nil];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
self.externalWindow= = [storyboard instantiateViewControllerWithIdentifier:@"ExternalDisplayView"];
and also, you need to override this handleScreenDidConnectNotification
-(void)handleScreenDidConnectNotification : (NSNotification *)aNotification{
UIScreen *newScreen = [aNotification object];
CGRect screenBounds = newScreen.bounds;
self.alertForNotifyDisplay = [[UIAlertView alloc] initWithTitle:@"External Display Connected." message:Nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[self.alertForNotifyDisplay show];
if (!self.extWindow) {
self.extWindow = [[UIWindow alloc] initWithFrame:screenBounds];
self.extWindow.screen = newScreen;
[self checkForExistingScreenAndInitializeIfPresent];
}
}
answered Jun 27 '14 at 8:46
Kumar KLKumar KL
11.3k93354
11.3k93354
You didn't get it - the problem is that it does't enter IF block - doesn't detect simulated external display
– Cheese
Jun 27 '14 at 8:49
Check the edited one. You need to handle the connection and need to callcheckForExistingScreenAndInitializeIfPresent
– Kumar KL
Jun 27 '14 at 8:50
I have the written handlers, just didn't paste them here. The problem is that, that code doesn't enter them if i disable or enable external display
– Cheese
Jun 27 '14 at 8:51
Downloaded source code from here: mattgemmell.com/ipad-vga-output also doesn't work. Maybe i have to enable something IN the simulator?
– Cheese
Jun 27 '14 at 9:03
There is nothing to do with the simulator, except enabling . Further all you need to do with the code .
– Kumar KL
Jun 28 '14 at 9:57
add a comment |
You didn't get it - the problem is that it does't enter IF block - doesn't detect simulated external display
– Cheese
Jun 27 '14 at 8:49
Check the edited one. You need to handle the connection and need to callcheckForExistingScreenAndInitializeIfPresent
– Kumar KL
Jun 27 '14 at 8:50
I have the written handlers, just didn't paste them here. The problem is that, that code doesn't enter them if i disable or enable external display
– Cheese
Jun 27 '14 at 8:51
Downloaded source code from here: mattgemmell.com/ipad-vga-output also doesn't work. Maybe i have to enable something IN the simulator?
– Cheese
Jun 27 '14 at 9:03
There is nothing to do with the simulator, except enabling . Further all you need to do with the code .
– Kumar KL
Jun 28 '14 at 9:57
You didn't get it - the problem is that it does't enter IF block - doesn't detect simulated external display
– Cheese
Jun 27 '14 at 8:49
You didn't get it - the problem is that it does't enter IF block - doesn't detect simulated external display
– Cheese
Jun 27 '14 at 8:49
Check the edited one. You need to handle the connection and need to call
checkForExistingScreenAndInitializeIfPresent
– Kumar KL
Jun 27 '14 at 8:50
Check the edited one. You need to handle the connection and need to call
checkForExistingScreenAndInitializeIfPresent
– Kumar KL
Jun 27 '14 at 8:50
I have the written handlers, just didn't paste them here. The problem is that, that code doesn't enter them if i disable or enable external display
– Cheese
Jun 27 '14 at 8:51
I have the written handlers, just didn't paste them here. The problem is that, that code doesn't enter them if i disable or enable external display
– Cheese
Jun 27 '14 at 8:51
Downloaded source code from here: mattgemmell.com/ipad-vga-output also doesn't work. Maybe i have to enable something IN the simulator?
– Cheese
Jun 27 '14 at 9:03
Downloaded source code from here: mattgemmell.com/ipad-vga-output also doesn't work. Maybe i have to enable something IN the simulator?
– Cheese
Jun 27 '14 at 9:03
There is nothing to do with the simulator, except enabling . Further all you need to do with the code .
– Kumar KL
Jun 28 '14 at 9:57
There is nothing to do with the simulator, except enabling . Further all you need to do with the code .
– Kumar KL
Jun 28 '14 at 9:57
add a comment |
Here's my complete code in my UIViewController
subclass. I have checked it with the 7.1 simulator and it works for me (I start the app, and then initialize the external display once it's already running):
- (void)viewDidLoad {
// Other viewDidLoad code…
// Check and initialize big screen
[self checkForExistingScreenAndInitializeIfPresent];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// Register for second screen notifications
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self selector:@selector(handleScreenDidConnectNotification:)
name:UIScreenDidConnectNotification object:nil];
[center addObserver:self selector:@selector(handleScreenDidDisconnectNotification:)
name:UIScreenDidDisconnectNotification object:nil];
}
- (void)handleScreenDidConnectNotification:(NSNotification *)notification {
[self checkForExistingScreenAndInitializeIfPresent];
}
- (void)handleScreenDidDisconnectNotification:(NSNotification *)notification {
[self checkForExistingScreenAndInitializeIfPresent];
}
- (void)checkForExistingScreenAndInitializeIfPresent {
if ([[UIScreen screens] count] > 1) {
// Get the screen object that represents the external display.
UIScreen *secondScreen = [[UIScreen screens] objectAtIndex:1];
secondScreen.currentMode = secondScreen.preferredMode;
secondScreen.overscanCompensation = 3;
// Get the screen's bounds so that you can create a window of the correct size.
CGRect screenBounds = CGRectMake(secondScreen.bounds.origin.x,
secondScreen.bounds.origin.y,
secondScreen.currentMode.size.width,
secondScreen.currentMode.size.height);
UIWindow *secondWindow = [[UIWindow alloc] initWithFrame:screenBounds];
secondWindow.screen = secondScreen;
// Setup external VC
[ExternalScreenViewController sharedExternalScreen].window = secondWindow;
// Set VC for second window
secondWindow.rootViewController = [ExternalScreenViewController sharedExternalScreen];
// Show the window.
secondWindow.hidden = NO;
} else {
// What to do if disconnected
}
}
It should work with minor changes.
add a comment |
Here's my complete code in my UIViewController
subclass. I have checked it with the 7.1 simulator and it works for me (I start the app, and then initialize the external display once it's already running):
- (void)viewDidLoad {
// Other viewDidLoad code…
// Check and initialize big screen
[self checkForExistingScreenAndInitializeIfPresent];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// Register for second screen notifications
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self selector:@selector(handleScreenDidConnectNotification:)
name:UIScreenDidConnectNotification object:nil];
[center addObserver:self selector:@selector(handleScreenDidDisconnectNotification:)
name:UIScreenDidDisconnectNotification object:nil];
}
- (void)handleScreenDidConnectNotification:(NSNotification *)notification {
[self checkForExistingScreenAndInitializeIfPresent];
}
- (void)handleScreenDidDisconnectNotification:(NSNotification *)notification {
[self checkForExistingScreenAndInitializeIfPresent];
}
- (void)checkForExistingScreenAndInitializeIfPresent {
if ([[UIScreen screens] count] > 1) {
// Get the screen object that represents the external display.
UIScreen *secondScreen = [[UIScreen screens] objectAtIndex:1];
secondScreen.currentMode = secondScreen.preferredMode;
secondScreen.overscanCompensation = 3;
// Get the screen's bounds so that you can create a window of the correct size.
CGRect screenBounds = CGRectMake(secondScreen.bounds.origin.x,
secondScreen.bounds.origin.y,
secondScreen.currentMode.size.width,
secondScreen.currentMode.size.height);
UIWindow *secondWindow = [[UIWindow alloc] initWithFrame:screenBounds];
secondWindow.screen = secondScreen;
// Setup external VC
[ExternalScreenViewController sharedExternalScreen].window = secondWindow;
// Set VC for second window
secondWindow.rootViewController = [ExternalScreenViewController sharedExternalScreen];
// Show the window.
secondWindow.hidden = NO;
} else {
// What to do if disconnected
}
}
It should work with minor changes.
add a comment |
Here's my complete code in my UIViewController
subclass. I have checked it with the 7.1 simulator and it works for me (I start the app, and then initialize the external display once it's already running):
- (void)viewDidLoad {
// Other viewDidLoad code…
// Check and initialize big screen
[self checkForExistingScreenAndInitializeIfPresent];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// Register for second screen notifications
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self selector:@selector(handleScreenDidConnectNotification:)
name:UIScreenDidConnectNotification object:nil];
[center addObserver:self selector:@selector(handleScreenDidDisconnectNotification:)
name:UIScreenDidDisconnectNotification object:nil];
}
- (void)handleScreenDidConnectNotification:(NSNotification *)notification {
[self checkForExistingScreenAndInitializeIfPresent];
}
- (void)handleScreenDidDisconnectNotification:(NSNotification *)notification {
[self checkForExistingScreenAndInitializeIfPresent];
}
- (void)checkForExistingScreenAndInitializeIfPresent {
if ([[UIScreen screens] count] > 1) {
// Get the screen object that represents the external display.
UIScreen *secondScreen = [[UIScreen screens] objectAtIndex:1];
secondScreen.currentMode = secondScreen.preferredMode;
secondScreen.overscanCompensation = 3;
// Get the screen's bounds so that you can create a window of the correct size.
CGRect screenBounds = CGRectMake(secondScreen.bounds.origin.x,
secondScreen.bounds.origin.y,
secondScreen.currentMode.size.width,
secondScreen.currentMode.size.height);
UIWindow *secondWindow = [[UIWindow alloc] initWithFrame:screenBounds];
secondWindow.screen = secondScreen;
// Setup external VC
[ExternalScreenViewController sharedExternalScreen].window = secondWindow;
// Set VC for second window
secondWindow.rootViewController = [ExternalScreenViewController sharedExternalScreen];
// Show the window.
secondWindow.hidden = NO;
} else {
// What to do if disconnected
}
}
It should work with minor changes.
Here's my complete code in my UIViewController
subclass. I have checked it with the 7.1 simulator and it works for me (I start the app, and then initialize the external display once it's already running):
- (void)viewDidLoad {
// Other viewDidLoad code…
// Check and initialize big screen
[self checkForExistingScreenAndInitializeIfPresent];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// Register for second screen notifications
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self selector:@selector(handleScreenDidConnectNotification:)
name:UIScreenDidConnectNotification object:nil];
[center addObserver:self selector:@selector(handleScreenDidDisconnectNotification:)
name:UIScreenDidDisconnectNotification object:nil];
}
- (void)handleScreenDidConnectNotification:(NSNotification *)notification {
[self checkForExistingScreenAndInitializeIfPresent];
}
- (void)handleScreenDidDisconnectNotification:(NSNotification *)notification {
[self checkForExistingScreenAndInitializeIfPresent];
}
- (void)checkForExistingScreenAndInitializeIfPresent {
if ([[UIScreen screens] count] > 1) {
// Get the screen object that represents the external display.
UIScreen *secondScreen = [[UIScreen screens] objectAtIndex:1];
secondScreen.currentMode = secondScreen.preferredMode;
secondScreen.overscanCompensation = 3;
// Get the screen's bounds so that you can create a window of the correct size.
CGRect screenBounds = CGRectMake(secondScreen.bounds.origin.x,
secondScreen.bounds.origin.y,
secondScreen.currentMode.size.width,
secondScreen.currentMode.size.height);
UIWindow *secondWindow = [[UIWindow alloc] initWithFrame:screenBounds];
secondWindow.screen = secondScreen;
// Setup external VC
[ExternalScreenViewController sharedExternalScreen].window = secondWindow;
// Set VC for second window
secondWindow.rootViewController = [ExternalScreenViewController sharedExternalScreen];
// Show the window.
secondWindow.hidden = NO;
} else {
// What to do if disconnected
}
}
It should work with minor changes.
answered Jun 27 '14 at 10:29
Marko NikolovskiMarko Nikolovski
3,3012535
3,3012535
add a comment |
add a comment |
The problem was in beta versions of OS and Xcode. Downgraded back to Maverics - and all works like a charm
add a comment |
The problem was in beta versions of OS and Xcode. Downgraded back to Maverics - and all works like a charm
add a comment |
The problem was in beta versions of OS and Xcode. Downgraded back to Maverics - and all works like a charm
The problem was in beta versions of OS and Xcode. Downgraded back to Maverics - and all works like a charm
answered Jul 15 '14 at 5:46
CheeseCheese
1,96852355
1,96852355
add a comment |
add a comment |
This was driving me nuts.
I'm on Version 10.0 (10A255) and it wasn't working. The reason why is I was looking at application:didFinishLaunchingWithOptions: for a UIScreen.screens.count > 1
This will always be 1
Instead try this
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let center = NotificationCenter.default
center.addObserver(self, selector: #selector(didConnect(notification:)), name: UIScreen.didConnectNotification, object: nil)
return true
}
@objc func didConnect(notification: Notification) {
if UIScreen.screens.count > 1 {
if let screen = UIScreen.screens.last {
let window = UIWindow(frame: screen.bounds)
window.screen = screen
let vc = UIViewController(nibName: nil, bundle: nil)
vc.view.backgroundColor = .red
window.isHidden = false
window.rootViewController = vc
self.secondWindow = window // Will not show unless window variable is retained.
}
}
}
add a comment |
This was driving me nuts.
I'm on Version 10.0 (10A255) and it wasn't working. The reason why is I was looking at application:didFinishLaunchingWithOptions: for a UIScreen.screens.count > 1
This will always be 1
Instead try this
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let center = NotificationCenter.default
center.addObserver(self, selector: #selector(didConnect(notification:)), name: UIScreen.didConnectNotification, object: nil)
return true
}
@objc func didConnect(notification: Notification) {
if UIScreen.screens.count > 1 {
if let screen = UIScreen.screens.last {
let window = UIWindow(frame: screen.bounds)
window.screen = screen
let vc = UIViewController(nibName: nil, bundle: nil)
vc.view.backgroundColor = .red
window.isHidden = false
window.rootViewController = vc
self.secondWindow = window // Will not show unless window variable is retained.
}
}
}
add a comment |
This was driving me nuts.
I'm on Version 10.0 (10A255) and it wasn't working. The reason why is I was looking at application:didFinishLaunchingWithOptions: for a UIScreen.screens.count > 1
This will always be 1
Instead try this
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let center = NotificationCenter.default
center.addObserver(self, selector: #selector(didConnect(notification:)), name: UIScreen.didConnectNotification, object: nil)
return true
}
@objc func didConnect(notification: Notification) {
if UIScreen.screens.count > 1 {
if let screen = UIScreen.screens.last {
let window = UIWindow(frame: screen.bounds)
window.screen = screen
let vc = UIViewController(nibName: nil, bundle: nil)
vc.view.backgroundColor = .red
window.isHidden = false
window.rootViewController = vc
self.secondWindow = window // Will not show unless window variable is retained.
}
}
}
This was driving me nuts.
I'm on Version 10.0 (10A255) and it wasn't working. The reason why is I was looking at application:didFinishLaunchingWithOptions: for a UIScreen.screens.count > 1
This will always be 1
Instead try this
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let center = NotificationCenter.default
center.addObserver(self, selector: #selector(didConnect(notification:)), name: UIScreen.didConnectNotification, object: nil)
return true
}
@objc func didConnect(notification: Notification) {
if UIScreen.screens.count > 1 {
if let screen = UIScreen.screens.last {
let window = UIWindow(frame: screen.bounds)
window.screen = screen
let vc = UIViewController(nibName: nil, bundle: nil)
vc.view.backgroundColor = .red
window.isHidden = false
window.rootViewController = vc
self.secondWindow = window // Will not show unless window variable is retained.
}
}
}
answered Nov 23 '18 at 18:44
afinlaysonafinlayson
8112
8112
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f24447427%2fipad-simulator-and-external-screen%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
I think you should have this code in the view controller, not in the app delegate. I have similar code to yours and it works perfectly.
– Marko Nikolovski
Jun 27 '14 at 8:57
Downloaded source code from here: mattgemmell.com/ipad-vga-output also doesn't work. Maybe i have to enable something IN the simulator?
– Cheese
Jun 27 '14 at 9:02
I'm almost sure you have to have this code in a
UIViewController
subclass. The view controller "owns" all of the views, internal & external.– Marko Nikolovski
Jun 27 '14 at 9:13
I just checked my old code, which is very similar to what you have (just contained in a view controller), and it works as expected.
– Marko Nikolovski
Jun 27 '14 at 9:13
This line of code
[self checkForExistingScreenAndInitializeIfPresent];
should be present in theviewDidLoad:
and notification handlers.– Marko Nikolovski
Jun 27 '14 at 9:14