Reliably opening App Store links from a UIWebView

有些话、适合烂在心里 提交于 2019-11-29 01:26:18
Jasarien

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.

On my tests, I only got phobos.apple.com links to automatically redirect to the AppStore (without any Safari redirect).

petershine

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;
}

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.

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];
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!