how to open itunes link in iphone app? - iphone

I am trying to open itunes link on UIControlEventTouchDown button press event. My code is as follows.
NSString *urlString =#"http://itunes.apple.com/in/album/carnatic-vocal-sanjay-subrahmanyan/id106924807?ign-mpt=uo%3D4";
NSString *str_ur=[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url=[NSURL URLWithString:str_ur];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webview_buy loadRequest:requestObj];
webview_buy.delegate=self;
[self.view addSubview:webview_buy];
This will go to itunes in the device and open the itunes store. But i get an alert message that says
Your Request could not be Completed.
Please give idea with code.

First copy the url from iTunes which you want to open in app.
Then use below code:
[[UIApplication sharedApplication]
openURL:[NSURL URLWithString:#"http://itunes.apple.com/in/album/carnatic-vocal-sanjay-subrahmanyan/id106924807?ign-mpt=uo%3D4"]];
here, URLWithString value will be your app url which you want to open.
Let me know in case of any difficulty.

Use the itms-apps:// prefix to open in iTunes, e.g.
[[UIApplication sharedApplication]
openURL:[NSURL URLWithString:#"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=409954448"]];

It will work only with device. Throws Request could not be completed on simulator.

Related

open pdf in to another pdfviewer application from my application

I have one pdf in my application and I want to open that pdf but not in my applicaton.
When ever i'll click or open that pdf it will ask me to open that pdf in another application of pdf viewer availbale on my device i wnt to know that is it possible & if possible how can i do that?
-Thanx in advance
You need to use only apple PDF viewer afaik. I dont know if I am wrong here. (Please correct me in this case)
To open PDF in iBook app, use this code
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 to register an app to respond to a custom URL scheme opening request?

Like this:
NSString *stringURL = #"appname://";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
I slightly remember it was necessary to write a value-key to Info.plist. How?
Add this to plist .
The app will by called by #"readtext://" url
This seems to be the question that I answered (with screenshots & source code) here.
And I've posted a full walkthrough of how to do this on my blog.

How to move the user to a URL in Safari

I am making an app for a charity and Apple's review guidelines state that all donations must be made outside of the app in Safari, except for SMS donations, which we're not doing anyway. How do I make a button, that when tapped, goes to a specific URL in Safari? Thanks for your help!
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"your.website.here"]];
And put it in an IBAction for your button.
There might be a problem connecting to your site try this:
NSURL *url = [NSURLWithString:#"your.website.here"];
if (![[UIApplication sharedApplication] openURL:url])
NSLog(#"%#%#",#"Failed to open url:",[url description]);
They actually have a post on it here:
How can I launch Safari from an iPhone app?
You can use this code in button click event
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: #"your url"]];
it automatically opens in safari

SMS body in iphone SDK

I need to send an SMS from my iphone app. the body of the SMS is created programatically. so when i tap on a button the SMS application should get opened with my message pre-typed in it. anybody knows how to do it? need help
Thanks in advance.
Shibin
You can't set the SMS body. The only things you can do from your code, as per the official SDK, is 1) to open the SMS application:
NSString *stringURL = #"sms:";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
and 2) to set the phone number for a new message:
NSString *stringURL = #"sms:+12345678901";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
You can set the body in iOS 4. Please cf the documentation.

iPhone: Open a url Programmatically

I am new to iPhone.
I want to open an url in my application.
How can I do this task? Please suggest me and provide some useful link.
Apparently the link given above is outdated. Here is the update link for the UIApplication class.
The quick and simple code snippet is:
// ObjC
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: #"http://www.google.com"]];
// Swift
UIApplication.shared.open(URL(string: "http://www.google.com")!, options: [:], completionHandler: nil)
Update (2016): The best way to do this nowadays is to instantiate and present an SFSafariViewController. This gives the user the security and speed of Safari, and access to any cookies or Safari features they may already have set without having to leave your app.
If you want to open the URL in Safari (and exit your application) you can use the openURL method of UIApplication
If you'd rather have it handled inside of your app, use WKWebView.
If you would like to open and just get the data from the URL, you could use NSString:
NSString *ans = [NSString stringWithContentsOfURL:url];
If what you are trying to get is an XML from a URL, you can directly use NSXMLParser:
NSURL *url = [[NSURL alloc] initWithString:urlstr];
NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
// parse here
[parser release];
[url release];
On the other hand, if by opening you mean, open a URl in an embedded browser, you could use UIWebView class.
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"https://medium.com/the-traveled-ios-developers-guide/swift-3-feature-highlight-c38f94359731#.83akhtihk"]]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"https://medium.com/the-traveled-ios-developers-guide/swift-3-feature-highlight-c38f94359731#.83akhtihk"]];
}
else{
[SVProgressHUD showErrorWithStatus:#"Please enable Safari from restrictions to open this link"];
}