How to load a local html file into webView on iPad - xcode4

I have an iPad Master Detail project and I am trying to display html content in a web view which is called detailWebView.
I have set the content of detailItem in the Master View Controller.
self.detailViewController.detailItem=[[_topicsData
objectAtIndex:indexPath.section]
objectAtIndex: indexPath.row];
I have tried many ways to get the extracted information to display in the web view but it will not.
In configureView I have:
NSString *myString=[_detailItem objectForKey:#"url"];
NSString *myNewString=[NSString stringWithFormat:#"%#%#",myString,#".html"];
NSURL *url = [NSURL URLWithString:myNewString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self.detailWebView loadRequest:request];
But nothing I try will load the content.
I know I have the correct detail for url because when I try
NSLog(#"detailItem is %#",url);
I get something like myurl.html

You need to add the code in viewDidLoad:
- (void) viewDidLoad {
[super viewDidLoad];
self. detailWebView.delegate = self;
NSString *myString=[_detailItem objectForKey:#"url"];
NSString *myNewString=[NSString stringWithFormat:#"%#%#",myString,#".html"];
NSURL *url = [NSURL URLWithString:myNewString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self. detailWebView loadRequest:request];
}

Related

can't see the banner on my simulator

I want to add Admob in my app, the compilation is correct, but I can not see the banner on my simulator.
The app is for iPad in landscape mode.
I added the UUID of my macbook to the variable TEST_DEVICE_ID.
Could you help me ??
Thanks
bannerView_ = [[GADBannerView alloc]
initWithFrame:CGRectMake(0.0,
self.view.frame.size.height -
GAD_SIZE_320x50.height,
GAD_SIZE_320x50.width,
GAD_SIZE_320x50.height)];
bannerView_.adUnitID = MY_BANNER_UNIT_ID;
bannerView_.rootViewController = self;
[self.view addSubview:bannerView_];
[bannerView_ loadRequest:[GADRequest request]];
GADRequest *request = [GADRequest request];
request.testDevices = [NSArray arrayWithObjects:
GAD_SIMULATOR_ID,
#"TEST_DEVICE_ID",
nil];
First of all, you're not actually passing the request with testDevices to AdMob. To do that, you'll want to write:
GADRequest *request = [GADRequest request];
request.testDevices = [NSArray arrayWithObjects:
GAD_SIMULATOR_ID,
#"TEST_DEVICE_ID",
nil];
[bannerView_ loadRequest:request];
Now when you actually release, you'll want to be able to get live ads too. To find out more information, implement GADBannerViewDelegate and log why you aren't getting an ad:
- (void)adView:(GADBannerView *)view
didFailToReceiveAdWithError:(GADRequestError *)error {
NSLog(#"Failed to receive ad with error: %#", [error localizedFailureReason]);
}
Remember you'll need to add bannerView_.delegate = self; to set the delegate for this method to be fired.

change url to nsstring

I am trying to put a movie into the body of a text message from inside my app. I am using MFMessageComposeViewController to bring up the message view. I can put text into the body but I would like to put a movie. like Apple does when you select a movie in the photo library.
I have the path and name for the movie I just need to convert the url to a string so I can have the body = to it. here is my code
NSString *audioName = [pictureDictionary2 objectForKey:#"photoVideokey"];
NSArray *pathsa = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectorya = [pathsa objectAtIndex:0];
//Get a full path to the image in the documents directory.
NSString *fullPatha = [documentsDirectorya stringByAppendingPathComponent:audioName];
self.sharingImage = [NSURL fileURLWithPath:fullPatha];
NSURL *url1 = [NSURL fileURLWithPath:fullPatha];
NSData *videoData = [[NSData alloc] initWithContentsOfURL:url1];
//I know this isn't right and I have tried several things but can't seem to solve it.
NSString* theString = [NSURL fileURLWithPath:fullPatha];
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText])
{
controller.body = theString;
controller.messageComposeDelegate = self;
if (controller) [self presentViewController:controller animated:YES completion:NULL];
}
thanks for any help anyone can give.
I think you can't because I think Apple doesn't gives such permission to a custom app to add data to a messagecomposer but you can do this with mailcomposer.

How to play a video in iPhone simulator

I want to play a video in the iPhone simulator. I have tried with MPMoviePlayerViewController, but its not playing. Anybody has an idea on how to do it ? If there is any good tutorial , please help me find one. Thanx.
NOTE: Question related to MPMoviePlayerViewController not MPMoviePlayerController
Just drag and drop the video file in Your Xcode project
Give the url of video in "videourl"
NSURL *url = [NSURL URLWithString:videourl];
MPMoviePlayerViewController *moviePlayer1 = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:moviePlayer1];
It will run perfectly in simulator
This link Can also help You
Assuming ARC.
You can for example call that in your viewDidLoad method and add that controller to your view using:
- (void)viewDidLoad
{
[super viewDidLoad];
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:#"test" ofType:#"m4v"];
NSURL *movieURL = [NSURL fileURLWithPath:moviePath];
MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
[theMovie play];
[self.view addSubview:theMovie.view];
[self addChildViewController:theMovie];
}
in my header file I write:
MPMoviePlayerController *moviePlayer;
with this property:
#property(nonatomic, strong) MPMoviePlayerController *moviePlayer;
and in the method in which I init the moviePlayer:
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:movieUrl];
self.moviePlayer = player;
Use the following code
MPMoviePlayerController *moviePlayer1 = [[MPMoviePlayerController alloc]
initWithContentURL:yourVideoURL];
moviePlayer1.view.frame = CGRectMake(0, 0, 200, 110);
[self.view addSubview:moviePlayer1.view];
[[NSNotificationCenter defaultCenter]addObserver:self
selector:#selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer1];
[moviePlayer1 play];

Hiding controls overlay in mediaplayer framework, sdk4 iphone xcode

I am building a simple & basic video app using the media player framework.
How do I hide the player control overlay in SDK4, xcode so that the user does not have access to play, pause, ff, rw, etc.?
The codes I have implemented simply do not work and either give errors or do nothing at all.
I am stumped and have not been able to find support via research. I also need to take care of a memory leak later.
I've tried:
-(IBAction)playMovie:(id)sender
{
NSString *filepath = [[NSBundle mainBundle] pathForResource:#"1960" ofType:#"m4v"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.fullscreen = YES;
moviePlayerController.scalingMode = MPMovieScalingModeAspectFill;
[moviePlayerController play];
}
NSString *filepath = [[NSBundle mainBundle] pathForResource:#"Video1" ofType:#"mp4"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[moviePlayerController.view setFrame:CGRectMake(38, 100, 250, 163)];
moviePlayerController.controlStyle=MPMovieControlStyleNone;
try
yourPlayer.controlStyle = MPMovieControlStyleNone;
and change yourPlayer to your name of the player.

Buttons and Images are not being added to the view on Device (works in simulator)

I'm trying to load a plist from my main bundle and it isn't working too well. I keep geting a invalid CFStringRef which results in a nil for all the displays that I wanted.
To make this even more odd. It works perfectly in the simulator. I have attached this image to help explain.
http://img847.imageshack.us/img847/1185/screenshot20110325at120m.png
This doesn't make any sense to me. It works in simulator, by why doesn't it work on the device?
- (void)viewDidLoad {
[super viewDidLoad];
imageV = [[UIImage alloc]init];
imageV = [UIImage imageNamed:[NSString stringWithFormat:#"%#", imageTitle]];
button = [UIButton buttonWithType:UIButtonTypeCustom];
CGRect frame = CGRectMake(0, 0, 320, 65);
button.frame = frame; // match the button's size with the image size
[button setBackgroundImage:imageV forState:UIControlStateNormal];
[button addTarget:self action:#selector(adClicked:) forControlEvents:UIControlEventTouchUpInside];
button.backgroundColor = [UIColor clearColor];
[self.view addSubview:button];
NSLog(#"%i %#", [self.view.subviews count], webLink);
}
in both the simulator and device the console reports that there is one subview in each view created. In the simulator the button is added and appears with its image changed. However On the Device the button does not appear with its image changed. though it says the button is there it simply doesn't appear and I can't interact with it either incase the image just wasn't setting.
//addScroller.m
I've tried cleaning the target and adding the images directly to the app folder... I got nothing. my next bet is that it has something to do with the fact that i'm loading it from a plist file or something. I did rename the ads folder and made it lower case and started pretty much from scratch. would the plist be causing the issue? is the way in which I've loaded it changing the file casing or modifying the strings?
- (void)viewDidLoad {
[super viewDidLoad];
adIndex = 0;
adTimer = [[NSTimer alloc]init];
ad = [[Ad alloc]init];
adsList = [[NSMutableDictionary alloc]init];
item = [[NSDictionary alloc]init];
filePath = [[NSString alloc]init];
filePath = [[NSBundle mainBundle] pathForResource:#"Ads" ofType:#"plist"];
NSLog(#"%#", filePath);
adsList = [[[NSMutableDictionary alloc] initWithContentsOfFile:filePath]retain];
for (int i = 0; i < [adsList count]; i++) {
item = [[NSDictionary alloc]init];
item = [adsList valueForKey:[NSString stringWithFormat:#"%i", i ]];
ad = [[Ad alloc] initWith:[item objectForKey:#"adImage"] Link:[item objectForKey:#"website"]];
//[ads addObject:a];
ad.view.frame = CGRectMake(320 * i, 0, 320, 65);
[adsView addSubview:ad.view];
[item release];
}
[adsView setContentSize:CGSizeMake(320 * [adsList count], 65)];
adsView.pagingEnabled = YES;
adIndex = HBRandomInt([adsList count]);
[self scrollAds];
[NSTimer scheduledTimerWithTimeInterval:8.0
target:self
selector:#selector(scrollAds)
userInfo:nil
repeats:YES];
//[adTimer release];
//[ad release];
//[item release];
//[adsList release];
}
EDIT: I loaded the picture elsewhere in the app and it worked fine
The simulator (Mac) isn't case sensitive. The device is. This is often what causes problems loading resources on a device that seem to work just fine in the simulator.
Don't use [[NSString alloc] init];
Try NSString *filePath = nil;

Resources