1

我正在使用以下代码

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSURL *myUrl = [[NSURL alloc] initWithString:self.selectedRing.ringThumbNailImagePath];
[Utilities responseDataFromURL:myUrl completionBlock:^(NSData *fileData, NSError *err)
{
    if (err != nil)
    {
        [self.indicator stopAnimating];
        [Utilities errorDisplay:@""];
    }
    else
    {
        NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Test.igo"];
        NSLog(@"FilePath: %@", filePath);

        if ([fileData writeToFile:filePath atomically:YES])
        {
            CGRect rect = CGRectMake(0 ,0 , 0, 0);    
            NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@", filePath]];
            NSLog(@"JPG path %@", filePath);

文件路径是

Users/umar/Library/Application Support/iPhone Simulator/6.1/Applications/B45223CF-B437-4617-A02D-DCA91C965A5A/Documents/Test.igo

但是我得到了 Nil igImageHookFile NSURL。怎么了?

4

2 回答 2

5

用于fileURLWithPath将您的文档目录路径转换为 ​​NSURL,如下所示:

NSURL *myImagePath = [NSURL fileURLWithPath:filePath]; //here filePath is your document directory full path with extantionm

例如:

NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Test.igo"];
        NSLog(@"FilePath: %@", filePath);

        if ([fileData writeToFile:filePath atomically:YES])
        {
            CGRect rect = CGRectMake(0 ,0 , 0, 0);   

            NSURL *igImageHookFile = [NSURL fileURLWithPath:filePath]; 

            NSLog(@"URL from path %@", igImageHookFile);

路径 URL 的输出如下所示:-

file://localhost/Users/umar/Library/Application Support/iPhone Simulator/6.1/Applications/B45223CF-B437-4617-A02D-DCA91C965A5A/Documents/Test.igo
于 2013-09-13T07:37:20.050 回答
-1

尝试这个:

NSURL *url = [NSURL URLWithString:[Request stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]];

希望能帮助到你!!

于 2013-09-13T07:30:36.317 回答