Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multi-target iOS configuration #753

Closed
chist3r opened this issue Feb 27, 2023 · 6 comments
Closed

Add multi-target iOS configuration #753

chist3r opened this issue Feb 27, 2023 · 6 comments
Assignees
Labels
feature request New feature or request

Comments

@chist3r
Copy link

chist3r commented Feb 27, 2023

Bug summary

Hello,
Recently working on a multi-target app that would need to include some permissions in all targets and a different permission in single target

As you can see in the below Podfile, I have included 3 permissions in both targets and camera permission only in MyTarget2

When building MyTarget2 it works fine. But when build MyTarget1 it fails with error Undefined symbol: _OBJC_CLASS_$_RNPermissionHandlerCamera

I believe this happens because cocoapods will collect libraries from all targets and them to header search paths for all targets. And while library implementation uses __has_include it will always resolve true in all targets because library header in the search path but the library itself is not included.

require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, min_ios_version_supported
prepare_react_native_project!

def permissions_pod(name)
  permissions_path = '../node_modules/react-native-permissions/ios'
  pod "Permission-#{name}", :path => "#{permissions_path}/#{name}"
end

def common_pods
  flipper_config = ENV['NO_FLIPPER'] == "1" ? FlipperConfiguration.disabled : FlipperConfiguration.enabled
  
  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

  config = use_native_modules!

  # Flags change depending on the env values.
  flags = get_default_flags()

  use_react_native!(
    :path => config[:reactNativePath],
    :hermes_enabled => flags[:hermes_enabled],
    :fabric_enabled => flags[:fabric_enabled],
    :flipper_configuration => flipper_config,
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )

  permissions_pod 'Notifications'
  permissions_pod 'LocationAlways'
  permissions_pod 'LocationWhenInUse'
end

target 'MyTarget1' do
  common_pods
end

target 'MyTarget2' do
  common_pods
  permissions_pod 'Camera'
end

post_install do |installer|
  react_native_post_install(
    installer,
    # Set `mac_catalyst_enabled` to `true` in order to apply patches
    # necessary for Mac Catalyst builds
    :mac_catalyst_enabled => false
  )
  __apply_Xcode_12_5_M1_post_install_workaround(installer)
end

Library version

3.7.2

Environment info

System:
    OS: macOS 13.2.1
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 99.43 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 14.16.0 - ~/.nvm/versions/node/v14.16.0/bin/node
    Yarn: Not Found
    npm: 6.14.11 - ~/.nvm/versions/node/v14.16.0/bin/npm
    Watchman: 2022.08.29.00 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.11.3 - /Users/atef/.rbenv/shims/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 22.1, iOS 16.1, macOS 13.0, tvOS 16.1, watchOS 9.1
    Android SDK:
      API Levels: 28, 29, 30, 31, 33
      Build Tools: 28.0.3, 29.0.2, 29.0.3, 30.0.2, 30.0.3, 31.0.0, 31.0.0
      System Images: android-27 | Google Play Intel x86 Atom, android-28 | Google Play Intel x86 Atom, android-30 | Google APIs Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: 4.2 AI-202.7660.26.42.7351085
    Xcode: 14.1/14B47b - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.15 - /usr/local/opt/openjdk@11/bin/javac
  npmPackages:
    @react-native-community/cli: 9.3.2 => 9.3.2
    react: 18.2.0 => 18.2.0
    react-native: 0.70.6 => 0.70.6
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Steps to reproduce

  1. Create a 2 targets app
  2. Include any permission in both targets
  3. Include different permission in a single target

Reproducible sample code

https://github.com/chist3r/RNPermissionsMultiTarget
@chist3r chist3r added the bug Something isn't working label Feb 27, 2023
@zoontek
Copy link
Owner

zoontek commented Feb 27, 2023

@chist3r First, please switch to the new linking system: https://github.com/zoontek/react-native-permissions/releases/tag/3.7.0

Then, for now I suggest to activate all used permissions (Notifications, LocationAlways, LocationWhenInUse and Camera) and warn the app store reviewer that you use a library (I recommend tweaking the purpose messages depending on the target)

You can also duplicate the whole ios directory. Which I highly recommend because you will have the exact same issues with other libraries (with react-native autolink)

@zoontek zoontek added feature request New feature or request and removed bug Something isn't working labels Feb 27, 2023
@zoontek zoontek changed the title Can't include different permissions per target Add multi-target iOS configutation Feb 27, 2023
@zoontek zoontek changed the title Add multi-target iOS configutation Add multi-target iOS configuration Feb 27, 2023
@chist3r
Copy link
Author

chist3r commented Feb 27, 2023

Thanks @zoontek
Just noticed the new implementation.. Looks cool..

Noticed you're using cosmiconfig to load the config key.
I think I can have permissions in .reactNativePermissionsIOSrc (git ignored) instead of package.json and automatically modify this file before calling the setup-ios-permissions command leaving package.json intact.

@zoontek
Copy link
Owner

zoontek commented Feb 27, 2023

Actually I removed it in 3.7.2 because it has an import problem.

But I could ship a new version that read reactNativePermissionsIOS.json at root if reactNativePermissionsIOS is not present in package.json if that works for you.

@chist3r
Copy link
Author

chist3r commented Feb 27, 2023

That would be great, thanks @zoontek

@zoontek
Copy link
Owner

zoontek commented Feb 28, 2023

@chist3r It's available: https://github.com/zoontek/react-native-permissions/releases/tag/3.7.3
I'm closing this, since it does the trick 🙂

@zoontek zoontek closed this as completed Feb 28, 2023
@hoodedice
Copy link

Hi, minor comment:
in this source file: react-native.config.js, we have:

        let config = JSON.parse(pkg)[CONFIG_KEY];

        if (!config && existsSync(jsonPath)) {
          const text = await fs.readFile(jsonPath, 'utf-8');
          config = JSON.parse(text);
        }

This leads to the package.json syntax being the same as in the Readme:

{
  "reactNativePermissionsIOS": [
  ]
}

but in the reactNativePermissionsIOS.json file it should just be an array. This is not very clear in the present Readme, and I got an error: Invalid "reactNativePermissionsIOS" config detected. It must be a non-empty array. when I used the json format as in the Readme

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants