1.1.0 • Published 5 years ago
@alpakaio/alpaka-native-useragent v1.1.0
alpaka-native-useragent
User Agent builder used by Alpaka React Native apps.
TOC
Installation
Using npm:
npm install --save @alpakaio/alpaka-native-useragent
⚠️ This package has a peer dependency of React Native Device Info at version 2.0.0 or higher.
Usage
import UserAgent from '@alpakaio/alpaka-native-useragent';
API
Method | Return Type | iOS | Android | Windows | Since |
---|---|---|---|---|---|
getUserAgentAsync() | Promise<string> | ✅ | ✅ | ✅ | 1.0.0 |
getUserAgentAsync()
Gets the appropriate user-agent string to use with Alpaka services.
Examples
const userAgentString = await UserAgent.getUserAgentAsync();
// "Alpaka Punch; 1.0.0; b.17; en-GB; (Apple; iOS; 12.1; Handset; iPhone10,6)"
UserAgent.getUserAgentAsync().then((userAgentString) => {
// "Alpaka Punch; 1.0.0; b.17; en-GB; (Apple; iOS; 12.1; Handset; iPhone10,6)"
});
Troubleshooting
When installing or using alpaka-native-useragent
, you may encounter the following problems:
alpaka-native-useragent
relies on react-native-device-info
which contains native code, and needs to be mocked. Jest Snapshot support may work though.
Here's how to do it with jest for example:
// in your package.json:
"jest": {
"setupFiles": [
"./testenv.js"
],
// testenv.js:
jest.mock('@alpakaio/alpaka-native-useragent', () => {
return {
getUserAgentAsync: jest.fn(),
};
});
Release Notes
See the CHANGELOG.md.
react-native-dom
This library was made compatible with react-native-dom and react-native-web by providing an empty polyfill in order to avoid breaking builds.