diff --git a/renderer/native/ios/renderer/component/webview/NativeRenderSimpleWebView.h b/renderer/native/ios/renderer/component/webview/NativeRenderSimpleWebView.h index 4229d821227..e11311be301 100644 --- a/renderer/native/ios/renderer/component/webview/NativeRenderSimpleWebView.h +++ b/renderer/native/ios/renderer/component/webview/NativeRenderSimpleWebView.h @@ -26,6 +26,7 @@ NS_ASSUME_NONNULL_BEGIN @interface NativeRenderSimpleWebView : WKWebView +@property (nonatomic, strong) NSString *userAgent; @property (nonatomic, strong) NSString *url; @property (nonatomic, strong) NSDictionary *source; @property (nonatomic, copy) HippyDirectEventBlock onLoadStart; diff --git a/renderer/native/ios/renderer/component/webview/NativeRenderSimpleWebView.m b/renderer/native/ios/renderer/component/webview/NativeRenderSimpleWebView.m index 25f864bdff9..9a5fb108822 100644 --- a/renderer/native/ios/renderer/component/webview/NativeRenderSimpleWebView.m +++ b/renderer/native/ios/renderer/component/webview/NativeRenderSimpleWebView.m @@ -38,17 +38,35 @@ - (void)setSource:(NSDictionary *)source { _source = source; if (source && [source[@"uri"] isKindOfClass:[NSString class]]) { NSString *urlString = source[@"uri"]; - [self loadUrl:urlString]; + NSString *method = source[@"method"]; + + // Wait for other properties to be updated + dispatch_async(dispatch_get_main_queue(), ^{ + [self loadUrl:urlString withMethod:method]; + }); } } -- (void)loadUrl:(NSString *)urlString { +- (void)loadUrl:(NSString *)urlString withMethod:(NSString*)method { _url = urlString; NSURL *url = HippyURLWithString(urlString, NULL); if (!url) { return; } - NSURLRequest *request = [NSURLRequest requestWithURL:url]; + + NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url]; + method = [method uppercaseString]; + if([method isEqualToString:@"GET"]){ + request.HTTPMethod = @"GET"; + }else if ([method isEqualToString:@"POST"]){ + request.HTTPMethod = @"POST"; + }else{ + // System default is 'GET' no need to be specified explicitly + } + NSString* ua = self.userAgent; + if(ua){ + self.customUserAgent = ua; + } [self loadRequest:request]; } diff --git a/renderer/native/ios/renderer/component/webview/NativeRenderSimpleWebViewManager.mm b/renderer/native/ios/renderer/component/webview/NativeRenderSimpleWebViewManager.mm index b9ea67249f9..3149de34a8b 100644 --- a/renderer/native/ios/renderer/component/webview/NativeRenderSimpleWebViewManager.mm +++ b/renderer/native/ios/renderer/component/webview/NativeRenderSimpleWebViewManager.mm @@ -26,6 +26,7 @@ @implementation NativeRenderSimpleWebViewManager HIPPY_EXPORT_MODULE(WebView) +HIPPY_EXPORT_VIEW_PROPERTY(userAgent, NSString) HIPPY_EXPORT_VIEW_PROPERTY(source, NSDictionary) HIPPY_EXPORT_VIEW_PROPERTY(onLoadStart, HippyDirectEventBlock) HIPPY_EXPORT_VIEW_PROPERTY(onLoadEnd, HippyDirectEventBlock)