2

Will Apple accept the following code?

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];

When I write this, I see the following warning:

warning: 'UIDevice' may not respond to '-setOrientation:'

So what can I do to set the iPhone's orientation programmatically?

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Jeeva
  • 101
  • 1
  • 5

4 Answers4

1

After writing [[UIDevice currentDevice] set ];, do you find option for setOrientation? Definitely it is a private API. Don't use it.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Raxit
  • 824
  • 7
  • 12
1

You should read the answers to this Stack Overflow question It has a long discussion with lots of code snippets about how to deal with the orientation and what to do about it.

Community
  • 1
  • 1
Walter
  • 5,867
  • 2
  • 30
  • 43
0

Just declare the method in a category in the .h or .m file of wherever you use it.

@interface UIDevice (MyPrivateNameThatAppleWouldNeverUseGoesHere)

-(void) setOrientation:(UIInterfaceOrientation)orientation;

@end

but also Apple rejects applications which use this code. So, use this for solution for call orienatation method.. and it works fine

UIViewController *viewController = [[UIViewController alloc] init];

[viewController setModalPresentationStyle:UIModalPresentationCurrentContext];

viewController.view.frame = CGRectZero;

[self presentModalViewController:viewController animated:NO];

[self dismissModalViewControllerAnimated:NO];

[viewController release];

sorry, if there is any mistake. i'm a fresher for iphone... :)

Chandani
  • 1
  • 1
0

No, Apple rejects applications which use this code.

Nickolay Olshevsky
  • 13,706
  • 1
  • 34
  • 48