I have a text label with the text set as Contact Us.. When user taps on this label it should launch safari to open the web page.My doubt is how to make Contact Us as hyperlink.Now I can't modify my code to include a UIWebView..Please help me guys..I am in final stages of my project..If possible please help me with sample code..thanks for all your time
The easiest way is to make the UILabel into a UIButton, style it (use Custom type to get rid of button look). Then connect to an Action that opens safari.
The action should do this:
NSURL *url = [[[ NSURL alloc ] initWithString: #"http://www.example.com" ] autorelease];
[[UIApplication sharedApplication] openURL:url];
for XOS use NSWorkspace instead:
- (IBAction)btnPressed:(id)sender {
NSURL *url = [[NSURL alloc] initWithString: #"https://www.google.com"];
[[NSWorkspace sharedWorkspace] openURL:url];
}
Related
I have a variable agencyWebsite and a label that should open the website when clicked with this method:
- (void)website1LblTapped {
NSURL *url = [NSURL URLWithString:self.agencyWebsite];
[[UIApplication sharedApplication] openURL:url];
}
I get a warning in the compiler saying:
Incompatible pointer types sending UILabel* to parameter of type NSString*
And the app crashes when the link is clicked. Any suggestions?
Edit: Here is what I am doing to make the label clickable
UITapGestureRecognizer* website1LblGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(website1LblTapped)];
// if labelView is not set userInteractionEnabled, you must do so
[self.agencyWebsite setUserInteractionEnabled:YES];
[self.agencyWebsite addGestureRecognizer:website1LblGesture];
What i used to get it working
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"http://%#", self.agencyWebsite.text]];
If agencyWebsite is of type UILabel*, you need to access its text property instead of passing the object itself to URLWithString:.
- (void)website1LblTapped {
NSURL *url = [NSURL URLWithString:self.agencyWebsite.text];
[[UIApplication sharedApplication] openURL:url];
}
Calling self.agencyWebsite will return your UILabel* object, whereas self.agencyWebsite.text will return a NSString* object containing the text from the label.
I've a a pdf placed in my Code files. I want it to open in iBooks, while researching I've found this :
NSString *stringURL = #"itms-books:";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
NSString *stringURL = #"itms-bookss:";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
How can I use this or what other way i can open my PDF File in iBook?
Regards
Maybe too late but I created a small example where the method explained in andycodes used. I uploaded to Github and you can download it here:
https://github.com/cjimenezpacho/openpdfibooks
Basically is this piece of code in a IBAction and the required delegate methods:
NSURL *url = [[NSBundle mainBundle]
URLForResource: #"iPhoneintro" withExtension:#"pdf"];
self.docController = [UIDocumentInteractionController interactionControllerWithURL:url];
self.docController.delegate = self;
[self.docController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
Links to Apple documentation:
Class:
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIDocumentInteractionController_class/Reference/Reference.html
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:#"itms-bookss://%#",self.pathToFile]]];
this does open a local pdf to Ibooks needs 2 s's.
Edit: to be specific on this this will open the local PDF if it is in iBooks already locally on the device.
if you need to add it to iBooks so far as I know you need to use the UIDocumentInteractionController.
Take a look at this Tumblr post explaining how do achieve a similar result using UIDocumentInteractionControllers.
http://andycodes.tumblr.com/post/738375724/ios4-sdk-opening-pdfs-in-ibooks
I want to use telprompt:// scheme to return to my application after it makes a call. But I have a problem.
If remote person is busy two buttons are shown to me: Redial and Cancel. So if I press Cancel I won't return to my application. Is there any way to handle it?
P. S. Isn't telprompt:// in Private API?
Here You can Use the WebView and Load Request on it.
UIWebView *callWebview = [[UIWebView alloc] init];
NSURL *telURL = [NSURL URLWithString:[NSString stringWithFormat:#"tel://%#", phoneNumber]
[callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];
I am Sure It would work with Charm.....
I think you need:
[[UIApplication sharedApplication] openURL: [NSURL URLWithString:[NSString stringWithFormat:#"telprompt:%#",num]]];
HI.. I have to show directions between two coordinates. I'd like to open Maps app, passing the start and end coordinates from my code.
I don't want to open it in the Google maps, which opens in browser(Safari). I tried that method. That was working perfect.
NSString* urlStr = [NSString stringWithFormat: #"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f", s_lat, s_long, d_lat, d_long];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString:urlStr]];
But, I want to open iPhone Maps app. How can i do this? Is this possible? Any help will be appreciated.
Try it on a real device. I'm using the same code and it opens Safari at the simulator and iPhone Maps at the device.
Hey Simon the method you are using is
[[UIApplication sharedApplication] openURL: [NSURL URLWithString:urlStr]];
will only open safari.So there is no chance that with open url you would open a diiferent thing.You can use the UIWebView for this and then load the webview with the url.I think that would be the simple thing like this
views=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
[views setBackgroundColor:[UIColor lightGrayColor]];
NSString* urlStr = [NSString stringWithFormat: #"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f", s_lat, s_long, d_lat, d_long];
NSURL *url=[NSURL URLWithString:urlStr];
NSURLRequest *req=[NSURLRequest requestWithURL:url];
//[views loadHTMLString:googlePage baseURL:requestURL];
[views loadRequest:req];
self.view=views;
And if you even don't want to use this then then you can use the MapKit provided in your XCode Frameworks.Hope this would help you.
I am new to iPhone developemnt.
NSString myUrl = #"www.google.com";
I need to know how to create a hyperlink for the above NSString variable.
In the MFMailComposeViewController I need to use like below
[mailViewController setMessageBody:myUrl isHTML:YES];
Please help me out.
Thanks for any help.
The easiest way is to make the UILabel into a UIButton, style it (use Custom type to get rid of button look). Then connect to an Action that opens safari.
The action should do this:
NSURL *url = [[[ NSURL alloc ] initWithString: #"http://www.example.com" ] autorelease];
[[UIApplication sharedApplication] openURL:url];