bang590 / JSPatch

JSPatch bridge Objective-C and Javascript using the Objective-C runtime. You can call any Objective-C class and method in JavaScript by just including a small engine. JSPatch is generally used to hotfix iOS App.
MIT License
11.37k stars 2.24k forks source link

webview #61

Open yuzhoulangzik opened 9 years ago

yuzhoulangzik commented 9 years ago

webview load html by jspatch has issue

bang590 commented 9 years ago

What did you mean?

yuzhoulangzik commented 9 years ago

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…]()

albert438 commented 9 years ago

missed require()

var webView = require('UIWebView').alloc().initWithFrame(self.view().frame())
yuzhoulangzik commented 9 years ago

@albert438 had add require('UIWebView'),

2015-07-14 12 54 03
albert438 commented 9 years ago

@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;
}
yuzhoulangzik commented 9 years ago

@albert438 //defineClass('UIWebView',{

// loadRequest :function(request){ // self.valueForKeyPath("documentView.webView.mainFrame.javaScriptContext") // self.ORIGloadRequest(request) // } // })

overwrite loadRequest it work

huohuoluo commented 9 years ago

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).

bang590 commented 8 years ago

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)
    })
}

https://github.com/bang590/JSPatch/wiki/performSelectorInOC-%E4%BD%BF%E7%94%A8%E6%96%87%E6%A1%A3#uiwebview%E4%BE%8B%E5%AD%90

ganvinalix commented 8 years ago

@albert438 this can be work for me ,but send a new version to appstore

lynulzy commented 8 years ago

@bang590 问下邦神,在需要覆盖的方法里没有直接调用uiwebview,但是某些代码会唤起带webview的viewcontroller,这种情况应该对需要覆盖的整个方法执行performSelectorInOC 吗?

lynulzy commented 8 years ago

上段代码

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呢?

xmw-simon commented 7 years ago

大神,UIWebView.performSelectorInOC这个api在初始化UIWebView之后,WebView里面的点击事件全部失效了!!