How Do I detect the orientation of the device on iOS?

Really old thread, but no real solution. I Had the same problem, but found out that getting The UIDeviceOrientation isn’t always consistent, so instead use this: UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; if(orientation == 0) //Default orientation //UI is in Default (Portrait) — this is really a just a failsafe. else if(orientation == UIInterfaceOrientationPortrait) //Do something … Read more

iOS: Device orientation on load

EDIT: I mis-read your question. This will allow you to start your application in certain orientations. Just realized you’re trying to figure out the orientation on launch. There is a method to check the status bar orientation on UIApplication: [[UIApplication sharedApplication] statusBarOrientation]; Original answer Try setting the application’s accepted device orientations in the plist file: … Read more

Detecting iOS UIDevice orientation

Try doing the following when the application loads or when your view loads: [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:[UIDevice currentDevice]]; Then add the following method: – (void) orientationChanged:(NSNotification *)note { UIDevice * device = note.object; switch(device.orientation) { case UIDeviceOrientationPortrait: /* start special animation */ break; case UIDeviceOrientationPortraitUpsideDown: /* start special animation */ … Read more

Detecting Color of iPhone/iPad/iPod touch?

There’s a private API to retrieve both the DeviceColor and the DeviceEnclosureColor. UIDevice *device = [UIDevice currentDevice]; SEL selector = NSSelectorFromString(@”deviceInfoForKey:”); if (![device respondsToSelector:selector]) { selector = NSSelectorFromString(@”_deviceInfoForKey:”); } if ([device respondsToSelector:selector]) { NSLog(@”DeviceColor: %@ DeviceEnclosureColor: %@”, [device performSelector:selector withObject:@”DeviceColor”], [device performSelector:selector withObject:@”DeviceEnclosureColor”]); } I’ve blogged about this and provide a sample app: Retrieve iOS … Read more

tech