Visitar URL original
feat(messaging,ios): migrate example iOS runner from ObjC to Swift (#… · firebase/flutterfire@69d16e4 · GitHub
Skip to content

Commit 69d16e4

Browse files
authored
feat(messaging,ios): migrate example iOS runner from ObjC to Swift (#18578)
Keep the UIScene launch path and notification-center delegate setup so the example matches flutter create and Apple's launch requirements.
1 parent 989a177 commit 69d16e4

6 files changed

Lines changed: 46 additions & 48 deletions

File tree

‎packages/firebase_messaging/firebase_messaging/README.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ Apps that adopt the UIScene lifecycle register Flutter plugins after
2323
`UNUserNotificationCenter.delegate` to be configured before that method returns, so configure
2424
Firebase Messaging explicitly from your app delegate:
2525

26+
```swift
27+
override func application(
28+
_ application: UIApplication,
29+
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
30+
) -> Bool {
31+
FLTFirebaseMessagingPlugin.configureNotificationCenterDelegate()
32+
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
33+
}
34+
```
35+
2636
```objectivec
2737
#import <firebase_messaging/FLTFirebaseMessagingPlugin.h>
2838

‎packages/firebase_messaging/firebase_messaging/example/ios/Runner.xcodeproj/project.pbxproj‎

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
00E92990C987F9E25B63A112 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 45E51992A527D76267EB20C4 /* Pods_Runner.framework */; };
1111
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
1212
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
13-
978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */; };
14-
97C146F31CF9000F007C117D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 97C146F21CF9000F007C117D /* main.m */; };
13+
74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; };
1514
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
1615
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; };
1716
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; };
@@ -41,12 +40,11 @@
4140
45E51992A527D76267EB20C4 /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; };
4241
5213D4DB21693B7FDB92C6A0 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; };
4342
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
44-
7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
45-
7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
43+
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = "<group>"; };
44+
74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
4645
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = "<group>"; };
4746
9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = "<group>"; };
4847
97C146EE1CF9000F007C117D /* Firebase Cloud Messaging Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Firebase Cloud Messaging Example.app"; sourceTree = BUILT_PRODUCTS_DIR; };
49-
97C146F21CF9000F007C117D /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
5048
97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
5149
97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
5250
97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
@@ -113,27 +111,18 @@
113111
isa = PBXGroup;
114112
children = (
115113
27715A442538A1AE00757C2A /* Firebase Cloud Messaging Example.entitlements */,
116-
7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */,
117-
7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */,
114+
74858FAE1ED2DC5600515810 /* AppDelegate.swift */,
118115
97C146FA1CF9000F007C117D /* Main.storyboard */,
119116
97C146FD1CF9000F007C117D /* Assets.xcassets */,
120117
97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */,
121118
97C147021CF9000F007C117D /* Info.plist */,
122-
97C146F11CF9000F007C117D /* Supporting Files */,
123119
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */,
124120
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */,
121+
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */,
125122
);
126123
path = Runner;
127124
sourceTree = "<group>";
128125
};
129-
97C146F11CF9000F007C117D /* Supporting Files */ = {
130-
isa = PBXGroup;
131-
children = (
132-
97C146F21CF9000F007C117D /* main.m */,
133-
);
134-
name = "Supporting Files";
135-
sourceTree = "<group>";
136-
};
137126
C6DFB291D4DE268ECF1E3926 /* Frameworks */ = {
138127
isa = PBXGroup;
139128
children = (
@@ -184,6 +173,7 @@
184173
TargetAttributes = {
185174
97C146ED1CF9000F007C117D = {
186175
CreatedOnToolsVersion = 7.3.1;
176+
LastSwiftMigration = 1100;
187177
};
188178
};
189179
};
@@ -298,8 +288,7 @@
298288
isa = PBXSourcesBuildPhase;
299289
buildActionMask = 2147483647;
300290
files = (
301-
978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */,
302-
97C146F31CF9000F007C117D /* main.m in Sources */,
291+
74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */,
303292
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */,
304293
);
305294
runOnlyForDeploymentPostprocessing = 0;
@@ -382,6 +371,7 @@
382371
baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */;
383372
buildSettings = {
384373
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
374+
CLANG_ENABLE_MODULES = YES;
385375
CODE_SIGN_ENTITLEMENTS = "Runner/Firebase Cloud Messaging Example.entitlements";
386376
CODE_SIGN_IDENTITY = "Apple Development";
387377
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
@@ -405,6 +395,8 @@
405395
PRODUCT_BUNDLE_IDENTIFIER = io.flutter.plugins.firebase.tests;
406396
PRODUCT_NAME = "$(TARGET_NAME)";
407397
PROVISIONING_PROFILE_SPECIFIER = "";
398+
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
399+
SWIFT_VERSION = 5.0;
408400
VERSIONING_SYSTEM = "apple-generic";
409401
};
410402
name = Profile;
@@ -521,6 +513,7 @@
521513
baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */;
522514
buildSettings = {
523515
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
516+
CLANG_ENABLE_MODULES = YES;
524517
CODE_SIGN_ENTITLEMENTS = "Runner/Firebase Cloud Messaging Example.entitlements";
525518
CODE_SIGN_IDENTITY = "Apple Development";
526519
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
@@ -544,6 +537,9 @@
544537
PRODUCT_BUNDLE_IDENTIFIER = io.flutter.plugins.firebase.tests;
545538
PRODUCT_NAME = "$(TARGET_NAME)";
546539
PROVISIONING_PROFILE_SPECIFIER = "";
540+
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
541+
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
542+
SWIFT_VERSION = 5.0;
547543
VERSIONING_SYSTEM = "apple-generic";
548544
};
549545
name = Debug;
@@ -553,6 +549,7 @@
553549
baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */;
554550
buildSettings = {
555551
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
552+
CLANG_ENABLE_MODULES = YES;
556553
CODE_SIGN_ENTITLEMENTS = "Runner/Firebase Cloud Messaging Example.entitlements";
557554
CODE_SIGN_IDENTITY = "Apple Development";
558555
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
@@ -576,6 +573,8 @@
576573
PRODUCT_BUNDLE_IDENTIFIER = io.flutter.plugins.firebase.tests;
577574
PRODUCT_NAME = "$(TARGET_NAME)";
578575
PROVISIONING_PROFILE_SPECIFIER = "";
576+
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
577+
SWIFT_VERSION = 5.0;
579578
VERSIONING_SYSTEM = "apple-generic";
580579
};
581580
name = Release;

‎packages/firebase_messaging/firebase_messaging/example/ios/Runner/AppDelegate.h‎

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import Flutter
2+
import UIKit
3+
4+
@main
5+
@objc class AppDelegate: FlutterAppDelegate, FlutterImplicitEngineDelegate {
6+
override func application(
7+
_ application: UIApplication,
8+
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
9+
) -> Bool {
10+
// UIScene registers plugins after this method returns. Apple requires the
11+
// UNUserNotificationCenter delegate to be set before launch completes.
12+
FLTFirebaseMessagingPlugin.configureNotificationCenterDelegate()
13+
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
14+
}
15+
16+
func didInitializeImplicitFlutterEngine(_ engineBridge: FlutterImplicitEngineBridge) {
17+
GeneratedPluginRegistrant.register(with: engineBridge.pluginRegistry)
18+
}
19+
}

packages/firebase_messaging/firebase_messaging/example/ios/Runner/AppDelegate.m renamed to packages/firebase_messaging/firebase_messaging/example/ios/Runner/Runner-Bridging-Header.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#import "AppDelegate.h"
21
#import "GeneratedPluginRegistrant.h"
32

43
// `<firebase_messaging/...>` is the CocoaPods header layout. Swift Package
@@ -11,17 +10,3 @@
1110
#else
1211
@import firebase_messaging;
1312
#endif
14-
15-
@implementation AppDelegate
16-
17-
- (BOOL)application:(UIApplication *)application
18-
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
19-
[FLTFirebaseMessagingPlugin configureNotificationCenterDelegate];
20-
return [super application:application didFinishLaunchingWithOptions:launchOptions];
21-
}
22-
23-
- (void)didInitializeImplicitFlutterEngine:(NSObject<FlutterImplicitEngineBridge> *)engineBridge {
24-
[GeneratedPluginRegistrant registerWithRegistry:engineBridge.pluginRegistry];
25-
}
26-
27-
@end

‎packages/firebase_messaging/firebase_messaging/example/ios/Runner/main.m‎

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)