I have a table view with list of we site addresses.
I have implemented to open website with url existing in cell Text, by clicking on a respective cell
as follows:
NSURL *websiteURL = [NSURL URLWithString:cell.textLabel.text];
[[UIApplication sharedApplication] openURL:websiteURL];
assume http://mywebsite.com" is the text on my cell
*
NSURL *websiteURL = [NSURL URLWithString:#"http://mywebsite.com"];
[[UIApplication sharedApplication] openURL:websiteURL];
*
it opens the correct web page but it quits my active application, and opens safari app
I was unable to came bak to my application again with out quit the webpage.
So I need to present webpage with in the app just like MF Emil composer.
As all we know MF Emil composer opens mail page and return back to active application, when click on cancel button.
I need same like MF Emil composer present model.
Do like this,
-> Create the new view controller.
-> Add webview as a subview of the view controller.
Eg:
UIWebView *webView = [[UIWebView alloc] initWithFrame: CGRectMake(0.0, 0.0, 1.0, 1.0)];
webView.delegate = self;
NSURLRequest *request = [[NSURLRequest alloc] initWithURL: [NSURL URLWithString: #"http://mywebsite.com"] cachePolicy: NSURLRequestUseProtocolCachePolicy timeoutInterval: myTimeoutValue];
[self.webView loadRequest: request];
->then Present the new view controller from where you want to call the url.
Related
Using this code to play YouTube video in UIWebView
- (void)embedYouTube {
UIWebView *webView = [[[UIWebView alloc] initWithFrame:self.view.bounds] autorelease];
webView.autoresizesSubviews = YES;
webView.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
// iframe
videoHTML = [NSString stringWithFormat:#"\
<html>\
<head>\
<style type=\"text/css\">\
iframe {position:absolute; top:50%%; margin-top:-130px;}\
body {background-color:#000; margin:0;}\
</style>\
</head>\
<body>\
<iframe width=\"560%%\" height=\"315px\" src=\"%#\"http://www.youtube.com/embed/j9CukQje2qw\" frameborder=\"0\" allowfullscreen></iframe>\
</body>\
</html>", videoURL];
[videoView loadHTMLString:videoHTML baseURL:nil];
}
When i click on this LaunchVideo UIButton all it shows black screen on iOS device
-(void)LaunchVideo:(id)sender
{
self.videoURL = #"http://www.youtube.com/embed/j9CukQje2qw";
WebViewController *webViewController = [[[WebViewController alloc] initWithNibName:nil bundle:nil] autorelease];
webViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
webViewController.videoURL = self.videoURL;
[self presentModalViewController:webViewController animated:YES];
}
If anyone can point out what i m missing or doing wrong in this code. Why youtube video is not showing. Not using interface builder doing programmtically. Got this project code from web. Tried this project code on ios device it works fine for that project but when applied its code in my project then it is not working. Only difference that his projectcode from web uses interface builder and i am doing it programmtically.I dont get it.
Please help what is wrong with this code.
Thanks for help.
Here is another way to load the youtube video into your app. First, put a UIWebView into your interface and size it to how big you want the video should show (there will be a button to make it full screen), then make an IBOutlet to it, so you can change its properties of hidden (to make it pop up and go away) Here is some code. In the code there is a method used called webviewshow, this calls a simple method that basically just says
webview.hidden = NO;
webviewbutton.hidden = NO;
Then there is a button that also pops up that makes the web view go away when tapped. Here is the code to load the youtube video into the web view
// Create your query ...
NSString* searchQuery = [NSString stringWithFormat:#"http://www.youtube.com/embed/j9CukQje2qw];
// Be careful to always URL encode things like spaces and other symbols that aren't URL friendly
searchQuery = [searchQuery stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
// Now create the URL string ...
NSString* urlString = searchQuery;
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
[webView loadRequest:request]; currentTimer= [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:#selector(webviewshow) userInfo:nil repeats:NO];;
It waits 2 seconds (usual wait time for most connections) until the web view is shown, so the page is loaded and the user does not have to watch it load.
Then when you want to make the video go away, make a method to close the web view like so
- (void) makewebviewGoAway {webview.hidden = YES; webviewbutton.hidden = YES;}
Hopefully, that was helpful. IF you need further help or explanation, just comment off of this.
In my application i get the links of video from server in UITableview .all these link are store on Sever in Textfile,i get all these link from sever one by one and assign each to cell in UITableview.all these i done succefully but i want when i click on any cell in UITableview its play the video in next view.here is my code.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
nextview *dvController = [[nextview alloc] initWithNibName:#"nextview" bundle:nil];
[self presentModalViewController:dvController animated:YES];
strFile = [Listdata objectAtIndex:indexPath.row];
NSLog(#"test=%#",strFile);
[dvController release];
}
and in next view i assign the link which i store in "strFile" to MPMoviePlayerController here is my code.
-(void)viewDidAppear:(BOOL)animated
{
NSLog(#"mytest=%#",strFile);
NSURL *url = [NSURL URLWithString:strFile];
NSLog(#"myurl=%#",url);
myplayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
myplayer.view.frame = CGRectMake(0, 0,900, 700);
[self.view addSubview:myplayer.view];
[myplayer play];
}
In NSlog i see the link but its not play in MPMoviePlayerController.Any one can guide me that what mistake i make.thanx in advance.
#prince : can u tell me what url you are getting in NSLog?? i think u're mistaken in getting the url.
we can get url either by
url = [NSURL fileURLWithPath:strUrl];
else
url = [NSURL URLWithString:strUrl];
try it out once.
You probably shouldn't be setting the frame and adding to the subview, You may be confused with MPMoviePlayerViewController. Try this...
-(void)viewDidAppear:(BOOL)animated {
NSLog(#"mytest=%#",strFile);
NSURL *url = [NSURL URLWithString:strFile];
NSLog(#"myurl=%#",url);
myplayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
myplayer.scalingMode = MPMovieScalingModeAspectFill;
[myplayer play];
}
EDIT disregard my code, you can't directly play a YouTube video in MPMoviePlayerController. Check this Post instead Play YouTube videos with MPMoviePlayerController instead of UIWebView
to youtube video play inside app is to create a UIWebView with the embed tag from Youtube for the movie you want to play as the UIWebView's content. UIWebView will detect that the embedded object is a Youtube link, and the web view's content will be the youtube preview for the video. When your user clicks the preview, the video will be shown in an MPMoviePlayerController. try this link:
http://iphoneincubator.com/blog/audio-video/how-to-play-youtube-videos-within-an-application
Unfortunately, there's no way to directly play a youtube video with MPMoviePlayerController because youtube does not expose direct links to the video files.
Facebook comment part of webview keep loading and it never finish on device.
But, it works just fine on simulator.
Does somebody have an idea to fix this? Thanks in advance!
This is the code to add UIWebview on UIViewController.
NSString *address = #"http://techcrunch.com/2012/03/10/entrepreneurs-are-difficult-at-best-and-abrasive-at-worst-get-over-it/?grcc=33333Z98";
//make webview frame
webView_ = [[UIWebView alloc] init];
webView_.delegate = self;
webView_.frame = self.view.bounds;
webView_.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
webView_.scalesPageToFit = YES;
[self.view addSubview:webView_];
//load page on webview
NSURL *myURL = [NSURL URLWithString:address];
NSURLRequest *myURLReq = [NSURLRequest requestWithURL:myURL];
[webView_ loadRequest:myURLReq];
This is the error message on - (void)webView:(UIWebView *)webView didFailLoadWithError:
Error Domain=NSURLErrorDomain Code=-999 "The operation couldn't be completed. (NSURLErrorDomain error -999.)"
Update
I tested it with a clean uiwebview, since the previous build had Sharekit plugin,
but the error still exist with a new build. Also, this link is related,
First dialog after authenticating fails immediately and closes dialog
FYI, I opened a bug recently on this. Facebook hasn't really responded and oddly classified it as a "wishlist" item:
https://developers.facebook.com/bugs/373249496041875?browse=search_4fa8cf425c5aa8d66140047
Am trying to load a .docx file into the uiwebview and am displaying it.To load the document into the webview it takes some fraction of seconds so i can see a white blank screen before the content can appear on the screen.I don't want to see that white screen while loading instead of that i want to do some actions like activity indicator or changing the background.How can i achieve this please help me.
Here is my code;
-(void)loadDocument:(NSString*)documentName inView:(UIWebView*)webViews
{
webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 416)];
isWebviewLoaded=YES;
webView.delegate=self;
webView.alpha=0;
NSString *path = [[NSBundle mainBundle] pathForResource:#"SKIN ADVISORuser_updated.docx" ofType:nil];
//NSString *path = [[NSBundle mainBundle]pathForResource:#"UserGuidelines3.html" ofType:nil];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webViews loadRequest:request];
}
and in viewdidload am calling above method:
[self loadDocument:#"ADVISORuser_updated.docx" inView:self.webView];
Even am implementing a delegate method to change the background but delegate is not executing
- (void)webViewDidFinishLoad:(UIWebView *)webViewload {
if (isWebviewLoaded)
{
isWebviewLoaded = NO;
webView.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:#"Instructions Screen Background light_PNG.png"]];
[UIView beginAnimations:#"webView" context:nil];
webView.alpha = 1.0;
[UIView commitAnimations];
}
}
Please can anyone help me..
before loadRequest u could create UIActivityIndicator object and start it by calling start method
and in webView delegate didFinishLoading: & didFailwithError method suspend the activity indicator
- (void)webViewDidFinishLoad:(UIWebView *)webViewload {
will be called only if you have set the delegate for the webView (in the xib &.h file)
This question already has answers here:
Make a phone call programmatically
(13 answers)
Closed 8 years ago.
I would lie to place a call in my app (I can use the tel:) but I would like to return to my app where I left after the users hangs up.
Is that possible?
I got this code from Apple site and it works perfectly:
-(IBAction) dialNumber:(id)sender{
NSString *aPhoneNo = [#"tel://" stringByAppendingString:[itsPhoneNoArray objectAtIndex:[sender tag]]] ; NSURL *url= [NSURL URLWithString:aPhoneNo];
NSString *osVersion = [[UIDevice currentDevice] systemVersion];
if ([osVersion floatValue] >= 3.1) {
UIWebView *webview = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
[webview loadRequest:[NSURLRequest requestWithURL:url]];
webview.hidden = YES;
// Assume we are in a view controller and have access to self.view
[self.view addSubview:webview];
[webview release];
} else {
// On 3.0 and below, dial as usual
[[UIApplication sharedApplication] openURL: url];
}
}
No it's not. The user controls where they navigate after the phone call has ended I'm afraid. by default, it stays in the phone application, and the only way for the user to exit out of it is to hit the home button, which takes them to their main screen. Save your state, and reload it when they come back like everyone else.
You cannot return to the app automatically, after the call completes, but if your app supports iOS 4, its multitasking features (if the app supports them) can bring the user back to the spot where he or she left off before the call, when the app is relaunched.
If you use iOS 3 or earlier, you will need to manually save the app's state yourself and then bring the user back to that state on relaunch.