gpt4 book ai didi

javascript - UIWebview javascript 仅在发布版本中失败

转载 作者:行者123 更新时间:2023-11-30 12:58:16 24 4
gpt4 key购买 nike

我正在尝试将我的 Backbone 应用程序的 javascript 手动注入(inject)到 UIWebview 中(为了避免客户端在应用程序启动时下载 1MB 的 JS 文件)。

下面的代码在应用程序的 DEBUG 版本中运行得非常好,但是一旦构建了 Ad Hoc 发布版本并对其进行测试,应用程序就无法正确加载。我认为这是某处的 JS 错误,但我不知道如何调试在发布版本中运行的 UIWebview(据我所知,Safari 开发工具只能在调试中使用)。

- (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]
}

关于为什么这会在 RELEASE 模式下失败的任何想法?关于如何在发布版本中测试 UIWebview javascript 错误的任何建议?

最佳答案

尝试删除以下行:

NSString *jsCode = [NSString stringWithFormat:@"var script=document.createElement('script'); script.type='text/javascript'; script.text=\"%@\"; document.head.appendChild(script);", code];

所以你会得到这个:

- (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]
}

关于javascript - UIWebview javascript 仅在发布版本中失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18305872/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com