Reputation: 58468
I have an app that will display web pages within a UIWebView. The pages it shows may contain links to other iPhone apps on the App Store.
In a normal browser on a desktop computer, clicking these App Store links would take me through a number of URL redirects and eventually end up opening iTunes and taking me to the page for that App.
Is there a way to ensure that when an App Store link is clicked inside my UIWebView that the App Store app on the iPhone will open and show the app?
What I've been seeing in my tests is that there are several types of links that can result in an App Store page, those being:
When I open any of these links in a desktop browser they will work and eventually open iTunes. When I open any of these links from within the iPhone the UIWebView goes through a number of redirects and eventually one of two things will happen:
The only time I've been able to get the App Store app to open is by using a direct iTunes link to the app without any referral or redirects.
Obviously for referral or affiliate links, I do not want to strip out the referral ID or affiliate ID. I shouldn't deprive them of a referral if it was their link that is clicked.
So any help would be greatly appreciated.
Thanks.
Upvotes: 17
Views: 11941
Reputation:
I've been trying to do the same thing. I wanted to place a link to the full version of my app in the free version. I just confirmed that the method used in the document works. ONLY on the actual device. Never trust the simulator!
Add the stuff in the document, and call it like this :
NSString *testLink = @"http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=284417350&mt=8";
self.iTunesLink = [NSURL URLWithString:testLink];
[self openReferralURL:iTunesLink];
Upvotes: 1
Reputation: 3200
Addition to developer documentation, I think they should have the case when the redirectResponse
is nil
.
It took me some time to figure out what was wrong.
// Save the most recent URL in case multiple redirects occur
// "iTunesURL" is an NSURL property in your class declaration
- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response {
if (response) {
self.iTunesURL = [response URL];
}
else {
self.iTunesURL = [request URL];
}
return request;
}
Upvotes: 2
Reputation: 58468
I found this Technical Q&A from Apple that answers my question:
The basic gist is this:
phobos.apple.com links constructed properly will redirect directly to the App Store app. itunes.apple.com links must be converted into phobos links. referral/affiliate links must be traversed using NSURLConnection and the final resulting URL will be a phobos link that can be used.
Thanks for your help guys.
Upvotes: 13
Reputation: 35935
If you have not tested this yet on an actual device, I can tell you that the iPhone Simulator has problems with redirecting these links to the App Store (probably because the Simulator doesn't have it). Running you application on the device will yield different behaviors in this specific area, so make sure you're testing it there.
Upvotes: 1
Reputation: 25011
On my tests, I only got phobos.apple.com
links to automatically redirect to the AppStore (without any Safari redirect).
Upvotes: 3