How to AutoRotate only MPMoviePlayerController in a ViewController? - rotation

I have tried many solutions but not worked yet! I'm developing iOS 6.1 iPhone app on Xcode 4.6.3.
I am using an MPMoviePlayerController in my application. I have 4 tabbed application. Movieplayer is in SecondViewController. I am not presenting it as a view controller but adding its view to my own view controller. The video plays just fine and I can go fullscreen.
Here's my code below. Any solutions?
#import "SecondViewController.h"
#interface SecondViewController ()
#end
#implementation SecondViewController
#synthesize moviePlayer;
- (IBAction)playVideo:(id)sender {
NSURL * url = [[NSURL alloc]initWithString:#"http://server:1935/live/test/playlist.m3u8"];
moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:url];
[self.view addSubview:moviePlayer.view];
moviePlayer.fullscreen = YES;
moviePlayer.allowsAirPlay = YES;
}
#end

Related

UIWebView in IOS 8 tables are not showing correctly

we recently upgraded to IOS 8 (and compiled the application).
we saw that tables with text are not showing well anymore (we use UIWebView).
did anyone encounter this? is this a known issue or a bug?
this is the code:
#import "ViewController.h"
#interface ViewController ()
#property (weak, nonatomic) IBOutlet UIWebView *viewWeb;
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSString* fullPath = #"/Users/deployment/Downloads/table-2.ppt";
[_viewWeb loadData:[NSData dataWithContentsOfFile:fullPath] MIMEType:#"application/vnd.ms-powerpoint" textEncodingName:nil baseURL:nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
thanks!
Are you tried this code...?
UIWebView *webView = [[UIWebView alloc]initWithFrame:CGRectMake(10.0,10.0,300,300)];
[webView setScalesPageToFit:YES];
webView.backgroundColor=[UIColor clearColor];
NSString *ppt = [[NSBundle mainBundle] pathForResource:#"test" ofType:#"ppt"];
NSURL *pptURL = [NSURL fileURLWithPath:ppt];
NSURLRequest *request = [NSURLRequest requestWithURL:pptURL];
[webView loadRequest:request];
[self.view addSubview:webView];
If this code also not worked with your ppt file. Please share your ppt file too. This code working in my case. May be some issue with presentation file.

UIWebView not loading content when it is passed from an UITableView in iOS6, but works perfectly in iOS5

First of all I would like to thank you reading this and helping me out if you know the answer, I am a bit of a newby to iOS and there is an issue that is driving me crazy.
I have an App that works perfectly in iOS5, it has an UITableVIewController and clicking on a row takes you to an UIView with a UIWebView. The idea is that the URL of the webpage to load is passed from the UITableViewController in this way.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if (([[segue identifier] isEqualToString:#"ViewWeb"])) {
WebViewController *detailViewController = [segue destinationViewController];
detailViewController.title=parameter;
detailViewController.detailItem = parameterURL;
}
}
Then in the WebViewController I use the following code. I declare everything in the .h:
#import <UIKit/UIKit.h>
#interface WebViewController : UIViewController <UIWebViewDelegate>{
IBOutlet UIWebView *webView;
NSString *detailItem;
}
#property(strong,nonatomic) IBOutlet UIWebView *webView;
#property (strong, nonatomic) NSString *detailItem;
#end
And In my .m I use the following code to load the URL:
#interface WebViewController ()
#end
#implementation WebViewController
#synthesize webView;
#synthesize detailItem;
- (void)viewDidLoad
{
[super viewDidLoad];
//Create a URL object.
NSURL *url = [NSURL URLWithString:detailItem];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[webView loadRequest:requestObj];
}
This is working perfectly fine in the iOS5 simulator, but in iOS6, the UIWebWiew remains blank and doesn't load up. I have read this solution UIWebView not loading URL when URL is passed from UITableView but placing the code in the (void)viewWillAppear:(BOOL)animated does not solve the issue. It works perfectly fine if I hard code the URL, so I am totally lost as to how to solve this.
Thank you very much in advance, I know everyone here is really busy and the fact that great guys take a few minutes to hep me is something amazing.

appdelegate object in xib

I am trying to follow the apple photopicker example which has an appdelegate object in an .xib file. How does an appdelegate object get into a xib file, and why is it important?
In my app I want a navigation controller like the photopicker example has. My test work has not included a navigation controller and I am having difficulty inserting one into my test work now that it has just a view controller because the interface builder seems to have made up its mind to not allow the addition. Will it be easiest for me to just start over with a new app that has the navigation controller architecture and then add in copies of my test work methods and classes. Or is starting over unnecessary? I suspect that inserting the appdelegate object into the xib would allow me to use the exist test work more directly.
update 0
I think I followed the instructions in your answer. Xcode suggested _viewController and I changed that. My app is for both iPad and iPhone (and I am working only on iPad now), so it is a little more complicated, I think. I compile fine, but I still see no appdelegate object in my xib file even though PhotoPicker's xib file has one.
I suspect I need to hook up some objects still, but I could use some help with that, too. In PhotoPicker the Connections Inspector for the Navigation Controller says that the Referencing Outlet is between navController and AppDelegate, and the Connections Inspector for the AppDelegate says that the Referencing Outlet is between delegate and File's Owner. But because my xib file has no (BS)AppDelegate object, I don't know how to hook up without it.
#interface BSAppDelegate ()
#property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
#end
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = [[BSViewController alloc] initWithNibName:#"BSViewController_iPhone" bundle:nil];
} else {
self.viewController = [[BSViewController alloc] initWithNibName:#"BSViewController_iPad" bundle:nil];
}
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:_viewController];
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
return YES;
}
update 0
Inside (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions, you can add uinavigationcontroller like this:
UIViewController *viewController = … //load your first view controller with the initial xib here
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
self.window.rootViewController = navigationController;

XCode Prevent UIWebView flashing white screen after Launch Image

I am fairly new to XCode - I'm designing an app with a single view that just displays a UIWebView that loads my jQuery mobile web site.
I have the Default.png and Default#2x.png files for the Launch images in place. When I run the app on my test device or in the emulator, it shows my Launch Image, and then flashes a white screen while the UIWebView loads the first page.
I know that I can change the background color and opacity so it will flash a different color than white, but I would like to prevent the flash altogether. I would like the app to launch, show the Launch image, and not show the UIWebView until the first page has completely loaded. Help?
# Andreas Volz (and anyone else wondering how I solved the problem of the white "flash")
First, add the name-of-loading-image.png and name-of-loading-image#2x.png files to your Xcode project. The regular image should be 320 x 460, and the #2x image should be 640 x 920.
Then, in my ViewController.h file I added these properties:
#property (nonatomic, retain) UIWebView *webView;
#property(nonatomic, strong) UIImageView *loadingImageView;
#end
And then in my ViewController.m file I added this:
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController;
#synthesize webView;
#synthesize loadingImageView;
- (void)viewDidLoad
{
[super viewDidLoad];
//**************** Set website URL for UIWebView
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.example.com"] cachePolicy:NSURLCacheStorageAllowed timeoutInterval:20.0]];
//**************** Add Static loading image to prevent white "flash" ****************/
UIImage *loadingImage = [UIImage imageNamed:#"name-of-loading-image.png"];
loadingImageView = [[UIImageView alloc] initWithImage:loadingImage];
loadingImageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"name-of-loading-image.png"],
nil];
[self.view addSubview:loadingImageView];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
// Remove loading image from view
[loadingImageView removeFromSuperview];
}
To know when your webView has finished loading, you must implement the UIWebViewDelegate protocol.
In your viewController's .h file:
#interface viewController : UIViewController <UIWebViewDelegate>
{
UIWebView *webView;
}
#end
Then in your viewController's .m file, add this method:
- (void)webViewDidFinishLoad:(UIWebView *)webView {
NSLog(#"content loading finished");
// Display your webView
[self.view addSubview:webView];
}
You can use the -viewDidLoad method in your viewController's .m to continue displaying your launch image. You can also begin the loading of content for your webView:
- (void)viewDidLoad {
[super viewDidLoad];
// continue to display launch image
UIImage *launchImage = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"launchImage.png" ofType:nil ]];
UIImageView *launchImageView = [[[UIImageView alloc] initWithImage:launchImage] autorelease];
[self.view addSubview:launchImageView];
// now setup the base view for the webView controller
UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
contentView.backgroundColor = [UIColor blueColor];
// for rotation
contentView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
self.view = contentView;
//create a frame to size and place the web view
CGRect webFrame = [[UIScreen mainScreen] applicationFrame];
UIWebView *aWebView = [[UIWebView alloc] initWithFrame:webFrame];
self.webView = aWebView;
//aWebView.scalesPageToFit = YES;
aWebView.autoresizesSubviews = YES;
aWebView.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
//set the web view delegates for the web view to be itself
[aWebView setDelegate:self];
//determine the path the to the index.html file in the Resources directory
NSURL *url = [[NSBundle mainBundle] URLForResource:#"index" withExtension:#"html"];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[aWebView loadRequest:requestObj];
}

IOS login screen before tab-controller view

I am still newbie for IOS Developing, i want to create a login page by MoralViewcontroller.
AppDelegate.h
#interface AppDelegate : UIResponder <UIApplicationDelegate>{
UITabBarController *tabBarController; }
#property (nonatomic,retain) IBOutlet UITabBarController * tabBarController
AppDelegate.m
(void)applicationDidFinishLaunching:(UIApplication *)application
{
// Override point for customization after app launch
[window addSubview:tabBarController. view];
[window makeKeyAndVisible];
LoginViewController *loginView=[[LoginViewController alloc]initWithNibName:#"LoginViewController" bundle:nil];
[tabBarController.view presentModelViewcontroller: loginView animated:YES];
}
However, the login view cannot be shown, I think I define wrongly for tabBarController, but I don't know what wrong with it. Can anyone please advise me? I am doing IOS 5.
Thanks alot..
I'd present a loginView controller from the rootView of the tabBarController.
-(void)viewDidLoad
{
//You can also do this inside a conditional statement, if needed
LoginViewController *loginView=[[LoginViewController alloc]initWithNibName:#"LoginViewController" bundle:nil];
[self.view presentModelViewcontroller:loginView animated:YES];
}
And here is the second way
AppDelegate.h
#interface AppDelegate : UIResponder {
LoginViewController *loginView;
}
#property (nonatomic,retain) LoginViewController *loginView;
AppDelegate.m
-(void)applicationDidFinishLaunching:(UIApplication *)application
{
// Override point for customization after app launch
self.loginView=[[LoginViewController alloc]initWithNibName:#"LoginViewController" bundle:nil];
[window addSubview:loginView. view];
[window makeKeyAndVisible];
}
LoginViewController.m
Call this method on successful login.
-(IBAction)login:(id)sender
{
//init tabbar with subviews;
UITabBarController *tabBarController = [[UITabBarController alloc] initW....];
[self.view addSubview:tabBarController.view];
}
I prefer first method, because in that you will be retaining the tabBarController in AppDelegate.
First of all you have to add the Loginviewcontroller to the window.And then you have to add the tabbarcontroller to the LoginViewController when the login button clicked.

Resources