我的应用程序使用标准 sharedApplication.OpenURL 直接打开 iTunes Affiliate 链接。但是,Apple 建议使用以下代码。
是否有支持 Xamarin 的 C# 版本?
// Process a LinkShare/TradeDoubler/DGM URL to something iPhone can handle
(void)openReferralURL:(NSURL *)referralURL
{
NSURLRequest *theRequest=[NSURLRequest requestWithURL:referralURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
[conn release];
}
// 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) {
NSMutableURLRequest *r = [[request mutableCopy] autorelease]; // original request
[r setURL: [request URL]];
self.iTunesURL = [r URL];
if ([self.iTunesURL.host hasSuffix:@"itunes.apple.com"]) {
[[UIApplication sharedApplication] openURL:self.iTunesURL];
}
return r;
} else {
return request;
}
}