iphone - detachNewThreadSelector 使应用程序随机崩溃

标签 iphone objective-c rss threadpool pool

我正在开发一个 iphone 应用程序,我在其中提取 RSS 提要然后解析它们。我的代码如下所示:

 - (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    NSLog(@"in view did appear");

    if ([stories count] == 0) {
        NSString * path = @"http://www.shire.com/shireplc/rss.jsp";

        //[self parseXMLFileAtURL:path];
        //[self performSelectorInBackground:@selector(parseXMLFileAtURL:) withObject:path];
        NSLog(@"internet is %d",[self checkInternet]);
        if([self checkInternet]==1)
        [NSThread detachNewThreadSelector:@selector(parseXMLFileAtURL:) 
                              toTarget:self withObject:path];

}
}

 - (void)parseXMLFileAtURL:(NSString *)URL
  { 
  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  stories = [[NSMutableArray alloc] init];

  //you must then convert the path to a proper NSURL or it won't work
  NSURL *xmlURL = [NSURL URLWithString:URL];

  // here, for some reason you have to use NSClassFromString when trying to alloc NSXMLParser, otherwise you will get an object not found error
  // this may be necessary only for the toolchain
  rssParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];

  // Set self as the delegate of the parser so that it will receive the parser delegate methods callbacks.
[rssParser setDelegate:self];

// Depending on the XML document you're parsing, you may want to enable these features of NSXMLParser.
[rssParser setShouldProcessNamespaces:NO];
[rssParser setShouldReportNamespacePrefixes:NO];
[rssParser setShouldResolveExternalEntities:NO];

[rssParser parse];

 [pool release];

}

谁能告诉我哪里出错了? 我的日志如下: 日志:[切换到线程 12803] [切换到线程 12035] 2011-05-10 11:31:30.932 年度报告 [454:490b] 找到文件并开始解析 [切换到线程 14339] 2011-05-10 11:32:04.742 年度报告 [454:640b] 找到文件并开始解析 [切换到线程 13827] [切换到线程 13827] 程序收到信号:“EXC_BAD_ACCESS”。

gdb stack trace at 'putpkt: write failed':
0   gdb-arm-apple-darwin                0x0019026b remote_backtrace_self + 54

最佳答案

我不确定,但我猜该方法的参数会在某个时候被释放。您能否确保方法 parseXMLFileAtURL

中存在 URL

关于iphone - detachNewThreadSelector 使应用程序随机崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5938569/

相关文章:

iphone - NSMutableString 作为保留/复制

ios - 使用自定义 getter 和 setter 通过 ARC 发送消息到已释放实例

iPhone流式编程(CFStream) Hello World

iphone - 如何将表情符号和文本一起保存到 sqlite 数据库中

python - 如何使用 Python 格式化 pubDate

iphone - 在 UIWebView 中加载具有透明背景的 pdf

iphone - 无法读取 Xcode 4.2 中的符号错误

ios - 如何检测来自另一个类的 touchesBegan、touchesMoved、touchesEnded 事件

php - 用 PHP 解析 iTunes RSS Atom 提要?

xml - 如何在 Atom Feed 中显示项目照片?