zoontek / react-native-permissions

An unified permissions API for React Native on iOS, Android and Windows.
MIT License
4.11k stars 837 forks source link

AppTrackingTransparency: The permission always return unavailable, even when NSUserTrackingUsageDescription is added #836

Closed imanshul closed 10 months ago

imanshul commented 10 months ago

Bug summary

We have added the key NSUserTrackingUsageDescription in the info.plist and enabled in podfile as well, still when we make a call the request method always result in RESULTS.UNAVAILABLE

Library version

4.0.1

Environment info

System:
  OS: macOS 14.1.2
  CPU: (8) arm64 Apple M1
  Memory: 87.41 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.16.1
    path: ~/.nvm/versions/node/v18.16.1/bin/node
  Yarn:
    version: 1.22.17
    path: /usr/local/bin/yarn
  npm:
    version: 9.5.1
    path: ~/.nvm/versions/node/v18.16.1/bin/npm
  Watchman:
    version: 2023.12.04.00
    path: /usr/local/bin/watchman
Managers:
  CocoaPods:
    version: 1.14.3
    path: /usr/local/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.0
      - iOS 17.0
      - macOS 14.0
      - tvOS 17.0
      - watchOS 10.0
  Android SDK:
    API Levels:
      - "17"
      - "23"
      - "27"
      - "28"
      - "29"
      - "30"
      - "31"
      - "33"
      - "34"
    Build Tools:
      - 29.0.2
      - 30.0.0
      - 30.0.1
      - 30.0.2
      - 30.0.3
      - 31.0.0
      - 33.0.0
      - 33.0.1
      - 34.0.0
    System Images:
      - android-26 | Google APIs ARM 64 v8a
      - android-28 | Google ARM64-V8a Play ARM 64 v8a
      - android-29 | Google Play ARM 64 v8a
      - android-30 | Google APIs ARM 64 v8a
      - android-31 | Google APIs ARM 64 v8a
      - android-32 | Google Play ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: 2023.1 AI-231.9392.1.2311.11076708
  Xcode:
    version: 15.0.1/15A507
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.6
    path: /usr/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.73.1
    wanted: 0.73.1
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

Steps to reproduce

Add the latest version and add the keys in info.plist and run app to ask permission

Reproducible sample code

Code:

requestPermission() {
    request(PERMISSIONS.IOS.APP_TRACKING_TRANSPARENCY).then(result => {
      switch (result) {
        case RESULTS.UNAVAILABLE:
          console.log(
            'Permission',
            'This feature is not available (on this device / in this context)',
          );
          break;
        case RESULTS.DENIED:
          console.log(
            'Permission',
            'The permission has not been requested / is denied but requestable',
          );
          break;
        case RESULTS.LIMITED:
          console.log(
            'Permission',
            'The permission is limited: some actions are possible',
          );
          break;
        case RESULTS.GRANTED:
          console.log('Permission', 'The permission is granted');
          break;
        case RESULTS.BLOCKED:
          console.log(
            'Permission',
            'The permission is denied and not requestable anymore',
          );
          break;
      }
    });
  }
zoontek commented 10 months ago

@imanshul You cleared the Xcode cache, just in case? (DerivedData)

imanshul commented 10 months ago

yeah removing derived data solved the problem, but the package was installed earlier, and i just enable the permission and did pod install. so do i have to do it everytime I enable or disable any permission?

zoontek commented 10 months ago

@imanshul Not if you follow the setup in the README

imanshul commented 10 months ago

All of the steps are followed by podfile is:

# Resolve react_native_pods.rb with node to allow for hoisting
# ----- Uncomment below code, if removing the react-naitve-permissions ----
# require Pod::Executable.execute_command('node', ['-p',
#   'require.resolve(
#     "react-native/scripts/react_native_pods.rb",
#     {paths: [process.argv[1]]},
#   )', __dir__]).strip

# ------ Start Used for react-native-permissions --------
def node_require(script)
  # Resolve script with node to allow for hoisting
  require Pod::Executable.execute_command('node', ['-p',
    "require.resolve(
      '#{script}',
      {paths: [process.argv[1]]},
    )", __dir__]).strip
end

node_require('react-native/scripts/react_native_pods.rb')
node_require('react-native-permissions/scripts/setup.rb')
# ------ END Used for react-native-permissions --------

platform :ios, min_ios_version_supported
prepare_react_native_project!

# ------ Start Used for react-native-permissions --------
# ⬇️ uncomment wanted permissions
setup_permissions([
   'AppTrackingTransparency',
  # 'Bluetooth',
  # 'Calendars',
  # 'CalendarsWriteOnly',
   'Camera',
  # 'Contacts',
  # 'FaceID',
  # 'LocationAccuracy',
  # 'LocationAlways',
  # 'LocationWhenInUse',
  # 'MediaLibrary',
  # 'Microphone',
  # 'Motion',
   'Notifications',
   'PhotoLibrary',
  # 'PhotoLibraryAddOnly',
  # 'Reminders',
  # 'Siri',
  # 'SpeechRecognition',
  # 'StoreKit',
])

# ------ END Used for react-native-permissions --------

# If you are using a `react-native-flipper` your iOS build will fail when `NO_FLIPPER=1` is set.
# because `react-native-flipper` depends on (FlipperKit,...) that will be excluded
#
# To fix this you can also exclude `react-native-flipper` using a `react-native.config.js`
# ```js
# module.exports = {
#   dependencies: {
#     ...(process.env.NO_FLIPPER ? { 'react-native-flipper': { platforms: { ios: null } } } : {}),
# ```
flipper_config = ENV['NO_FLIPPER'] == "1" ? FlipperConfiguration.disabled : FlipperConfiguration.disabled

linkage = ENV['USE_FRAMEWORKS']
if linkage != nil
  Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green
  use_frameworks! :linkage => linkage.to_sym
end

target 'App13Karat' do
  pod 'WebEngage'
  config = use_native_modules!

  use_frameworks! :linkage => :static
  $RNFirebaseAsStaticFramework = true

  use_react_native!(
    :path => config[:reactNativePath],
    # Enables Flipper.
    #
    # Note that if you have use_frameworks! enabled, Flipper will not work and
    # you should disable the next line.
    :flipper_configuration => flipper_config,
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )

  target 'App13KaratTests' do
    inherit! :complete
    # Pods for testing
  end

  # ServiceExtension Target
  target 'NotificationService' do
      platform :ios, min_ios_version_supported
      pod 'WebEngageBannerPush'
  end

  # ContentExtension Target
  target 'NotificationViewController' do
    platform :ios, min_ios_version_supported
    pod 'WebEngageAppEx/ContentExtension'
  end

  post_install do |installer|
    # https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202
    react_native_post_install(
      installer,
      config[:reactNativePath],
      :mac_catalyst_enabled => false
    )
    workAroundForSharedApplication(installer)
  end
end

# Fix for MMKV after adding WebEngage, especially NotificationService and NotificationViewController as App Extension
def workAroundForSharedApplication(installer)
    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
            config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'No'
        end
    end
end
zoontek commented 10 months ago

In this case, it will work after a pod install and a cache clean.