問題: このプロセスは、iOS6 では問題なく機能しました。現在は、最新の情報を取得せず、表示されているデータを置き換えます。そのため、アプリケーション情報は常に間違っています。シミュレーターの内容をリセットすると、その時点で機能します。その後、コンテンツを再度リセットする必要があります。助言がありますか。参照用に、すべてのデータ処理を処理する 3 つのファイルを含めました。
Reader.M
- (void) startRequest
{
NSURL *url = [[NSURL alloc] initWithString:@"http://www.something.com/app/rss/"];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url cachePolicy:NSURLCacheStorageNotAllowed timeoutInterval:60.0f];
NSURLConnection *conn = [[NSURLConnection alloc]initWithRequest:request delegate:self startImmediately:YES];
if(conn)
{
_receivedData = [[NSMutableData alloc]init];
}
}
#pragma mark - NSURLConnectionDataDelegate
- (void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(@"%@",error.description);
}
- (void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
NSLog(@"received %d bytes",data.length);
[_receivedData appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSXMLParser *parser = [[NSXMLParser alloc] initWithData:_receivedData];
JSTRRSSParser *rssParser = [[JSTRRSSParser alloc] init];
parser.delegate = rssParser;
[parser parse];
NSMutableArray *articleList = [rssParser getParsedList];
NSLog(@"%@", articleList);
NSString *fileName = [NSString stringWithFormat:@"%@/popular.rss", [JSTRRSSUtil getDocumentRoot]];
[articleList writeToFile:fileName atomically:YES];
}
@end
パーサー.m
#import "JSTRRSSParser.h"
@implementation JSTRRSSParser
- (id) init
{
self = [super init];
if (self) {
// custom initializer
_list = [[NSMutableArray alloc] init];
}
return self;
}
- (NSMutableArray *)getParsedList
{
return _list;
}
#pragma mark - implement NSXMLParserDelegate
- (void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict
{
if ([elementName isEqualToString:@"item"]) {
_item = [[NSMutableDictionary alloc]init];
[_item setValue:[[NSMutableArray alloc] init] forKey:@"category"];
[_list addObject:_item];
_foundItem = YES;
}
if([elementName isEqualToString:@"image"] ||
[elementName isEqualToString:@"slider"] ||
[elementName isEqualToString:@"title"] ||
[elementName isEqualToString:@"link"] ||
[elementName isEqualToString:@"description"] ||
[elementName isEqualToString:@"category"] ||
[elementName isEqualToString:@"sliderphoto"] ||
[elementName isEqualToString:@"linkId"]||
[elementName isEqualToString:@"pubDate"]||
[elementName isEqualToString:@"sliderpriority"]||
[elementName isEqualToString:@"pageorder"]||
[elementName isEqualToString:@"sectionalphoto"]) {
_tempStore = [[NSMutableString alloc] init];
}
}
- (void) parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if (_foundItem) {
[_tempStore appendString:string];
}
}
- (void) parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if (_foundItem) {
if([elementName isEqualToString:@"item"]) {
_foundItem = NO;
return; // don't preceed
}
// trim whitespace from left and right and replace commonly encoded html string
NSString *content = [_tempStore stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceCharacterSet]];
content = [content stringByReplacingOccurrencesOfString:@" " withString:@""];
content = [content stringByReplacingOccurrencesOfString:@"&" withString:@"&"];
content = [content stringByReplacingOccurrencesOfString:@""" withString:@"\""];
content = [content stringByReplacingOccurrencesOfString:@"­" withString:@"-"];
content = [content stringByReplacingOccurrencesOfString:@"»" withString:@">>"];
content = [content stringByReplacingOccurrencesOfString:@"·" withString:@"-"];
content = [content stringByReplacingOccurrencesOfString:@"<" withString:@"<"];
content = [content stringByReplacingOccurrencesOfString:@">" withString:@">"];
content = [content stringByReplacingOccurrencesOfString:@"<br /> <br />" withString:@"\n"];
content = [content stringByReplacingOccurrencesOfString:@"—" withString:@"-"];
content = [content stringByReplacingOccurrencesOfString:@"’" withString:@"'"];
content = [content stringByReplacingOccurrencesOfString:@"“" withString:@"'"];
content = [content stringByReplacingOccurrencesOfString:@"‘" withString:@"'"];
content = [content stringByReplacingOccurrencesOfString:@"–" withString:@"-"];
if( [elementName isEqualToString:@"slider"] ) {
[_item setObject:content forKey:@"slider"];
} else if( [elementName isEqualToString:@"image"] ) {
[_item setObject:content forKey:@"image"];
} else if( [elementName isEqualToString:@"title"] ) {
[_item setObject:content forKey:@"title"];
} else if ( [elementName isEqualToString:@"link"]) {
[_item setObject:content forKey:@"link"];
} else if ( [elementName isEqualToString:@"description"]) {
[_item setObject:content forKey:@"description"];
} else if ( [elementName isEqualToString:@"category"]) {
NSMutableArray *temp = (NSMutableArray *)[_item objectForKey:@"category"];
[temp addObject:content];
} else if ( [elementName isEqualToString:@"sliderphoto"]) {
[_item setObject:content forKey:@"sliderphoto"];
} else if ( [elementName isEqualToString:@"linkId"]) {
[_item setObject:content forKey:@"linkId"];
} else if ( [elementName isEqualToString:@"pubDate"]) {
[_item setObject:content forKey:@"pubDate"];
} else if ( [elementName isEqualToString:@"sliderpriority"]) {
[_item setObject:content forKey:@"sliderprioroty"];
} else if ( [elementName isEqualToString:@"sectionalphoto"]) {
[_item setObject:content forKey:@"sectionalphoto"];
} else if ( [elementName isEqualToString:@"pageorder"]) {
[_item setObject:content forKey:@"pageorder"];
}
}
}
UTIL.h
+ (NSString *) getDocumentRoot
{
// search for available path and return first
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
return [paths objectAtIndex:0];
}
さらに、コンテンツがリセットされない場合、リーダーでさえ RSS フィードから正しい情報を取得できません。