How to Integrate Flutter Boost into an iOS (Objective‑C) Project
This guide walks through preparing an Xcode project with CocoaPods, adding a Flutter module as a dependency, implementing the required platform router in Objective‑C, binding it in AppDelegate, and using Flutter Boost’s open and present APIs to navigate between native and Flutter pages.
1. Introduction
After integrating Flutter Boost into an Android project, this article explains how to add the same capability to an iOS project written in Objective‑C.
2. Integration
2.1 Project preparation
Create a blank Xcode project that uses CocoaPods and add the previously built Flutter module as a pod in the
Podfile:
<code>flutter_application_path = '../flutter_module'
load File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')
target 'FlutterHybridiOS' do
install_all_flutter_pods(flutter_application_path)
end
</code>Run
pod installin the project root. The Pods list should now contain the Flutter modules, indicating a successful integration.
2.2 Implementing the router class
Copy the router implementation from the Flutter Boost example. The header declares the
FLBPlatformprotocol implementation:
<code>#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <flutter_boost/FlutterBoost.h>
NS_ASSUME_NONNULL_BEGIN
@protocol FLBPlatform;
NS_ASSUME_NONNULL_END
@interface PlatformRouterImp : NSObject <FLBPlatform>
@property (nonatomic, strong) UINavigationController *navigationController;
@end
</code>The implementation handles
open,
present, and
closeactions:
<code>#import "PlatformRouterImp.h"
#import <flutter_boost/FlutterBoost.h>
@implementation PlatformRouterImp
- (void)open:(NSString *)name urlParams:(NSDictionary *)params exts:(NSDictionary *)exts completion:(void(^)(BOOL))completion {
BOOL animated = [exts[@"animated"] boolValue];
FLBFlutterViewContainer *vc = FLBFlutterViewContainer.new;
[vc setName:name params:params];
[self.navigationController pushViewController:vc animated:animated];
if (completion) completion(YES);
}
- (void)present:(NSString *)name urlParams:(NSDictionary *)params exts:(NSDictionary *)exts completion:(void(^)(BOOL))completion {
BOOL animated = [exts[@"animated"] boolValue];
FLBFlutterViewContainer *vc = FLBFlutterViewContainer.new;
[vc setName:name params:params];
[self.navigationController presentViewController:vc animated:animated completion:^{ if (completion) completion(YES); }];
}
- (void)close:(NSString *)uid result:(NSDictionary *)result exts:(NSDictionary *)exts completion:(void(^)(BOOL))completion {
BOOL animated = [exts[@"animated"] boolValue];
UIViewController *vc = self.navigationController.presentedViewController;
if ([vc isKindOfClass:[FLBFlutterViewContainer class]] && [vc.uniqueIDString isEqual:uid]) {
[vc dismissViewControllerAnimated:animated completion:^{}];
} else {
[self.navigationController popViewControllerAnimated:animated];
}
if (completion) completion(YES);
}
@end
</code>2.3 Binding the router in AppDelegate
Add the router header to the project and configure it in
application:didFinishLaunchingWithOptions::
<code>#import "AppDelegate.h"
#import "PlatformRouterImp.h"
#import <flutter_boost/FlutterBoost.h>
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
PlatformRouterImp *router = [PlatformRouterImp new];
[[FlutterBoostPlugin sharedInstance] startFlutterWithPlatform:router onStart:^(FlutterEngine *engine) {
// optional engine configuration
}];
UITabBarController *tabVC = [[UITabBarController alloc] init];
UINavigationController *rvc = [[UINavigationController alloc] initWithRootViewController:tabVC];
router.navigationController = rvc;
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.rootViewController = rvc;
[self.window makeKeyAndVisible];
return YES;
}
@end
</code>2.4 Using Flutter Boost from native code
Open a Flutter page with a normal push:
<code>- (void)openClick:(UIButton *)button {
[FlutterBoostPlugin open:@"first" urlParams:@{kPageCallBackId:@"MycallbackId#1"} exts:@{@"animated":@(YES)} onPageFinished:^(NSDictionary *result) {
NSLog(@"call me when page finished, and your result is:%@", result);
} completion:^(BOOL finished) {
NSLog(@"page is opened");
}];
}
</code>Open a Flutter page as a modal presentation:
<code>- (void)openPresentClick:(UIButton *)button {
[FlutterBoostPlugin open:@"second" urlParams:@{@"present":@(YES), kPageCallBackId:@"MycallbackId#2"} exts:@{@"animated":@(YES)} onPageFinished:^(NSDictionary *result) {
NSLog(@"call me when page finished, and your result is:%@", result);
} completion:^(BOOL finished) {
NSLog(@"page is presented");
}];
}
</code>Both methods demonstrate how native iOS code can push or present Flutter pages and receive callbacks.
3. Run the app
After the above steps, the iOS project is fully integrated with Flutter Boost. Build and run the app to start the hybrid development experience.
QQ Music Frontend Team
QQ Music Web Frontend Team
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.