2

I've managed to addSubview: a UIProgressView in/onto a UIAlertView, as well as set everything for ASIHTTPRequest, but where-ever I put the [request startSynchronous];, it crashes the app.

[request startAsynchronous]; doesn't help either.

Thanks.

Here's what I have so far;

There is a check that checks if the file exists etc, which works, but I've removed it for the sake of this question.

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

Call stack;

#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();

Pdantix
  • 23
  • 1
  • 4
  • Even a crash log would be more helpful for us to understand your problem :-) – Di Wu Jan 05 '11 at 08:33
  • There wasn't one, now there is. :3 Added. – Pdantix Jan 05 '11 at 08:47
  • 1
    You'll need to symbolicate the crash report for it to be useful, or provide the stacktrace from the debugger. You'll definitely want to make the call asynchronous: a synchronous call will lock up the UI and your progressView won't do anything useful. – Matthew Frederick Jan 05 '11 at 08:59
  • Not that it's a direct solution to your problem, but I'm using DSActivityView with ASIHTTPRequest in an app and they get along great. http://www.dejal.com/developer/dsactivityview – Matthew Frederick Jan 05 '11 at 09:00
  • It seems I don't have the symbolicatecrash script/app anywhere on my computer. And the debugger returns nothing. I'd use MBProgressHUD, which is similar to DSActivityView, but the UIProgressView just looks nice. :) – Pdantix Jan 05 '11 at 09:15
  • symbolicatecrash should be in /Developer/Platforms/iPhoneOS.platform/Developer/Library/PrivateFrameworks/DTDeviceKit.framework/Versions/A/Resources/symbolicatecrash – JosephH Jan 05 '11 at 10:54
  • Ah, I was looking in an old location. – Pdantix Jan 05 '11 at 11:27
  • Superb..i have worked it out well..... – user2136 Dec 27 '11 at 04:07

1 Answers1

2

Without the call stack it's hard to say what the exact problem is.

However this code is potentially worrying:

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

The "release" call should be moved to after the dismissWithClickedButtonIndex. However I think it's unlikely this is the cause of the crash.

I see the problem now've posted the stack dump:

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

should be:

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

To be honest, I'm very surprised the compiler wasn't giving you a warning about that.

JosephH
  • 37,173
  • 19
  • 130
  • 154
  • Now this makes the alert popup, then just as it does, the app crashes. I'd paste a log from the debugger, but there's nothing to paste. – Pdantix Jan 05 '11 at 09:22
  • @Pdantix - the debugger really should be showing you a callstack for the location of the crash - check you are running in the debugger, are looking at the debugger window (the run->debugger menu), etc – JosephH Jan 05 '11 at 10:52
  • "To be honest, I'm very surprised the compiler wasn't giving you a warning about that." -- Oh, I'm pretty sure it has to have been. The lesson, @Pdantix, is never to ignore compiler warnings. – Dan Ray Jan 05 '11 at 13:17