-
Notifications
You must be signed in to change notification settings - Fork 338
Setup IOS in case of Object C project
By Andrea Antonello.
Based on how your flutter project has been created, you might find yourself with an object-c project (you will recognise it from the presence of the files AppDelegate.m and main.m)
Your best bet is to convert the project into a SWIFT project. To do so the steps listed below are necessary. Consider doing them from within Xcode (i.e. not from terminal or the file manager), since it will make sure that references to files in the project files are removed and added when necessary.
- Delete the files:
- AppDelegate.m
- AppDelegate.h
- main.m
- Create a new SWIFT file named AppDelegate.swift and paste into it the the following lines:
import background_locator
func registerPlugins(registry: FlutterPluginRegistry) -> () {
GeneratedPluginRegistrant.register(with: registry)
}
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
BackgroundLocatorPlugin.setPluginRegistrantCallback(registerPlugins)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
When the file is created, you should be prompted for the generation of a Runner-bridging-Header.h file. It is important that is it created and contains the following line: #import "GeneratedPluginRegistrant.h"
- The last step requires to make a change in the Podfile. Add to the target Runner the entries use_frameworks and use_modular_headers. It should then look like:
...
target 'Runner' do
use_frameworks!
use_modular_headers!
# Flutter Pod
copied_flutter_dir = File.join(__dir__, 'Flutter')
copied_framework_path = File.join(copied_flutter_dir, 'Flutter.framework')
...
After the changes it will be necessary to clean and rebuild the pods. This can be done by removing the:
- Podfile.lock
- Pods folder
- Runner.xcworkspace
Then run the command pod install
inside the ios folder and rebuild the project.