text stringlengths 1 474 |
|---|
the flag --cocoapods. This produces a Flutter.podspec |
instead of an engine Flutter.xcframework. |
The App.xcframework and plugin frameworks are generated |
as described in Option B.To generate the Flutter.podspec and frameworks, run the following |
from the command line in the root of your Flutter module:Host apps using CocoaPods can add Flutter to their Podfile: |
<code_start>pod 'Flutter', :podspec => 'some/path/MyApp/Flutter/[build mode]/Flutter.podspec'<code_end> |
info Note |
You must hard code the [build mode] value. |
For example, use Debug if you need to use |
flutter attach and Release when you’re ready to ship.Link and embed the generated App.xcframework, |
FlutterPluginRegistrant.xcframework, |
and any plugin frameworks into your existing application |
as described in Option B.<topic_end> |
<topic_start> |
Local Network Privacy Permissions |
On iOS 14 and higher, enable the Dart multicast DNS |
service in the Debug version of your app |
to add debugging functionalities such as hot-reload and |
DevTools via flutter attach.warning Warning |
This service must not be enabled in the Release |
version of your app, or you might experience App Store rejections.One way to do this is to maintain a separate copy of your app’s Info.plist per |
build configuration. The following instructions assume |
the default Debug and Release. |
Adjust the names as needed depending on your app’s build configurations.Rename your app’s Info.plist to Info-Debug.plist. |
Make a copy of it called Info-Release.plist and add it to your Xcode project.In Info-Debug.plist only add the key NSBonjourServices |
and set the value to an array with the string _dartVmService._tcp. |
Note Xcode will display this as “Bonjour services”.Optionally, add the key NSLocalNetworkUsageDescription set to your |
desired customized permission dialog text.In your target’s build settings, change the Info.plist File |
(INFOPLIST_FILE) setting path from path/to/Info.plist to path/to/Info-$(CONFIGURATION).plist.This will resolve to the path Info-Debug.plist in Debug and |
Info-Release.plist in Release.Alternatively, you can explicitly set the Debug path to Info-Debug.plist |
and the Release path to Info-Release.plist.If the Info-Release.plist copy is in your target’s Build Settings > Build Phases > Copy Bundle |
Resources build phase, remove it.The first Flutter screen loaded by your Debug app will now prompt |
for local network permission. The permission can also be allowed by enabling |
Settings > Privacy > Local Network > Your App.<topic_end> |
<topic_start> |
Apple Silicon (arm64 Macs) |
On an Apple Silicon (M1) Mac, the host app builds for an arm64 simulator. |
While Flutter supports arm64 simulators, some plugins might not. If you use |
one of these plugins, you might see a compilation error like Undefined symbols |
for architecture arm64 and you must exclude arm64 from the simulator |
architectures in your host app.In your host app target, find the Excluded Architectures (EXCLUDED_ARCHS) build setting. |
Click the right arrow disclosure indicator icon to expand the available build configurations. |
Hover over Debug and click the plus icon. Change Any SDK to Any iOS Simulator SDK. |
Add arm64 to the build settings value.When done correctly, Xcode will add "EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64; to your project.pbxproj file.Repeat for any iOS unit test targets.<topic_end> |
<topic_start> |
Development |
You can now add a Flutter screen to your existing application. |
<topic_end> |
<topic_start>Add a Flutter screen to an iOS app |
This guide describes how to add a single Flutter screen to an existing iOS app.<topic_end> |
<topic_start> |
Start a FlutterEngine and FlutterViewController |
To launch a Flutter screen from an existing iOS, you start a |
FlutterEngine and a FlutterViewController.The FlutterEngine serves as a host to the Dart VM and your Flutter runtime, |
and the FlutterViewController attaches to a FlutterEngine to pass |
input events into Flutter and to display frames rendered by the |
FlutterEngine.The FlutterEngine might have the same lifespan as your |
FlutterViewController or outlive your FlutterViewController.lightbulb Tip |
It’s generally recommended to pre-warm a long-lived |
FlutterEngine for your application because:See Loading sequence and performance |
for more analysis on the latency and memory |
trade-offs of pre-warming an engine.<topic_end> |
<topic_start> |
Create a FlutterEngine |
Where you create a FlutterEngine depends on your host app.In this example, we create a FlutterEngine object inside a SwiftUI ObservableObject. |
We then pass this FlutterEngine into a ContentView using the |
environmentObject() property. |
<code_start>import SwiftUI |
import Flutter |
// The following library connects plugins with iOS platform code to this app. |
import FlutterPluginRegistrant |
class FlutterDependencies: ObservableObject { |
let flutterEngine = FlutterEngine(name: "my flutter engine") |
init(){ |
// Runs the default Dart entrypoint with a default Flutter route. |
flutterEngine.run() |
// Connects plugins with iOS platform code to this app. |
GeneratedPluginRegistrant.register(with: self.flutterEngine); |
} |
} |
@main |
struct MyApp: App { |
// flutterDependencies will be injected using EnvironmentObject. |
@StateObject var flutterDependencies = FlutterDependencies() |
var body: some Scene { |
WindowGroup { |
ContentView().environmentObject(flutterDependencies) |
} |
} |
}<code_end> |
As an example, we demonstrate creating a |
FlutterEngine, exposed as a property, on app startup in |
the app delegate. |
<code_start>import UIKit |
import Flutter |
// The following library connects plugins with iOS platform code to this app. |
import FlutterPluginRegistrant |
@UIApplicationMain |
class AppDelegate: FlutterAppDelegate { // More on the FlutterAppDelegate. |
lazy var flutterEngine = FlutterEngine(name: "my flutter engine") |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.