如何从iOS上
问题描述:
非HTTP URL数据我正在开发一个应用程序,获取RSS从网站订阅和URL具有以下形式:如何从iOS上
feed://feeds.<a_site_name>.org/...
因为它不是一个HTTP协议,当我使用NSURLConnection和NSUrlRequest获取数据时,它总是返回零数据。
NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:feedURL] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60];
NSOperationQueue *aqueue = [[[NSOperationQueue alloc] init] autorelease];
[NSURLConnection sendAsynchronousRequest:request queue:aqueue completionHandler:^(NSURLResponse *response, NSData *resultJsonData, NSError *error)
{
}];
我用ASIHttpRequest第三方库来获得,它的工作原理,但我不想在这里使用第三方库。
我可以使用任何给定的iOS框架或任何简单的代码来获取?
答
A feed://
URL实际上只是一个HTTP或HTTPS URL,但打算由知道如何处理RSS提要的应用读取。解决此问题的方法是将URL方案更改为http
(如果可能,则为https
)。例如:
NSURLComponents *components = [NSURLComponents componentsWithURL:feedURL
resolvingAgainstBaseURL:YES];
components.scheme = @"https";
feedURL = [components URL];
然后尝试URL,如果失败,改变计划,HTTP,然后再试一次。