My app is portrait only except one view which contains an embedded YouTube video. That view is supposed to open in landscape and up until recently, worked just fine. The only change I have made to the app is to make it a universal app. I have made no changes to the code for this view though. It seems that the view initially loads ok in landscape if you are still holding the device in portrait. It doesn't crash until you actually rotate the device or, if you keep holding the device in portrait, press the play button. I tried adding the shouldAutoRotateMethod and returning NO and that causes the app not to crash but when pressing play it rotates back to portrait.
Any ideas?
The error is:
Here is my code:
Any ideas?
The error is:
Code:
Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES'
Here is my code:
Code:
#import "YouTubeView.h"
#import <MediaPlayer/MediaPlayer.h>
#import "KFBAppDelegate.h"
@interface YouTubeView ()
{
UIWindow *window;
}
@end
@implementation YouTubeView
@synthesize thumbnailView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
thumbnailView.backgroundColor = [UIColor clearColor];
KFBAppDelegate* myDelegate = (((KFBAppDelegate*) [UIApplication sharedApplication].delegate));
window = myDelegate.window;
// Custom initialization
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youTubeStarted:) name:@"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youTubeFinished:) name:@"UIMoviePlayerControllerDidExitFullscreenNotification" object:nil];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
/*
[self.view setBounds:CGRectMake( 0, 0, 480, 320)];
[self.view setCenter:CGPointMake(160, 240)];
[self.view setTransform:CGAffineTransformMakeRotation(M_PI/ 2)];
*/
self.title = @"Monthly Video";
// Do any additional setup after loading the view from its nib.
// webView is a UIWebView, either initialized programmatically or loaded as part of a xib.
int screenWidth = [UIScreen mainScreen].bounds.size.height;
NSString *htmlString = [NSString stringWithFormat:@"<html><head><meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = %d\"/></head><body style=\"background:#000;margin-top:10px;margin-left:0px\"><div><object width=\"220\" height=\"128\"><param name=\"movie\" value=\"http://www.youtube.com/embed/videoseries?list=PL0B9BF37A24840E28&hl=en_US""></param><param name=\"wmode\" value=\"transparent\"></param><embed src=\"http://www.youtube.com/embed/videoseries?list=PL0B9BF37A24840E28&hl=en_US""type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"%d\" height=\"218\"></embed></object></div></body></html>",screenWidth,screenWidth];
[thumbnailView loadHTMLString:htmlString baseURL:[NSURL URLWithString:@"http://www.youtube.com/playlist?list=PL0B9BF37A24840E28&feature=plcp"]];
}
-(IBAction)back:(id)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
// return UIDeviceOrientationLandscapeLeft | UIDeviceOrientationLandscapeRight | UIDeviceOrientationPortraitUpsideDown;
}
-(void)youTubeStarted:(id)sender
{
NSLog(@"Video Starting");
}
-(void)youTubeFinished:(id)sender
{
NSLog(@"bye");
}
@end