title: Using UIImagePicker in iPad with Landscape only on iOS 6
body: <p>I am making an iPad app that only supports landscape orientations, and in that app i am calling the photo Library using the following code</p>
  
  <pre><code>UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
  imagePicker.delegate = self;
  imagePicker.sourceType =
  UIImagePickerControllerSourceTypePhotoLibrary;
  imagePicker.mediaTypes = [NSArray arrayWithObjects: (NSString *) kUTTypeImage, nil];
  
  self.iPadPopoverController = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
  [self.iPadPopoverController setDelegate:self];
  [self.iPadPopoverController presentPopoverFromRect:CGRectMake(490, 638, 44, 44) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
  </code></pre>
  
  <p>However, This causes a crash with the following exception:</p>
  
  <pre><code>Uncaught exception: Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES
  </code></pre>
  
  <p><strong>The Reason for the Crash:</strong></p>
  
  <p>After researching I found that the crash was due to the <code>UIImagePickerController</code> always being displayed in <code>Portrait</code> mode even when the interface orientation is <code>Landscape</code>.</p>
  
  <p><strong>How I tried to solve it:</strong></p>
  
  <p>After reading the 
  <a href="http://developer.apple.com/library/ios/#releasenotes/General/RN-iOSSDK-6_0/_index.html" rel="nofollow">iOS6 release notes</a> and several questions previously posted; I found that the method from which the crash was originating was in the Application Delegate's</p>
  
  <pre><code>- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
  </code></pre>
  
  <p>the obvious solution was to have it return <code>UIInterfaceOrientationMaskLandscape|UIInterfaceOrientationMaskPortrait</code></p>
  
  <p>however, I want my app to support <code>Landscape</code> only! so my first solution was to add a <code>Boolean</code> flag to the App Delegate and set it to <code>YES</code> just before I call the <code>UIImagePickerController</code> and set back to <code>NO</code> after I dismiss it.</p>
  
  <p>And it worked, but I was not happy with it, it felt like a messy solution. So instead I had the method check for its caller and if it were the function that initializes the <code>UIImagePickerController</code> then the method would return <code>UIInterfaceOrientationMaskPortrait</code>. </p>
  
  <pre><code>-(BOOL) iPadPopoverCallerFoundInStackSymbols{
      NSArray *stackSymbols = [NSThread callStackSymbols];
  
      for (NSString *sourceString in stackSymbols) {
         if ([sourceString rangeOfString:@"[UIViewController(PhotoImport) importPhotoFromAlbum]"].location == NSNotFound) {
             continue;
         }else{
             return YES;
         }
     }
     return NO;
  }
  </code></pre>
  
  <p>That solution worked on the simulator and on the device.</p>
  
  <p><strong>Here is the weird part</strong></p>
  
  <p>After submitting my app to the store, all my users were reporting that the app was crashing whenever they would access the photo library. I looked over the crash reports and found that the crash was occurring due to the exception mentioned above. I could not understand why this was happening.</p>
  
  <p>So I submitted a TSI(Technical Support Incident) to apple about this issue. They replied that the stack symbols are not human readable after the app is archived and that is why my check would always fail.</p>
  
  <p>They also suggested testing on devices by archiving the project first into a <code>.ipa</code> file and installing it through iTunes inorder to detect issues like this in the future.</p>
  
  <p><strong>That's Great but my problem still exists</strong></p>
  
  <p>Does anyone know how to solve this problem?</p>