From 9e133e4c96b8354392263681562478db6901ceeb Mon Sep 17 00:00:00 2001 From: Danny Greg Date: Sat, 18 Feb 2012 22:35:00 +0000 Subject: [PATCH] Add basic token replacement to our custom HTML. --- AppDelegate.m | 13 ++++++++++++- cover.html | 3 ++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/AppDelegate.m b/AppDelegate.m index 552785e..313e763 100644 --- a/AppDelegate.m +++ b/AppDelegate.m @@ -14,6 +14,8 @@ #import #import +NSString *const AppDelegateHTMLImagePlaceholder = @"#{IMAGE_URL}#"; + @implementation AppDelegate @synthesize window = _window; @@ -54,7 +56,16 @@ -(void) setTheLoopCount:(int)theLoopCount - (void)awakeFromNib { NSURL *htmlFileURL = [[NSBundle mainBundle] URLForResource:@"cover" withExtension:@"html"]; - [self.coverWebView setMainFrameURL:[htmlFileURL absoluteString]]; + NSError *err = nil; + NSMutableString *html = [NSMutableString stringWithContentsOfURL:htmlFileURL encoding:NSUTF8StringEncoding error:&err]; + if (html == nil) { + //Do something with the error + NSLog(@"%@", err); + return; + } + + [html replaceOccurrencesOfString:AppDelegateHTMLImagePlaceholder withString:@"blah" options:0 range:NSMakeRange(0, html.length)]; + [self.coverWebView.mainFrame loadHTMLString:html baseURL:nil]; } - (void)applicationDidFinishLaunching:(NSNotification *)aNotification diff --git a/cover.html b/cover.html index a3c1276..4b27c4f 100644 --- a/cover.html +++ b/cover.html @@ -1,4 +1,5 @@ -

Hello World!

+

Hello World!

+ \ No newline at end of file