iOS UIWebView 的 RSS 看起来更像 Safari 并留在应用程序中

发布于 2024-11-14 20:57:52 字数 1157 浏览 6 评论 0原文

我正在创建一个 RSS 阅读器应用程序...但我注意到 UIWebView 呈现 RSS 提要的方式与 Safari 非常不同。

这是 RSS 提要... http://www.sigmapi2.org/index.html php?option=com_ninjarsssyndicator&feed_id=2&format=raw

这就是我希望 UIWebView 的外观就像...这是 iOS 的 Mobile Safari 的屏幕截图 在此处输入图像描述

NSURL *url = [NSURL URLWithString:@"http://www.sigmapi2.org/index.php?option=com_ninjarsssyndicator&feed_id=1&format=raw"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView1 loadRequest:request];}

在 UIWebView 中生成一个空白页面

下面的代码...(地址取自 mobile safari像我想要的那样加载了 RSS 提要)...

    NSURL *url = [NSURL URLWithString:@"http://reader.mac.com/mobile/v1/www.sigmapi2.org/index.php?option=com_ninjarsssyndicator&feed_id=1&format=raw"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView1 loadRequest:request];}

显示了这个... 在此处输入图像描述

任何帮助将不胜感激。

Im creating an RSS reader app...but I have noticed that UIWebView renders the RSS feed very differently than Safari does.

This is the RSS feed...
http://www.sigmapi2.org/index.php?option=com_ninjarsssyndicator&feed_id=2&format=raw

This is what I want my UIWebView to look like...this is a screenshot from iOS' Mobile Safari
enter image description here

NSURL *url = [NSURL URLWithString:@"http://www.sigmapi2.org/index.php?option=com_ninjarsssyndicator&feed_id=1&format=raw"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView1 loadRequest:request];}

produces a blank page in the UIWebView

And this code below...(Address taken from mobile safari when it loaded the RSS feed like I wanted it to)...

    NSURL *url = [NSURL URLWithString:@"http://reader.mac.com/mobile/v1/www.sigmapi2.org/index.php?option=com_ninjarsssyndicator&feed_id=1&format=raw"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView1 loadRequest:request];}

shows this...
enter image description here

any help would greatly be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

铁憨憨 2024-11-21 20:57:52

您需要创建一个 XML 解析器。 UIWebView 不具备与 Safari 相同的功能。我发现的最好的 XML 解析器在这里: https://github.com/mwaterfall/MWFeedParser

You need to create an XML Parser. The UIWebView does not have the same capabilities as Safari. The best XML parser I found is here: https://github.com/mwaterfall/MWFeedParser

£噩梦荏苒 2024-11-21 20:57:52

您需要实现一个必须与 baseurl 不同的 url。

NSString * userAgent = @"Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+                  (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3";
NSString * urlString = @"http://reader.mac.com";
NSURL *URL = [NSURL URLWithString:urlString];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:URL];
[req setValue:userAgent forHTTPHeaderField:@"User-Agent"];
NSURLResponse* response = nil;
NSError* error = nil;
NSData* data = [NSURLConnection sendSynchronousRequest:req
                                         returningResponse:&response
                                                     error:&error];
[self.article loadData:data MIMEType:@"text/html" textEncodingName:@"utf-8" baseURL:URL];

You need to implement a url that must be different than the baseurl.

NSString * userAgent = @"Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+                  (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3";
NSString * urlString = @"http://reader.mac.com";
NSURL *URL = [NSURL URLWithString:urlString];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:URL];
[req setValue:userAgent forHTTPHeaderField:@"User-Agent"];
NSURLResponse* response = nil;
NSError* error = nil;
NSData* data = [NSURLConnection sendSynchronousRequest:req
                                         returningResponse:&response
                                                     error:&error];
[self.article loadData:data MIMEType:@"text/html" textEncodingName:@"utf-8" baseURL:URL];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文