npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@generac/react-native-local-network-permission

v1.2.0

Published

A React Native / Expo module to request permission to access local network on iOS

Downloads

3,853

Readme

React Native Local Network Permission

A library to handle the local network permission introduced with iOS 14. It is only relevant for iOS, not for Android or web.

Getting started

Add this library to your project:

npm install @generac/react-native-local-network-permission

yarn add @generac/react-native-local-network-permission

iOS manual configuration

NSLocalNetworkUsageDescription

You need to add the NSLocalNetworkUsageDescription key to your Info.plist file. This should be a description of why your app needs Local Network permissions:

<key>NSLocalNetworkUsageDescription</key>
<string>App requires local network access to do ...</string>

See also: Apple documentation

NSBonjourServices

You need to add the NSBonjourServices key to your Info.plist file. This should be an array of Bonjour services that your app uses:

<key>NSBonjourServices</key>
<array>
  <string>_bonjour._tcp</string>
  <string>_lnp._tcp.</string>
</array>

See also: Apple documentation

Expo

If you are using the Expo managed workflow, you cannot directly edit your Info.plist. Instead, you can add the following to your app.json or app.config.js:

expo: {
  ios: {
    infoPlist: {
      NSLocalNetworkUsageDescription: 'App requires local network access to do ...',
      NSBonjourServices: ['_bonjour._tcp', '_lnp._tcp.'],
    },
  },
}

Usage

This library can be used in both React Native and Expo projects. Note however:

import {
  checkLocalNetworkAccess,
  requestLocalNetworkAccess,
} from '@generac/react-native-local-network-permission';

//you need to make sure the local network permission dialog popup once
const result = await requestLocalNetworkAccess();

//then use checkLocalNetworkAccess when you need
const result = await checkLocalNetworkAccess();
//here run the code depends local network access

Jest mocking

If you need to mock this library in your Jest tests, you can use the following code in your testSetup.ts file which you need to reference in your jest.config.js under setupFilesAfterEnv:

jest.mock('@generac/react-native-local-network-permission', () => ({
    checkLocalNetworkAccess: jest.fn(),
    requestLocalNetworkAccess: jest.fn(),
  }),
);

Commit messages

This repository uses a commit message convention which is enforced by a pre-commit hook. If you execute npm run commit instead of git commit -m "some message" you will be guided through the steps to write an acceptable commit message.

It is important that you do this properly, because the semantic-release automation depends on the commit messages to be starting with the proper keyword to determine if a major, minor or patch semantic version should be assigned.

See also