Skip to content

Latest commit

 

History

History
101 lines (68 loc) · 3.23 KB

README.md

File metadata and controls

101 lines (68 loc) · 3.23 KB

alpaka-native-useragent

npm version

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:

[tests] - Cannot run my test suite when using this library

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(),
  };
});
[warnings] - dispatch_sync

Some of the APIs internally used will throw warnings in certain conditions like on tvOS or the iOS emulator. This won't be visible in production but even in development it may be irritating. It is useful to have the warnings because these devices return no state, and that can be surprising, leading to github support issues. The warnings is intended to educate you as a developer. If the warnings are troublesome you may try this in your code to suppress them:

import { YellowBox } from 'react-native';
YellowBox.ignoreWarnings(['Required dispatch_sync to load constants for RNDeviceInfo']);

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.