Set user agent with WebView with react-native

后端 未结 9 1483
闹比i
闹比i 2021-02-19 13:26

I want to modify the user agent string in a WebView so that on the server side I can detect that the request has come from my react-native app. I want to do this using the sourc

相关标签:
9条回答
  • 2021-02-19 14:00
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    
    NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36", @"UserAgent", nil];
     [[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];
    
    }
    
    
    0 讨论(0)
  • 2021-02-19 14:03

    just add this to user agent you can update the versions in future, I used is as google login was giving me issue

    userAgent="Mozilla/5.0 (Linux; Android 10; Android SDK built for x86 Build/LMY48X) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/81.0.4044.117 Mobile Safari/608.2.11"

    0 讨论(0)
  • 2021-02-19 14:06

    This is a terrible idea. Just use a custom header:

    X-MY-CUSTOM-HEADER = MyAppName. 
    
    0 讨论(0)
提交回复
热议问题