Browse Source

fix(WKWebview): Fixed for supporting mediaPlaybackRequiresUserAction option under iOS 10. (#129)

ifsnow 6 years ago
parent
commit
c0c0116c80
1 changed files with 11 additions and 9 deletions
  1. 11
    9
      ios/RNCWKWebView.m

+ 11
- 9
ios/RNCWKWebView.m View File

@@ -92,7 +92,9 @@ static NSString *const MessageHanderName = @"ReactNative";
92 92
     wkWebViewConfig.mediaTypesRequiringUserActionForPlayback = _mediaPlaybackRequiresUserAction
93 93
       ? WKAudiovisualMediaTypeAll
94 94
       : WKAudiovisualMediaTypeNone;
95
-   wkWebViewConfig.dataDetectorTypes = _dataDetectorTypes;
95
+    wkWebViewConfig.dataDetectorTypes = _dataDetectorTypes;
96
+#else
97
+    wkWebViewConfig.mediaPlaybackRequiresUserAction = _mediaPlaybackRequiresUserAction;
96 98
 #endif
97 99
 
98 100
     _webView = [[WKWebView alloc] initWithFrame:self.bounds configuration: wkWebViewConfig];
@@ -216,7 +218,7 @@ static NSString *const MessageHanderName = @"ReactNative";
216 218
 
217 219
 -(void)setHideKeyboardAccessoryView:(BOOL)hideKeyboardAccessoryView
218 220
 {
219
-    
221
+
220 222
     if (_webView == nil) {
221 223
         _savedHideKeyboardAccessoryView = hideKeyboardAccessoryView;
222 224
         return;
@@ -225,29 +227,29 @@ static NSString *const MessageHanderName = @"ReactNative";
225 227
     if (_savedHideKeyboardAccessoryView == false) {
226 228
         return;
227 229
     }
228
-    
230
+
229 231
     UIView* subview;
230 232
     for (UIView* view in _webView.scrollView.subviews) {
231 233
         if([[view.class description] hasPrefix:@"WK"])
232 234
             subview = view;
233 235
     }
234
-    
236
+
235 237
     if(subview == nil) return;
236
-    
238
+
237 239
     NSString* name = [NSString stringWithFormat:@"%@_SwizzleHelperWK", subview.class.superclass];
238 240
     Class newClass = NSClassFromString(name);
239
-    
241
+
240 242
     if(newClass == nil)
241 243
     {
242 244
         newClass = objc_allocateClassPair(subview.class, [name cStringUsingEncoding:NSASCIIStringEncoding], 0);
243 245
         if(!newClass) return;
244
-        
246
+
245 247
         Method method = class_getInstanceMethod([_SwizzleHelperWK class], @selector(inputAccessoryView));
246 248
         class_addMethod(newClass, @selector(inputAccessoryView), method_getImplementation(method), method_getTypeEncoding(method));
247
-        
249
+
248 250
         objc_registerClassPair(newClass);
249 251
     }
250
-    
252
+
251 253
     object_setClass(subview, newClass);
252 254
 }
253 255