1

I am using the following code to set the device orientation

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

when i used i got the warning and i found the below code to fix that warning.

@interface UIDevice (MyPrivateNameThatAppleWouldNeverUseGoesHere)
- (void) setOrientation:(UIInterfaceOrientation)orientation;
@end

Now what i would like to know is ...

Can the app store accepts this code to be in an application?

Thanks for any help!.

Stefan
  • 5,203
  • 8
  • 27
  • 51
user198725878
  • 6,266
  • 18
  • 77
  • 135

3 Answers3

6

oh god, no. The warning you're getting is because this is not a readwrite property; merely adding a category that declares the method will not let you set the orientation. Not only will the AppStore not accept this, it will crash the first time it's called, as there's no accessor. (well, it will PROBABLY crash. There may be an undocumented API here, in which case you'll JUST get rejected).

Ben Gottlieb
  • 85,404
  • 22
  • 176
  • 172
2

If you are trying to rotate the view programmatically, you should look at shouldAutorotateToInterfaceOrientation and if you just want the App to be of a specific orientation, try using UIInterfaceOrientation set in plist.

Another useful post: Forcing UIInterfaceOrientation changes on iPhone

Community
  • 1
  • 1
Ankit
  • 3,878
  • 5
  • 35
  • 51
0

Instead of setting an orientation, the proper way to do it is by having your application listen for when the user rotates the phone, then return YES or NO to indicate that the app should, in fact, rotate (i.e. always return NO if you want the app to always remain in its initial state.) The shouldAutorotateToInterfaceOrientation: method is automatically called whenever the user changes orientation.

For example, in your view controller, implement the method to only allow the phone to be used in landscape right/left:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    if (UIDeviceOrientationIsLandscape) { return YES };
    return NO;
}

You will also want to set your app's default orientation (so it doesn't start in portrait mode) by adding the UIInterfaceOrientation tag to your app's info.plist file with the value UIInterfaceOrientationLandscapeRight. Otherwise, the default value is portrait, and the user will have to tilt the phone to get it into the expected orientation.