This is an automated email from the ASF dual-hosted git repository.
moshen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-weex.git
The following commit(s) were added to refs/heads/master by this push:
new 2379171 fix bug wkwebview crash
new 10f7406 Merge pull request #3080 from yaochenfeng/feature/web
2379171 is described below
commit 23791716ae6487cd782a932ec3c2355b5ec6cc79
Author: yaochenfeng <[email protected]>
AuthorDate: Fri Dec 13 19:22:57 2019 +0800
fix bug wkwebview crash
---
ios/sdk/WeexSDK/Sources/Component/WXWebComponent.m | 72 +++++++++++-----------
1 file changed, 35 insertions(+), 37 deletions(-)
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXWebComponent.m
b/ios/sdk/WeexSDK/Sources/Component/WXWebComponent.m
index 1b37c28..f053a39 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXWebComponent.m
+++ b/ios/sdk/WeexSDK/Sources/Component/WXWebComponent.m
@@ -43,8 +43,6 @@
@interface WXWebComponent ()
-@property (nonatomic, strong) JSContext *jsContext;
-
@property (nonatomic, strong) WXWebView *webview;
@property (nonatomic, strong) NSString *url;
@@ -98,7 +96,7 @@ WX_EXPORT_METHOD(@selector(goForward))
- (UIView *)loadView
{
- return [[WXWebView alloc] initWithFrame:self.view.frame
configuration:[self baseConfiguration]];
+ return [[WXWebView alloc] initWithFrame:CGRectZero configuration:[self
baseConfiguration]];
}
- (void)viewDidLoad
@@ -107,39 +105,39 @@ WX_EXPORT_METHOD(@selector(goForward))
_webview.navigationDelegate = self;
[_webview setBackgroundColor:[UIColor clearColor]];
_webview.opaque = NO;
- _jsContext = [_webview
valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
- __weak typeof(self) weakSelf = self;
+// _jsContext = [_webview
valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
+// __weak typeof(self) weakSelf = self;
// This method will be abandoned slowly.
- _jsContext[@"$notifyWeex"] = ^(JSValue *data) {
- if (weakSelf.notifyEvent) {
- [weakSelf fireEvent:@"notify" params:[data toDictionary]];
- }
- };
-
- //Weex catch postMessage event from web
- _jsContext[@"postMessage"] = ^() {
-
- NSArray *args = [JSContext currentArguments];
-
- if (args && args.count < 2) {
- return;
- }
-
- NSDictionary *data = [args[0] toDictionary];
- NSString *origin = [args[1] toString];
-
- if (data == nil) {
- return;
- }
-
- NSDictionary *initDic = @{ @"type" : @"message",
- @"data" : data,
- @"origin" : origin
- };
-
- [weakSelf fireEvent:@"message" params:initDic];
- };
+// _jsContext[@"$notifyWeex"] = ^(JSValue *data) {
+// if (weakSelf.notifyEvent) {
+// [weakSelf fireEvent:@"notify" params:[data toDictionary]];
+// }
+// };
+//
+// //Weex catch postMessage event from web
+// _jsContext[@"postMessage"] = ^() {
+//
+// NSArray *args = [JSContext currentArguments];
+//
+// if (args && args.count < 2) {
+// return;
+// }
+//
+// NSDictionary *data = [args[0] toDictionary];
+// NSString *origin = [args[1] toString];
+//
+// if (data == nil) {
+// return;
+// }
+//
+// NSDictionary *initDic = @{ @"type" : @"message",
+// @"data" : data,
+// @"origin" : origin
+// };
+//
+// [weakSelf fireEvent:@"message" params:initDic];
+// };
self.source = _inInitsource;
if (_url) {
@@ -235,7 +233,7 @@ WX_EXPORT_METHOD(@selector(goForward))
{
NSString *json = [WXUtility JSONString:data];
NSString *code = [NSString stringWithFormat:@"(function(){var evt=null;var
data=%@;if(typeof CustomEvent==='function'){evt=new
CustomEvent('notify',{detail:data})}else{evt=document.createEvent('CustomEvent');evt.initCustomEvent('notify',true,true,data)}document.dispatchEvent(evt)}())",
json];
- [_jsContext evaluateScript:code];
+ [_webview evaluateJavaScript:code completionHandler:nil];
}
// Weex postMessage to web
@@ -259,7 +257,7 @@ WX_EXPORT_METHOD(@selector(goForward))
NSString *json = [WXUtility JSONString:initDic];
NSString *code = [NSString stringWithFormat:@"(function
(){window.dispatchEvent(new MessageEvent('message', %@));}())", json];
- [_jsContext evaluateScript:code];
+ [_webview evaluateJavaScript:code completionHandler:nil];
}
#pragma mark Webview Delegate
@@ -272,7 +270,7 @@ WX_EXPORT_METHOD(@selector(goForward))
[self.webview evaluateJavaScript:@"document.title" completionHandler:^(id
_Nullable result, NSError * _Nullable error) {
[info setObject:result ? result : @"" forKey:@"title"];
if (completion) {
- completion(result);
+ completion(info);
}
}];
}