最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Permissions in IOS and flutter - Stack Overflow

programmeradmin2浏览0评论

I am pretty new to the mobile development world and I am writing an IOS/Android app using Flutter.

It seems that there are different ways to tell IOS about the permissions that my app needs. The first way is to add them in the Info.plist file. E.g.

<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
    <string>My explanation</string>

And then in the Podfile


post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
    target.build_configurations.each do |config|
      config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
      '$(inherited)',
      'PERMISSION_LOCATION=1',
      ]
      end
  end
end

I got things to work, but i'd like to understand why there are two places where I need to tell IOS about permissions. Is this a flutter specific thing? or is this just regular IOS and there is another purpose to this redundancy?

Thanks!

I am pretty new to the mobile development world and I am writing an IOS/Android app using Flutter.

It seems that there are different ways to tell IOS about the permissions that my app needs. The first way is to add them in the Info.plist file. E.g.

<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
    <string>My explanation</string>

And then in the Podfile


post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
    target.build_configurations.each do |config|
      config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
      '$(inherited)',
      'PERMISSION_LOCATION=1',
      ]
      end
  end
end

I got things to work, but i'd like to understand why there are two places where I need to tell IOS about permissions. Is this a flutter specific thing? or is this just regular IOS and there is another purpose to this redundancy?

Thanks!

Share Improve this question asked Mar 31 at 15:38 Nicola PedrettiNicola Pedretti 5,1943 gold badges41 silver badges46 bronze badges 4
  • Do you use the permission_handler package? – Peter Koltai Commented Mar 31 at 17:18
  • Exactly! You need todeclare permissions in two places.The Info.plist file and the Podfile. So, what's the difference? In Info.plist, you must declare the permissions because AppStoreConnect requires you to specify the purpose of each permission. If you don't include them,you may face issues when submitting your app. The Podfile ensures that the permission is enabled during the build and testing process. Without it,some permissions might not work correctly in your app You'll find more info in the permission_handler documentation – Frank Ray Yager Commented Mar 31 at 20:02
  • Peter Koltai, yeah, I do use the permission_handler package in the app to request the permissions. – Nicola Pedretti Commented Mar 31 at 20:49
  • @FrankRayYager thanks for the info. If i understand correctly, Info.plist is for AppStoreConnect review purposes, while the Podfile is for the platform to actually grant those permissions at the software level – Nicola Pedretti Commented Mar 31 at 20:51
Add a comment  | 

1 Answer 1

Reset to default 0

it's not redundancy—it’s two separate steps required by iOS for different reasons.

The two places where permissions are defined serve different purposes in iOS development, and this is not Flutter-specific—it's how iOS handles permissions at both runtime and compile-time.

1. Info.plist – Declaring Permissions for iOS
Purpose: This is required by iOS to display permission prompts to users.

How it works: When an app requests access to a feature (e.g., location, camera, microphone), iOS checks Info.plist for the corresponding usage description.

Example:


<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>We need your location to improve recommendations.</string>

Without this: The app will crash when requesting a permission because iOS enforces explicit usage descriptions.

2. Podfile – Configuring iOS Dependencies (Compile-Time)
Purpose: Some dependencies (like permission_handler) use preprocessor flags to enable/disable specific permissions at compile time.

Why? iOS apps must only include permissions they actually use, or Apple may reject the app.

Example:


post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
    target.build_configurations.each do |config|
      config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
        '$(inherited)',
        'PERMISSION_LOCATION=1',
      ]
    end
  end
end

How it works:

This tells the permission_handler plugin to include location permissions in the app.

If you omit this, iOS might strip out permission-related code, causing the permission request to fail at runtime.

Hope this information clears your doubt.

发布评论

评论列表(0)

  1. 暂无评论