i have one problem with my app.Im building an app having navigation controller.when i select a particular row,its related url will be loaded.it is working fine.but how to get back from this view to the previous view?I tried to place a navigation bar top of the view but it is not visible.could u please help me out.....
I placed the following coding in did selectrowmethod
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//Get the selected country
NSString *selectedCountry = [listOfItems objectAtIndex:indexPath.row];
//NSString *url=#"";
if (indexPath.row==0) {
//url=#"http://www.osha.gov/dcsp/osp/stateprogs/alaska.html" ;
//label.text=url;
NSLog(#"======");
NSURL *url = [[NSURL alloc] initWithString:#"http://labor.state.ak.us/lss/oshhome.htm"];
[[UIApplication sharedApplication] openURL:url];
// self.label.text=#"url";
// NSLog(#"++++++:%#",self.label.text);
//textView.text=#"url";
}
else if(indexPath.row==1) {
NSURL *url = [[NSURL alloc] initWithString:#"http://www.ica.state.az.us/ADOSH/"];
[[UIApplication sharedApplication] openURL:url];
//url=#"http://www.osha.gov/dcsp/osp/stateprogs/arizona.html";
}
else if(indexPath.row==2) {
NSURL *url = [[NSURL alloc] initWithString:#"http://www.dir.ca.gov/occupational_safety.html"];
[[UIApplication sharedApplication] openURL:url];
//url=#"http://www.osha.gov/dcsp/osp/stateprogs/arizona.html";
}
else if(indexPath.row==3) {
NSURL *url = [[NSURL alloc] initWithString:#"http://www.ctdol.state.ct.us/osha/osha.htm"];
[[UIApplication sharedApplication] openURL:url];
//url=#"http://www.osha.gov/dcsp/osp/stateprogs/arizona.html";
}
}
Your code opens Safari. You can't go back from there. I suggest you check out UIWebView.
Related
I'm using this code to assign the link of my button to the wiki page, while capturing the countryName.text in the UILabel to be a part of the URL, but Xcode gives me an error when I press it. Here's the code:
- (IBAction)openWiki:(id)sender {
NSString *sampleUrl = [[NSString alloc] initWithFormat:#"http://en.wikipedia.org/wiki/%#%#",self.countryName.text];
NSURL *wikiUrl = [[NSURL alloc] initWithString:sampleUrl];
[[UIApplication sharedApplication] openURL:wikiUrl];}
Thanks in advance.
In your format you expect two parameters, but give only one:
#"http://en.wikipedia.org/wiki/%#%#",self.countryName.text
// ^^
Remove one specifier:
- (IBAction)openWiki:(id)sender {
NSString *sampleUrl = [[NSString alloc]
initWithFormat:#"http://en.wikipedia.org/wiki/%#",self.countryName.text];
// ^^
NSURL *wikiUrl = [[NSURL alloc] initWithString:sampleUrl];
[[UIApplication sharedApplication] openURL:wikiUrl];
}
I am trying to initiate a call from my iphone app,and I did it the following way..
-(IBAction) call:(id)sender
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Call Besito" message:#"\n\n\n"
delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Submit", nil];
[alert show];
[alert release];
}
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (buttonIndex != [alertView cancelButtonIndex])
{
NSString *phone_number = #"0911234567"; // assing dynamically from your code
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:#"tel:%#", phone_number]]];
NSString *phone_number = #"09008934848";
NSString *phoneStr = [[NSString alloc] initWithFormat:#"tel:%#",phone_number];
NSURL *phoneURL = [[NSURL alloc] initWithString:phoneStr];
[[UIApplication sharedApplication] openURL:phoneURL];
[phoneURL release];
[phoneStr release];
}
}
by the above code..I am able to successfully make a call..but when I end a call,I'm not able to return to my app
So, I want to know how to achieve,that..also please tell me how we can initiate a call using webview...
This is my code :
NSURL *url = [NSURL URLWithString:#"telprompt://123-4567-890"];
[[UIApplication sharedApplication] openURL:url];
Use this so that after call end it will return to app.
UIWebView *callWebview = [[UIWebView alloc] init];
NSURL *telURL = [NSURL URLWithString:#"tel:+9196815*****"];
[callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];
Please try this it will definitely let you Back to Your App.
NSString *phoneNumber = // dynamically assigned
NSString *phoneURLString = [NSString stringWithFormat:#"tel:%#", phoneNumber];
NSURL *phoneURL = [NSURL URLWithString:phoneURLString];
[[UIApplication sharedApplication] openURL:phoneURL];
following code will not return to your app [no alertview will show before make call]
UIWebView *callWebview = [[UIWebView alloc] init];
NSURL *telURL = [NSURL URLWithString:[NSString stringWithFormat:#"tel://%#",phoneNumber]];
[callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];
following code will return to your app "alertview will show before make call"
UIWebView *callWebview = [[UIWebView alloc] init];
NSURL *telURL = [NSURL URLWithString:[NSString stringWithFormat:#"telprompt://%#", phoneNumber]];
[callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];
You can also use webview, this is my code :
NSURL *url = [NSURL URLWithString:#"tel://123-4567-890"];
UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(50, 50, 150, 100)];
[self.view addSubview:btn];
UIWebView *webview = [[UIWebView alloc] initWithFrame:CGRectMake(50, 50, 150, 100)];
webview.alpha = 0.0;
[webview loadRequest:[NSURLRequest requestWithURL:url]];
// Assume we are in a view controller and have access to self.view
[self.view insertSubview:webview belowSubview:btn];
[webview release];
[btn release];
It's not possible to return back to the app after ending a call because it's an app.
I have a table which lists out items I would to make each of the row in the table to point to a URL which is assigned to each item.
In your tableview delegate function didSelectRowAtIndexPath you can use this code to open a url in the Safari application.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSURL *url = [NSURL URLWithString:#"http://stackoverflow.com"];
[[UIApplication sharedApplication] openURL:url];
}
If you don't want to leave your app, you can open the url in a UIWebView.
UIWebView * wv = [[UIWebView alloc] initWithFrame:CGRectMake(0,0,320,460)];
[self.view addSubview:wv]; // or push onto Navigation Stack
// if adding wv as subview, also need to add a back button to self.view to dismiss webview.
[wv loadRequest:
[NSURLRequest requestWithURL:
[NSURL URLWithString: myURLForSelectedRow]]];
[wv autorelease];
When a cell is selected, the -tableview:didSelectRowAtIndexPath: delegate method will be called. From there, assuming you have the url for each row, the following code will open the URL url in Safari.
NSURL *url = /* Assume this exists */;
if( [[UIApplication sharedApplication] canOpenURL:url] )
{
[[UIApplication sharedApplication] openURL: url];
}
Is it possible to launch an application at the end of phone call or after sending SMS?
NO this is not at all possible. Because you cant get the event when the call is ended or message is sent. So theres no way you can open up the application.
Happy Coding...
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];
}
//[[UIApplication sharedApplication] openURL:[NSURL URLWithString:aPhoneNo]];
}
Looks like it might help ..
iPhone SDK: Launching an app after call ends
Ok, I understand that using strings that have special characters is an encoding issue.
However I am not sure how to adjust my code to allow these characters. Below is the code that works great for text that contains no special characters, but can you show me how and where to change the code to allow for the special characters to be used. Right now those characters crash the app.
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 1) {
//iTunes Audio Search
NSString *stringURL = [NSString stringWithFormat:#"http://phobos.apple.com/WebObjects/MZSearch.woa/wa/search?WOURLEncoding=ISO8859_1&lang=1&output=lm&term=\"%#\"",currentSong.title];
stringURL = [stringURL stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
}
}
And this:
-(IBAction)launchLyricsSearch:(id)sender{
WebViewController * webView = [[WebViewController alloc] initWithNibName:#"WebViewController" bundle:[NSBundle mainBundle]];
webView.webURL = [NSString stringWithFormat:#"http://www.google.com/m/search?hl=es&q=\"%#\"+letras",currentSong.title];
webView.webTitle = #"Letras";
[self.navigationController pushViewController:webView animated:YES];
}
Please show me how and where to do this for these two bits of code.
-[NSString stringByAddingPercentEscapesUsingEncoding:]
NSASCIIStringEncoding usually works best for URL encoding.
If you only want to escape certain characters, use CFURLCreateStringByAddingPercentEscapes().
You should use the percent-escapes only to the currentSong.title and not to the entire URL. Here's what it should look like:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 1) {
//iTunes Audio Search
NSString *stringURL = [NSString stringWithFormat:
#"http://phobos.apple.com/WebObjects/MZSearch.woa/wa/search?WOURLEncoding=ISO8859_1&lang=1&output=lm&term=\"%#\"",
[currentSong.title stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
}
}
-(IBAction)launchLyricsSearch:(id)sender{
WebViewController * webView = [[WebViewController alloc] initWithNibName:#"WebViewController" bundle:[NSBundle mainBundle]];
webView.webURL = [NSString stringWithFormat:
#"http://www.google.com/m/search?hl=es&q=\"%#\"+letras",
[currentSong.title stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
webView.webTitle = #"Letras";
[self.navigationController pushViewController:webView animated:YES];
}
For non-ASCII characters such as ñ, the NSUTF8StringEncoding should properly handle them. NSUTF8StringEncoding is the recommended encoding for URLs.
Ok Dave's answer works great for Part 1:
Working Code:
NSString *stringURL = [NSString stringWithFormat:#"http://phobos.apple.com/WebObjects/MZSearch.woa/wa/search?WOURLEncoding=ISO8859_1&lang=1&output=lm&term=\"%#\"",currentSong.title];
stringURL = [stringURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
However, Part 2 isn't there yet (I know its me... but could you help?)
webView.webURL = [NSString stringwithFormat:#"http://www.google.com/m/search?hl=es&q=\"%#\"+letras",currentSong.title];
webView.webURL = [webView.webURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
What would be the correct code to get webView.webURL to allow spanish characters like "ñ"?