Home > Enterprise >  What is React Native Permissions & how to use it?
What is React Native Permissions & how to use it?

Time:04-19

How to use the React Native Permissions Library? I have started learning it tell me the best practices using the library?

CodePudding user response:

App permissions help support user privacy by protecting access to the following:

  • Restricted data, such as system state and a user's contact information.

  • Restricted actions, such as connecting to a paired device and recording audio. react-native-permissions A unified permissions API for React Native on iOS, Android and Windows. You can install it from terminal by the following command

    $ npm install --save react-native-permissions

    --- or ---

    $ yarn add react-native-permissions

https://github.com/zoontek/react-native-permissions#readme

Understanding permission flow As permissions are not handled in the same way on iOS and Android, this library provides an abstraction over the two platforms' behaviors. (Check details here).
 Update Pod files for installing permission handler. By default no permission handler is installed. Update your Podfile by choosing the ones you want to check or request, then run pod install.

Example

    target 'YourAwesomeProject' do
    
      # …
    
      permissions_path = '../node_modules/react-native-permissions/ios'
    
      pod 'Permission-AppTrackingTransparency', :path => "#{permissions_path}/AppTrackingTransparency"
      pod 'Permission-BluetoothPeripheral', :path => "#{permissions_path}/BluetoothPeripheral"
      pod 'Permission-Calendars', :path => "#{permissions_path}/Calendars"
      pod 'Permission-Camera', :path => "#{permissions_path}/Camera"
      pod 'Permission-Contacts', :path => "#{permissions_path}/Contacts"
    
    end
    
    

Then update your Info.plist with wanted permissions usage descriptions:

        <?xml version="1.0" encoding="UTF-8"?>
        <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" 
        "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
        <plist version="1.0">
        <dict>
        
          <!--            
  • Related