【问题标题】:Using ASIHTTPRequest with a UIProgressView in a UIAlertView在 UIAlertView 中将 ASIHTTPRequest 与 UIProgressView 一起使用
【发布时间】:2011-01-05 08:26:02
【问题描述】:

我已经成功地将addSubview: 一个 UIProgressView 放入 / 到一个 UIAlertView 中,并为 ASIHTTPRequest 设置了所有内容,但是无论我把 [request startSynchronous]; 放在哪里,它都会使应用程序崩溃。

[request startAsynchronous]; 也无济于事。

谢谢。

这是我目前所拥有的;

有一个检查文件是否存在等检查,这是可行的,但为了这个问题,我已经删除了它。

-(IBAction) update {
    // define everything.
    NSString *script;
    script = [[[NSBundle mainBundle] bundlePath] stringByAppendingString:@"/myfile.txt"];

    NSURL *url = @"http://example.com/myfile.txt";

        UIAlertView *progressAlert = [[UIAlertView alloc] initWithTitle: @"Updating..." message: @"Please wait..." delegate: self cancelButtonTitle: nil otherButtonTitles: nil];

        progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(30.0f, 80.0f, 225.0f, 90.0f)];
        [progressAlert addSubview:progressView];
        [progressView setProgressViewStyle: UIProgressViewStyleBar];
        ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
        [request setDownloadDestinationPath:script];
        [request setDownloadProgressDelegate:progressView];
        [progressAlert show];
        [progressAlert release];
        [request startSynchronous];
        [progressAlert dismissWithClickedButtonIndex:0 animated:YES];
}

调用栈;

#0  0x010cda44 in CFURLCopyAbsoluteURL
#1  0x00cee0f4 in HTTPMessage::initialize
#2  0x00cee018 in CFHTTPMessageCreateRequest
#3  0x00016d91 in -[ASIHTTPRequest main] at ASIHTTPRequest.m:855
#4  0x000859a6 in __NSThreadPerformPerform
#5  0x0119a01f in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
#6  0x010f828b in __CFRunLoopDoSources0
#7  0x010f7786 in __CFRunLoopRun
#8  0x010f7240 in CFRunLoopRunSpecific
#9  0x010fa504 in CFRunLoopRun
#10 0x0001ae30 in +[ASIHTTPRequest runRequests] at ASIHTTPRequest.m:4286
#11 0x00070d4c in -[NSThread main]
#12 0x00070cd8 in __NSThread__main__
#13 0x9319785d in _pthread_start
#14 0x931976e2 in thread_start

3:request = CFHTTPMessageCreateRequest(kCFAllocatorDefault, (CFStringRef)[self requestMethod], (CFURLRef)[self url], [self useHTTPVersionOne] ? kCFHTTPVersion1_0 : kCFHTTPVersion1_1);

10:CFRunLoopRun();

【问题讨论】:

  • 即使是崩溃日志也会更有助于我们了解您的问题 :-)
  • 以前没有,现在有了。 :3 添加。
  • 您需要对崩溃报告进行符号化以使其有用,或者提供来自调试器的堆栈跟踪。你肯定想让调用异步:同步调用会锁定 UI,而你的 progressView 不会做任何有用的事情。
  • 并不是说它可以直接解决您的问题,但我在应用程序中使用 DSActivityView 和 ASIHTTPRequest 并且他们相处得很好。 dejal.com/developer/dsactivityview
  • 我的电脑上似乎没有 symbolicatecrash 脚本/应用程序。调试器什么也不返回。我会使用类似于 DSActivityView 的 MBProgressHUD,但 UIProgressView 看起来不错。 :)

标签: iphone cocoa-touch uialertview asihttprequest uiprogressview


【解决方案1】:

没有调用堆栈,很难说出确切的问题是什么。

但是这段代码可能令人担忧:

    [progressAlert release];
    [request startSynchronous];
    [progressAlert dismissWithClickedButtonIndex:0 animated:YES];

“释放”调用应该移到dismissWithClickedButtonIndex 之后。 但是我认为这不太可能是导致崩溃的原因。

我看到问题现在已经发布了堆栈转储:

NSURL *url = @"http://example.com/myfile.txt";

应该是:

NSURL *url = [NSURL URLWithString:@"http://example.com/myfile.txt"];

说实话,我很惊讶编译器没有就此发出警告。

【讨论】:

  • 现在这会弹出警报,然后就像它一样,应用程序崩溃了。我会从调试器中粘贴一条日志,但没有可粘贴的内容。
  • @Pdantix - 调试器确实应该向您显示崩溃位置的调用堆栈 - 检查您是否在调试器中运行,正在查看调试器窗口(运行->调试器菜单),等
  • “说实话,我很惊讶编译器没有给你一个警告。” ——哦,我很确定一定是这样。 @Pdantix 的教训是永远不要忽略编译器警告。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多