@alpakaio/alpaka-native-useragent
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

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.

Package Sidebar

Install

npm i @alpakaio/alpaka-native-useragent

Weekly Downloads

1

Version

1.1.0

License

MIT

Unpacked Size

7.61 kB

Total Files

10

Last publish

Collaborators

  • phillrodgers
  • thomastuts
  • victoriafrench