Since Apple now requires a PrivacyInfo.xcprivacy
file for all apps submitted to the App Store, Flutter developers targeting iOS need to ensure this file is included in their projects. This article provides a step-by-step guide on how to manually add this file and configure your project correctly.
Why is a PrivacyInfo.xcprivacy File Required?
This file declares your app’s data collection, use, and security practices. It helps users understand how their data is handled and improves transparency on the App Store.
Step-by-Step Guide to Adding the PrivacyInfo.xcprivacy File
-
Create the PrivacyInfo.xcprivacy File:
Create a new file named
PrivacyInfo.xcprivacy
in your Flutter project’sios/Runner
directory. You can use a text editor or Xcode. -
Add Content to the File:
The
PrivacyInfo.xcprivacy
file is a plist (property list) file in XML format. It needs specific keys and values that describe your app’s privacy practices. The contents will depend on your app’s specific requirements. Here’s a basic example structure:<?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> <key>NSPrivacyTracking</key> <true/> <key>NSPrivacyTrackingDomains</key> <array> <string>example.com</string> </array> <key>NSPrivacyCollectedDataTypes</key> <array> <dict> <key>NSPrivacyCollectedDataType</key> <string>NSPrivacyCollectedDataTypeContactInfo</string> <key>NSPrivacyCollectedDataTypeLinked</key> <true/> <key>NSPrivacyCollectedDataTypePurposes</key> <array> <string>NSPrivacyCollectedDataTypePurposeThirdPartyAdvertising</string> </array> </dict> </array> <key>NSPrivacyAccessedAPICategoryFileTimestamp</key> <false/> </dict> </plist>
Important: This is a simplified example. You must consult Apple’s official documentation and your app’s actual data usage to determine the correct values for each key. Keys like
NSPrivacyTracking
,NSPrivacyTrackingDomains
, andNSPrivacyCollectedDataTypes
require accurate information about your app’s data collection practices.
Failure to do so can result in your app being rejected.Refer to Apple’s documentation for a complete list of available keys and their meanings: Apple Privacy Manifest Documentation
-
Add the file to your Xcode project:
- Open the
ios/Runner.xcworkspace
file in Xcode. - Right-click on the
Runner
group in the Project navigator. - Select “Add Files to ‘Runner’…”.
- Navigate to your
PrivacyInfo.xcprivacy
file in theios/Runner
directory and select it. - Make sure the “Add to targets” checkbox is selected for the
Runner
target. - Click “Add”.
- Open the
-
Verify the File is Included in the Bundle:
In Xcode, select the
Runner
target, then go to the “Build Phases” tab. Expand the “Copy Bundle Resources” phase and ensure thatPrivacyInfo.xcprivacy
is listed. -
Update `pbxproj` file (If needed):
Sometimes the project might not automatically update. In this case, you need to manually modify the
pbxproj
file. To do so, open theios/Runner.xcodeproj/project.pbxproj
file in a text editor.
You need to add the file reference to the PBXBuildFile section and the file itself to the PBXResourcesBuildPhase section./* Begin PBXBuildFile section */ ... XXXXXXXXXXXXXX /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = YYYYYYYYYYYYYY /* PrivacyInfo.xcprivacy */; settings = {ASSET_PACK_COMPILATION = YES; }; }; ... /* End PBXBuildFile section */ /* Begin PBXFileReference section */ ... YYYYYYYYYYYYYY /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = PrivacyInfo.xcprivacy; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; }; ... /* End PBXFileReference section */ /* Begin PBXResourcesBuildPhase section */ ... files = ( ... XXXXXXXXXXXXXX /* PrivacyInfo.xcprivacy in Resources */, ... ); ... /* End PBXResourcesBuildPhase section */
Replace `XXXXXXXXXXXXXX` and `YYYYYYYYYYYYYY` with unique IDs generated in your project. You can generate these IDs using a UUID generator online or within Xcode.
Common Errors and Solutions
-
Error: “Missing Privacy Manifest File” during App Store submission.
Solution: Double-check that the
PrivacyInfo.xcprivacy
file exists in the correct directory (ios/Runner
), is correctly added to your Xcode project’s “Copy Bundle Resources” build phase, and contains valid XML. -
Error: App rejected due to inaccurate privacy declarations.
Solution: Carefully review the content of your
PrivacyInfo.xcprivacy
file. Ensure that all declared data collection practices are accurate and comprehensive. Consult Apple’s documentation for detailed guidance on each key and its permissible values.
Conclusion
Adding a PrivacyInfo.xcprivacy
file is a crucial step for Flutter iOS app development to meet Apple’s requirements. By following this guide and ensuring accurate privacy declarations, you can avoid potential rejection and maintain transparency with your users.