0

I have this url, an audio file http://www.metrixzolutions.com/audio/1353301873.caf I check the url on browser, it's an audio data file.

However, when I do this

   NSString* Path;
Path=@"http://www.metrixzolutions.com/audio/1353301873.caf";
NSURL *url = [NSURL fileURLWithPath:Path];
NSData *downloadData = [NSData dataWithContentsOfURL:url];

The downloadData is nil, and saying it's not a NSdata, why?

2 Answers 2

2

Because this URL doesn't represent a filesystem path. Try using NSURL *url = [NSURL URLWithString:Path]; and it should be fine.

And next time please make the effort to read attentively the correspoding documentation.

1

If you want to get data from the web you can implement NSURLRequest and NSURLConnection.

NSString *path = @"http://www.metrixzolutions.com/audio/1353301873.caf";
NSURL *url = [NSURL URLWithString:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];


[NSURLConnection sendAsynchronousRequest:request
                 queue:[NSOperationQueue mainQueue]
                 completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {

    NSLog(@"%@", data); //<-- this is your data

}];
1
  • "you need to implement..." - you needn't, the error is not there.
    – user529758
    Nov 25, 2012 at 20:03

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.