# react-native-user-agent

> Library that helps you to get mobile application user agent and web view user agent strings.

Latest version **2.3.1** (published 2022-02-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-native-user-agent
pnpm add react-native-user-agent
yarn add react-native-user-agent
bun add react-native-user-agent
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.3.1 |
| Published | 2022-02-11 |
| First published | 2018-07-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 32.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 42 |
| Author | Bebnev Anton |
| Maintainers | bebnev_anton |
| Keywords | react-native, user-agent, user agent, http, webView, httpUserAgent |

## Links

- npm: https://www.npmjs.com/package/react-native-user-agent
- Repository: https://github.com/bebnev/react-native-user-agent
- Issues: https://github.com/bebnev/react-native-user-agent/issues
- npm.io page: https://npm.io/package/react-native-user-agent

## Recent versions

- 2.3.1 (latest) — 2022-02-11
- 2.2.0 — 2022-02-10
- 2.1.0 — 2019-11-13
- 2.0.0 — 2019-11-13
- 1.0.6 — 2019-11-09
- 1.0.4 — 2019-06-21
- 1.0.3 — 2019-01-14
- 1.0.1 — 2018-07-11
- 1.0.0 — 2018-07-10
- 0.0.9 — 2018-07-10
- 0.0.8 — 2018-07-10
- 0.0.7 — 2018-07-10
- 0.0.6 — 2018-07-10
- 0.0.5 — 2018-07-10
- 0.0.4 — 2018-07-10
- … 3 more at https://npm.io/package/react-native-user-agent/versions

## README

# React Native User Agent

## Platforms Supported

- [x] iOS
- [x] Android

## Getting Started Guide

1. Add react-native-user-agent to your dependencies

```sh
yarn add react-native-user-agent
```

or, for npm use

```sh
npm install react-native-user-agent --save
```

2. Link native dependencies

2.1 **react-native >= 0.60**

Autolinking will take care of the link step, but for iOS, don't forget to run `pod install` in `ios/` folder

If you haven't set up cocoapods yet, please refer to [that article](https://engineering.brigad.co/demystifying-react-native-modules-linking-ae6c017a6b4a)

2.2 **react-native < 0.60**

You have to call `link` command manualy:

```sh
react-native link react-native-user-agent
```

*For manual linking*, please refer to:
- [that article](https://engineering.brigad.co/demystifying-react-native-modules-linking-964399ec731b) for Android
- [react-native own tutorial](https://facebook.github.io/react-native/docs/linking-libraries-ios) for iOS

## Usage

```javascript
import UserAgent from 'react-native-user-agent';

UserAgent.getUserAgent(); //synchronous

UserAgent.getWebViewUserAgent() //asynchronous
    .then(ua => {})
    .catch(e => {})
```

### Examples:

| System | User-Agent | WebView User-Agent |
| ------ | ---------- | ------------------ |
| iOS    | application-name/1.6.4.176 CFNetwork/897.15 Darwin/17.5.0 (iPhone/6s iOS/11.3) | Mozilla/5.0 (iPhone; CPU iPhone OS 11_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E217 |
| Android | application-name/1.6.7.42 Dalvik/2.1.0 (Linux; U; Android 5.1.1; Android SDK built for x86 Build/LMY48X) | Mozilla/5.0 (Linux; Android 5.1.1; Android SDK built for x86 Build/LMY48X) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/39.0.0.0 Mobile Safari/537.36 |

Additionally module returns a set of constants, that are used in user agent string building.

For iOS:
- systemName
- systemVersion
- applicationName
- applicationVersion
- buildNumber
- darwinVersion
- cfnetworkVersion
- deviceName **deprecated**
- modelName

For Android:
- systemName
- systemVersion
- applicationName
- applicationVersion
- buildNumber

## Versioning

**Breaking History:**
- [2.3.0](https://github.com/bebnev/react-native-user-agent/releases/tag/v2.3.0)
    - unification for ios device names
    - fix android gradle script
    - add types definition
- [2.1.0](https://github.com/bebnev/react-native-user-agent/releases/tag/v2.1.0) - support for tvos
- [2.0.0](https://github.com/bebnev/react-native-user-agent/releases/tag/v2.0.0) - supports [autolinking](https://github.com/react-native-community/cli/blob/master/docs/autolinking.md), native code refactoring, removes UIWebView, `getWebViewUserAgent()` returns promise
- [1.0.6](https://github.com/bebnev/react-native-user-agent/releases/tag/v1.0.6) - First release

## License

[MIT](LICENSE). Copyright (c) 2018 Anton Bebnev.

---
_Source: https://npm.io/package/react-native-user-agent · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
