Set user agent with WebView with react-native

后端 未结 9 1523
闹比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:58

    This library now provides a method to get the userAgent for both ios and android:

    https://github.com/react-native-community/react-native-device-info#getuseragent

    this.state = { 
       userAgent: "",
    }
    
    componentDidMount = async () => {
       this.setState({ userAgent: await DeviceInfo.getUserAgent() })
    }
    
    
    
    

提交回复
热议问题