Skip to main content

Building for iOS

1. Understanding iOS Project Structure

Folder/File Description Notes
ios/ Root folder for iOS-specific files Contains all Xcode project files and configurations
ios/Runner.xcodeproj/ Xcode project file Used to open and manage the iOS app in Xcode
ios/Runner.xcworkspace/ Xcode workspace file Used to manage dependencies and build configurations
ios/Runner/AppDelegate.swift Entry point for iOS app Handles app lifecycle events and integrates with Flutter engine
ios/Runner/Info.plist Configuration file for iOS app Defines app metadata, permissions, and settings
ios/Runner/Base.lproj/LaunchScreen.storyboard Launch screen layout Defines how the app appears while loading
ios/Runner/Base.lproj/Main.storyboard Main UI layout Defines the initial view controller and main app interface
ios/Runner/Assets.xcassets/ Asset catalog Stores app icons, launch images, and other assets

Example: Info.plist configuration

<?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>CFBundleDisplayName</key>
    <string>MyApp</string>
    <key>CFBundleIdentifier</key>
    <string>com.example.myapp</string>
    <key>CFBundleVersion</key>
    <string>1.0</string>
    <key>CFBundleShortVersionString</key>
    <string>1.0.0</string>
  </dict>
</plist>

2. Configuring Info.plist File

Property Value Description
CFBundleIdentifier com.example.myapp Unique identifier for the app
CFBundleName MyApp Name displayed to users
CFBundleDisplayName MyApp Display name in app launcher
CFBundleVersion 1.0.0 Build version shown to users
CFBundleShortVersionString 1.0.0 Marketing version shown to users
LSRequiresIPhoneOS true Indicates app requires iOS
UIRequiredDeviceCapabilities armv7 Minimum device capabilities required
UISupportedInterfaceOrientations UIInterfaceOrientationPortrait Supported screen orientations
UISupportedInterfaceOrientations~ipad UIInterfaceOrientationPortrait Supported orientations for iPad

Example: Adding Custom Permissions

<key>NSCameraUsageDescription</key>
&lt<string>This app needs access to the camera to take photos.</string>
Note: The Info.plist file is located in ios/Runner/Info.plist.

3. Setting Bundle Identifier and Version

Field Value Description
bundleIdentifier com.example.myapp Unique identifier for the iOS app bundle
version 1.0.0 App version string, used in App Store
buildNumber 1 Build number, incremented for each release

Example: Configuring in pubspec.yaml

name: myapp
description: A new Flutter project.
version: 1.0.0+1

environment:
  sdk: "^3.3.0"

dependencies:
  flutter:
    sdk: flutter

flutter:
  uses-material-design: true
  ios:
    bundleIdentifier: com.example.myapp
    version: 1.0.0
    buildNumber: 1

4. Configuring Deployment Target

Property Value Description
flutter.ios.deploymentTarget 12.0 Minimum iOS version required to run the app

Example: Setting deployment target in build.gradle

android {
    compileSdkVersion 33
    defaultConfig {
        targetSdkVersion 33
        minSdkVersion 12
    }
}
Note: Ensure that your Podfile also reflects the correct deployment target.

5. Using Build Configurations

Build configurations in Flutter allow you to manage different settings and behaviors for various environments such as development, staging, and production. These configurations are typically managed through flutter.yaml or by using environment-specific files.

Configuration Description Usage
debug Used for debugging and testing during development. Default configuration when running flutter run.
release Optimized for performance and size; suitable for production builds. Used when building for distribution via flutter build ios.
profile Includes performance profiling capabilities while maintaining optimized build settings. Used for performance analysis with flutter run --profile.

Example: Setting up build configurations in pubspec.yaml

flutter:
  uses-material-design: true

  # Define build configurations
  build:
    debug:
      environment:
        FLUTTER_ENV: development
    release:
      environment:
        FLUTTER_ENV: production
    profile:
      environment:
        FLUTTER_ENV: staging
