Open yuzhoulangzik opened 9 years ago
What did you mean?
loadweb : function() { var webView = UIWebView.alloc().initWithFrame(self.view().frame()) webView.setDelegate(self) var url = NSURL.URLWithString("https://www.baidu.com/") var request = NSURLRequest.alloc().initWithURL(url) self.view().addSubview(webView) webView.loadRequest(request) }
![Uploading 屏幕快照 2015-07-14 上午11.18.20.png…]()
missed require()
var webView = require('UIWebView').alloc().initWithFrame(self.view().frame())
@albert438 had add require('UIWebView'),
@yuzhoulangzik Confirmed. I guess it's a conflict between JSPatch and UIWebvView, for both of them use JSCore.framework. It seems that it's unable to init UIWebView in JSPatch. I start the UIWebview in appdelegate
and it worked.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIWebView *view = [[UIWebView alloc]init]; //Useless. Just to load the UIWebview framework.
view.frame = CGRectZero;
[JPEngine startEngine];
//.......
return YES;
}
@albert438 //defineClass('UIWebView',{
// loadRequest :function(request){ // self.valueForKeyPath("documentView.webView.mainFrame.javaScriptContext") // self.ORIGloadRequest(request) // } // })
overwrite loadRequest it work
in our app, I write [JPEngine startEngine] in
and all the viewcontroller that contains a webview will crash.
I think [JSPatch startEngine] should be called after webview calss something init (lazy load).
Now we can use -performSelectorInOC
API to avoid the conflict of JavaScriptCore and UIWebView:
loadweb : function() {
return UIWebView.performSelectorInOC('new', [], function(ret) {
var webview = ret;
webView.setDelegate(self)
var url = NSURL.URLWithString("https://www.baidu.com/")
var request = NSURLRequest.alloc().initWithURL(url)
self.view().addSubview(webView)
webView.loadRequest(request)
})
}
@albert438 this can be work for me ,but send a new version to appstore
@bang590 问下邦神,在需要覆盖的方法里没有直接调用uiwebview,但是某些代码会唤起带webview的viewcontroller,这种情况应该对需要覆盖的整个方法执行performSelectorInOC 吗?
上段代码
defineClass("AppDelegate", {
application_openURL_sourceApplication_annotation: function(application, url, sourceApplication, annotation) {
if (url.absoluteString().isEqualToString("***://")) {
return 1
}
// self.ORIGapplication_openURL_sourceApplication_annotation(application, url, sourceApplication, annotation);
}
})
其中注释掉的那句,能否使用PerformSelectorInOC呢?
大神,UIWebView.performSelectorInOC这个api在初始化UIWebView之后,WebView里面的点击事件全部失效了!!
webview load html by jspatch has issue