iPhone Dev: UIWebView baseUrl to resources in Documents folder not App bundle

后端 未结 3 1944
-上瘾入骨i
-上瘾入骨i 2020-12-01 04:52

Greetings! Can anyone please kindly assist me finding a way around the following:

  • load an html into a UIWebView using loadHTMLString and incl
3条回答
  •  忘掉有多难
    2020-12-01 05:30

     // call this method and set the directory , Currently it is cache directory . If you want document directory then change NSCacheDirectory to NSDocumentDirectory
    
    -(NSString*)getBasePath
    {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory,
                                                         NSUserDomainMask, YES);
    NSMutableString *cacheDirectory = [NSMutableString stringWithString:[paths objectAtIndex:0]];
    
    [cacheDirectory appendString:@"/"];
    NSRange renge= NSMakeRange(0, cacheDirectory.length);
    [cacheDirectory replaceOccurrencesOfString:@"/" withString:@"//" options:NSCaseInsensitiveSearch range:renge];
    renge= NSMakeRange(0, cacheDirectory.length);
    [cacheDirectory replaceOccurrencesOfString:@" " withString:@"%20" options:NSCaseInsensitiveSearch range:renge];
    [cacheDirectory insertString:@"file://" atIndex:0];
    //file:////Users//hb//Library//Application%20Support//iPhone%20Simulator//6.0//Applications//3A141D33-390A-4DD2-8825-7DDC07D29894//Library//Caches//
    return cacheDirectory;
    

    }

提交回复
热议问题