Reputation: 771
I'm trying to manually inject the javascript for my Backbone app into a UIWebview (in order to save the client from downloading a 1MB JS file when the app boots).
The code below works perfectly fine in DEBUG builds of the app, but as soon as build an Ad Hoc release build and test that out, the app doesn't load properly. I assume it is a JS error somewhere but I don't know how to debug a UIWebview running in a release build (the Safari dev tools only work in Debug as far as I could tell).
- (void)webViewDidFinishLoad:(UIWebView *)webView {
// Inject the JS
NSLog(@"Injecting JS 1 from disk");
NSString *path = [[NSBundle mainBundle] pathForResource:@"backbone_application" ofType:@"js"];
NSString *code = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
NSString *jsCode = [NSString stringWithFormat:@"var script=document.createElement('script'); script.type='text/javascript'; script.text=\"%@\"; document.head.appendChild(script);", code];
[self.webPortal stringByEvaluatingJavaScriptFromString:jsCode]
}
Any ideas on why this would be failing in RELEASE mode? Any suggestion on how to test for UIWebview javascript errors in a release build?
Upvotes: 1
Views: 843
Reputation: 34
Try removing the following line:
NSString *jsCode = [NSString stringWithFormat:@"var script=document.createElement('script'); script.type='text/javascript'; script.text=\"%@\"; document.head.appendChild(script);", code];
So you'll have this:
- (void)webViewDidFinishLoad:(UIWebView *)webView {
// Inject the JS
NSLog(@"Injecting JS 1 from disk");
NSString *path = [[NSBundle mainBundle] pathForResource:@"backbone_application" ofType:@"js"];
NSString *code = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
[self.webPortal stringByEvaluatingJavaScriptFromString:code]
}
Upvotes: 1
Reputation: 918
There are settings on both the project and target of your code for each build mode. It sounds to me that you have one or more settings for DEBUG mode that are not the same as RELASE mode. Double check to see if any setting is different, other way to prove this is to create an Archive for Ad Hoc distribution in DEBUG mode (You can edit that on your Scheme Editing Dialog.) If this new .IPA runs as expected then for sure you have different settings for DEBUG/RELEASE.
Hope this helps,
Upvotes: 1