iOS UIWebView of RSS to look more like Safari and

2019-05-04 03:32发布

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.

2条回答
姐就是有狂的资本
2楼-- · 2019-05-04 04:08

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];
查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-05-04 04:20

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

查看更多
登录 后发表回答