Search code examples
iosexcelms-wordnsdatansurl

+URLWithString: returns nil


Im using QLPreviewController to view word, excel,pdf etc. The problem is the file is in the server so I need to download it from a certain URL.

I'm using this code:

NSURL *dLurl = [NSURL URLWithString:[NSString stringWithFormat:@"%@",DLPathStr]];
NSData *data = [NSData dataWithContentsOfURL:dLurl];

for downloading files, It works for the PDF file but in the word and excel files it doesn't work I'm not able to download anything.


Solution

  • I fixed it by using this code it doesn't download anything because the URL is wrong because it contains spaces.

    NSString *str = [DLPathStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSURL *dLurl = [NSURL URLWithString:[NSString stringWithFormat:@"%@",str]];