-3

i want to download file from web server and for that I need
1. send request for file path to web service method
2. receive this path on iphone side
3. now convert this path into NSURL
4. and finally send the request to web server for file download

right now i am doing all above but user have to
1. GetURL button and then
2. Download button

I want all this in one button click.

I tried for this too but problem is:

DownlloadButtonClick  
{  
   [self getURL];  
   [self DownloadFile];  
} 
getURL{  
    soapmsg  
    NSURL  
    NSURLReuest  
    ...  
    ..  
    ..  
} 

//after this i was expecting that connection should be done and data(filepath) will be received, but this not happen

after getURL() method its back to above and call DownloadFile() and then app will crash...
app is crash this is accepted as i know its depend on getURL() method..

now my problem is where should i place getURL() method and DownloadFile() method so i can execute both on one click

thank you in advance

2
  • Your question ('que'?) is hard to answer as it isn't very well stated. And your app is crashing but this isn't actually the problem?
    – occulus
    Feb 25, 2011 at 13:03
  • right my app is crashing and thats not problem for me because i know why this happen but my main problem is i want to do all 4 (or you can say execute 2 methods )steps in one click...
    – Pooja
    Feb 25, 2011 at 13:08

1 Answer 1

0

If I've understood your hard to decipher question correctly...

Your problem seems to be that you want to do an asynchronous action - getURL - and then when that has completed, another action. In your DownlloadButtonClick method, you want to think about only calling getURL (and not DownloadFile yet). In whatever code you have for handling the result of getURL (i.e. the URL has been fetched), you can then kick off your DownloadFile action.

5
  • i did this, -(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { if( [elementName isEqualToString:@"getURLResponse"]) { NSLog(@"soapResults : %@",soapResults); UrlForDownload = soapResults; soapResults=nil; [self DownloadFile]; } } if i am doing so app is crashing
    – Pooja
    Feb 25, 2011 at 13:30
  • You don't want to kick off something like a sychronous download right in the middle of some XML parsing code, which may already be on the main runloop. How does DownloadFile work? Is it synchronous or asynchronous? If it is synchronous, you want to not be doing that on the main thread.
    – occulus
    Feb 25, 2011 at 13:38
  • I'm trying to help you help yourself here, so without pasting more code, can you tell me if the fragment you posted is synchronous or asynchronous? If you don't understand those concepts, you should make sure you do, as it will be of use to you in the future.
    – occulus
    Feb 25, 2011 at 13:53
  • Ok, cool, it is asynchronous. "Chaining" your communications so that the result of the first request coming back kicks off your second request is the way to go. I'm afraid I have no idea why your app is crashing and with the very limited info you provide, I can't help any further. The more info you provide in your questions, and the more clearly you state them, the more other people will be able to help you. I strongly recommend reading at least some of this: catb.org/~esr/faqs/smart-questions.html
    – occulus
    Feb 25, 2011 at 22:49
  • In fact, before looking at the above link, check out this one first: msmvps.com/blogs/jon_skeet/archive/2010/08/29/…
    – occulus
    Feb 26, 2011 at 1:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.