Set user agent with WebView with react-native

后端 未结 9 1495
闹比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 13:52

    For Android, you only need to set userAgent attribute, for example:

    
    

    For iOS, you need to add the code below inside the method didFinishLaunchingWithOptions (before the line return YES;) in AppDelegate.m implementation:

    NSString *userAgent = @"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36";
    NSDictionary *dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:userAgent, @"UserAgent", nil];
    [[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];
    

提交回复
热议问题