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
 - [`mixedContentMode`](Reference.md#mixedcontentmode)
30
 - [`mixedContentMode`](Reference.md#mixedcontentmode)
31
 - [`thirdPartyCookiesEnabled`](Reference.md#thirdpartycookiesenabled)
31
 - [`thirdPartyCookiesEnabled`](Reference.md#thirdpartycookiesenabled)
32
 - [`userAgent`](Reference.md#useragent)
32
 - [`userAgent`](Reference.md#useragent)
33
+- [`applicationNameForUserAgent`](Reference.md#applicationNameForUserAgent)
33
 - [`allowsFullscreenVideo`](Reference.md#allowsfullscreenvideo)
34
 - [`allowsFullscreenVideo`](Reference.md#allowsfullscreenvideo)
34
 - [`allowsInlineMediaPlayback`](Reference.md#allowsinlinemediaplayback)
35
 - [`allowsInlineMediaPlayback`](Reference.md#allowsinlinemediaplayback)
35
 - [`bounces`](Reference.md#bounces)
36
 - [`bounces`](Reference.md#bounces)
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
 ### `allowsFullscreenVideo`
620
 ### `allowsFullscreenVideo`
612
 
621
 
613
 Boolean that determines whether videos are allowed to be played in fullscreen. The default value is `false`.
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
 @property (nonatomic, assign) BOOL incognito;
43
 @property (nonatomic, assign) BOOL incognito;
44
 @property (nonatomic, assign) BOOL useSharedProcessPool;
44
 @property (nonatomic, assign) BOOL useSharedProcessPool;
45
 @property (nonatomic, copy) NSString *userAgent;
45
 @property (nonatomic, copy) NSString *userAgent;
46
+@property (nonatomic, copy) NSString *applicationNameForUserAgent;
46
 @property (nonatomic, assign) BOOL cacheEnabled;
47
 @property (nonatomic, assign) BOOL cacheEnabled;
47
 @property (nonatomic, assign) BOOL allowsLinkPreview;
48
 @property (nonatomic, assign) BOOL allowsLinkPreview;
48
 @property (nonatomic, assign) BOOL showsHorizontalScrollIndicator;
49
 @property (nonatomic, assign) BOOL showsHorizontalScrollIndicator;

+ 4
- 0
ios/RNCWKWebView.m View File

142
     wkWebViewConfig.mediaPlaybackRequiresUserAction = _mediaPlaybackRequiresUserAction;
142
     wkWebViewConfig.mediaPlaybackRequiresUserAction = _mediaPlaybackRequiresUserAction;
143
 #endif
143
 #endif
144
 
144
 
145
+    if (_applicationNameForUserAgent) {
146
+        wkWebViewConfig.applicationNameForUserAgent = [NSString stringWithFormat:@"%@ %@", wkWebViewConfig.applicationNameForUserAgent, _applicationNameForUserAgent];
147
+    }
148
+
145
     if(_sharedCookiesEnabled) {
149
     if(_sharedCookiesEnabled) {
146
       // More info to sending cookies with WKWebView
150
       // More info to sending cookies with WKWebView
147
       // https://stackoverflow.com/questions/26573137/can-i-set-the-cookies-to-be-used-by-a-wkwebview/26577303#26577303
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
 RCT_EXPORT_VIEW_PROPERTY(incognito, BOOL)
48
 RCT_EXPORT_VIEW_PROPERTY(incognito, BOOL)
49
 RCT_EXPORT_VIEW_PROPERTY(pagingEnabled, BOOL)
49
 RCT_EXPORT_VIEW_PROPERTY(pagingEnabled, BOOL)
50
 RCT_EXPORT_VIEW_PROPERTY(userAgent, NSString)
50
 RCT_EXPORT_VIEW_PROPERTY(userAgent, NSString)
51
+RCT_EXPORT_VIEW_PROPERTY(applicationNameForUserAgent, NSString)
51
 RCT_EXPORT_VIEW_PROPERTY(cacheEnabled, BOOL)
52
 RCT_EXPORT_VIEW_PROPERTY(cacheEnabled, BOOL)
52
 RCT_EXPORT_VIEW_PROPERTY(allowsLinkPreview, BOOL)
53
 RCT_EXPORT_VIEW_PROPERTY(allowsLinkPreview, BOOL)
53
 
54