【问题标题】:iOS UIWebView of RSS to look more like Safari and stay inside appRSS 的 iOS UIWebView 看起来更像 Safari 并留在应用程序中
【发布时间】:2011-06-09 02:58:02
【问题描述】:

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

这是 RSS 提要... http://www.sigmapi2.org/index.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 中生成一个空白页面

下面的代码...(当它像我想要的那样加载 RSS 提要时从移动 safari 获取的地址)...

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

显示这个...

任何帮助将不胜感激。

【问题讨论】:

    标签: ios4 rss uiwebview mobile-safari


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      你需要实现一个与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];
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-03-27
        • 1970-01-01
        • 1970-01-01
        • 2017-03-19
        • 1970-01-01
        • 1970-01-01
        • 2016-01-09
        • 2023-03-29
        相关资源
        最近更新 更多