Browse Source

feat(iOS WkWebview): Add applicationNameForUserAgent support (#506)

Penar Musaraj 5 years ago
parent
commit
4dc4b89e64
4 changed files with 15 additions and 0 deletions
  1. 9
    0
      docs/Reference.md
  2. 1
    0
      ios/RNCWKWebView.h
  3. 4
    0
      ios/RNCWKWebView.m
  4. 1
    0
      ios/RNCWKWebViewManager.m

+ 9
- 0
docs/Reference.md View File

@@ -30,6 +30,7 @@ This document lays out the current public properties and methods for the React N
30 30
 - [`mixedContentMode`](Reference.md#mixedcontentmode)
31 31
 - [`thirdPartyCookiesEnabled`](Reference.md#thirdpartycookiesenabled)
32 32
 - [`userAgent`](Reference.md#useragent)
33
+- [`applicationNameForUserAgent`](Reference.md#applicationNameForUserAgent)
33 34
 - [`allowsFullscreenVideo`](Reference.md#allowsfullscreenvideo)
34 35
 - [`allowsInlineMediaPlayback`](Reference.md#allowsinlinemediaplayback)
35 36
 - [`bounces`](Reference.md#bounces)
@@ -608,6 +609,14 @@ Sets the user-agent for the `WebView`. This will only work for iOS if you are us
608 609
 
609 610
 ---
610 611
 
612
+### `applicationNameForUserAgent`
613
+
614
+Append to the existing user-agent. Available on iOS WKWebView only. Setting `userAgent` will override this.
615
+
616
+| Type   | Required | Platform      |
617
+| ------ | -------- | ------------- |
618
+| string | No       | iOS WKWebView |
619
+
611 620
 ### `allowsFullscreenVideo`
612 621
 
613 622
 Boolean that determines whether videos are allowed to be played in fullscreen. The default value is `false`.

+ 1
- 0
ios/RNCWKWebView.h View File

@@ -43,6 +43,7 @@
43 43
 @property (nonatomic, assign) BOOL incognito;
44 44
 @property (nonatomic, assign) BOOL useSharedProcessPool;
45 45
 @property (nonatomic, copy) NSString *userAgent;
46
+@property (nonatomic, copy) NSString *applicationNameForUserAgent;
46 47
 @property (nonatomic, assign) BOOL cacheEnabled;
47 48
 @property (nonatomic, assign) BOOL allowsLinkPreview;
48 49
 @property (nonatomic, assign) BOOL showsHorizontalScrollIndicator;

+ 4
- 0
ios/RNCWKWebView.m View File

@@ -142,6 +142,10 @@ static NSURLCredential* clientAuthenticationCredential;
142 142
     wkWebViewConfig.mediaPlaybackRequiresUserAction = _mediaPlaybackRequiresUserAction;
143 143
 #endif
144 144
 
145
+    if (_applicationNameForUserAgent) {
146
+        wkWebViewConfig.applicationNameForUserAgent = [NSString stringWithFormat:@"%@ %@", wkWebViewConfig.applicationNameForUserAgent, _applicationNameForUserAgent];
147
+    }
148
+
145 149
     if(_sharedCookiesEnabled) {
146 150
       // More info to sending cookies with WKWebView
147 151
       // https://stackoverflow.com/questions/26573137/can-i-set-the-cookies-to-be-used-by-a-wkwebview/26577303#26577303

+ 1
- 0
ios/RNCWKWebViewManager.m View File

@@ -48,6 +48,7 @@ RCT_EXPORT_VIEW_PROPERTY(allowsBackForwardNavigationGestures, BOOL)
48 48
 RCT_EXPORT_VIEW_PROPERTY(incognito, BOOL)
49 49
 RCT_EXPORT_VIEW_PROPERTY(pagingEnabled, BOOL)
50 50
 RCT_EXPORT_VIEW_PROPERTY(userAgent, NSString)
51
+RCT_EXPORT_VIEW_PROPERTY(applicationNameForUserAgent, NSString)
51 52
 RCT_EXPORT_VIEW_PROPERTY(cacheEnabled, BOOL)
52 53
 RCT_EXPORT_VIEW_PROPERTY(allowsLinkPreview, BOOL)
53 54