gpt4 book ai didi

iphone - Xamarin iTunes 附属链接

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:08:51 26 4
gpt4 key购买 nike

我的应用程序直接使用标准的 sharedApplication.OpenURL 打开 iTunes 附属链接。但是,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;
}

}

最佳答案

找不到现有的 API,所以我写了它:

尽情享受吧!

    NSUrlRequest theRequest;
NSUrlConnection conn;

void Process (NSUrl url)
{
theRequest = new NSUrlRequest (url, NSUrlRequestCachePolicy.UseProtocolCachePolicy, 30);
var del = new LinkDelegate ();
conn = new NSUrlConnection (theRequest, del);
conn.Start ();
}
}

class LinkDelegate: NSUrlConnectionDelegate
{

public override NSUrlRequest WillSendRequest (NSUrlConnection connection, NSUrlRequest request, NSUrlResponse response)
{
if (response!=null) {
var url = request.Url;
if (url.Host.ToLower ().Contains ("itunes.apple.com"))
UIApplication.SharedApplication.OpenUrl (url);
return NSUrlRequest.FromUrl (url);
} else {
return request;
}
}
}

关于iphone - Xamarin iTunes 附属链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18816849/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com