Note: The FLUTTER_ENV variable can be accessed in your Dart code using Platform.environment['FLUTTER_ENV'].

Workflow: Managing Build Configurations

  1. Create a config.dart file to define environment variables.
  2. Use conditional logic based on the FLUTTER_ENV value to switch between configurations.
  3. Run flutter run --release or flutter run --profile to use specific configurations.

6. Building iOS App

Example: Build Flutter app for iOS

flutter build ios --release
Command Description Notes
flutter build ios Builds the iOS app in debug mode Uses default configuration
flutter build ios --release Builds the iOS app in release mode Optimizes for performance and size
flutter build ios --simulator Builds the iOS app for simulator Useful for testing without physical device
flutter build ios --target=<file> Specifies the main entry point file Defaults to lib/main.dart
Note: Ensure Xcode is installed and configured before building for iOS.
Warning: Release builds require code signing with a valid certificate.

7. Creating IPA Files

Note: IPA files are used for distributing iOS apps through the App Store or for ad-hoc distribution.
Step Description Command
1. Prepare for Release Ensure your app is configured for release mode and all assets are optimized. flutter build ios --release
2. Archive the App Use Xcode to archive your app after building it with Flutter. flutter build ios --release --no-codesign
3. Export IPA Export the archived app as an IPA file using Xcode or flutter build ios --release. xcodebuild -exportArchive -archivePath build/Runner.xcarchive -exportPath build/ios -exportFormat IPA

Example: Build and Export IPA

flutter build ios --release --no-codesign
xcodebuild -exportArchive -archivePath build/Runner.xcarchive -exportPath build/ios -exportFormat IPA
Note: You must have valid Apple Developer credentials and certificates set up in Xcode to successfully create an IPA file.

8. Setting Up Code Signing

Example: Xcode Code Signing Setup

flutter build ios --release
Step Description Action
1. Create Certificate Generate a development certificate in Apple Developer Portal Open Keychain Access > Certificates > Create Certificate
2. Configure Xcode Set up code signing in Xcode project settings Project > Signing & Capabilities > Team
3. Build Release Build the app with release configuration flutter build ios --release
Note: Ensure your Apple Developer account is active and the certificate is valid.
Warning: Incorrect code signing settings can prevent app installation on devices.

9. Using Xcode for Configuration

Workflow: Configuring iOS Build in Xcode

  1. Open the ios/Runner.xcworkspace file in Xcode
  2. Select the project target from the navigator
  3. Navigate to the Signing & Capabilities tab
  4. Enable Automatically manage signing or manually configure certificates
  5. Add required capabilities (e.g., Push Notifications, Background Modes)
  6. Set the deployment target to match Flutter's minimum iOS version (iOS 12.0 or higher)
  7. Configure the app bundle ID to match your Flutter project's bundleIdentifier
  8. Build and run the app from Xcode or archive for distribution
Configuration Description Value
bundleIdentifier Unique identifier for the iOS app com.example.myapp
deploymentTarget Minimum iOS version supported 12.0
signingCertificate Signing certificate for app distribution Apple Development

Example: Setting up Xcode Build Settings

flutter build ios --release
Note: Ensure that the Xcode project is configured with the correct provisioning profile and certificates for distribution.

10. Configuring Capabilities

Example: Enabling Push Notifications

import UserNotifications

func enablePushNotifications() {
    UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in
        if granted {
            print("Push notifications enabled")
        } else {
            print("Push notifications denied")
        }
    }
}
Capability Description Status
Push Notifications Enables sending push notifications to the app NEW
Background Modes Allows app to run in background for specific tasks DEPRECATED
In-App Purchases Enables purchase of digital goods within the app NEW
Note: Ensure that your app's Info.plist includes the necessary entitlements for each capability you enable.
Warning: Some capabilities require specific provisioning profiles and certificates from Apple Developer Portal.

Was this article helpful?