Created
November 14, 2014 20:10
-
-
Save ben-ng/1efc627fe74aa66f2e93 to your computer and use it in GitHub Desktop.
Use UIWebView's `loadHTMLString:baseURL:` and set the baseURL to where your assets are in the app bundle. Then replace all absolute paths in your html/js/css with relative ones using something like the script below. The relative URLs will be loaded relative to the baseURL, whereas absolute ones are loaded relative to the root of the filesystem, …
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This doodad converts absolute paths like "/assets/thing.jpg" into relative ones like "assets/thing.jpg" | |
NSString * (^fixPrefix)(NSString *, NSString *) = ^NSString *(NSString * input, NSString *prefix) { | |
NSString *needle = [[@"/" stringByAppendingString:prefix] stringByAppendingString:@"/"]; | |
NSString *replacement = [prefix stringByAppendingString:@"/"]; | |
input = [input stringByReplacingOccurrencesOfString:[@"'" stringByAppendingString:needle] withString:[@"'" stringByAppendingString:replacement]]; | |
input = [input stringByReplacingOccurrencesOfString:[@"\"" stringByAppendingString:needle] withString:[@"\"" stringByAppendingString:replacement]]; | |
input = [input stringByReplacingOccurrencesOfString:[@"(" stringByAppendingString:needle] withString:[@"(" stringByAppendingString:replacement]]; | |
return input; | |
}; | |
fileContents = fixPrefix(fileContents, @"assets"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment