To integrate firebase_messaging plugin into the iOS part of your app, follow these steps:
(Apple Push Notification service)
- APNs key. (Used by FCM to send Push Notifications to the app identified by the App ID)
- Create a new one here or use existing one:
- Click the Add (+) button and enter a description for the APNs Auth Key.
- Select the APNs checkbox
- Click Confirm and then Download. Save your key (sertificate?) in a secure place (*.p8).
- Note: this is a one-time download, and the key cannot be retrieved later.
- Take note of the Key ID.
- Create a new one here or use existing one:
- Create an App ID here or use existing one
- Click the + button and select App IDs radio button
- Select iOS, tvOS, watchOS under Platform
- Input a Description for your App ID (e.g. Firebase Sample App)
- Select Explicit App ID, then input your Bundle ID (e.g. com.google.samples.firebaseexample). The value of the Bundle ID should match the value that you are using in your app's Info.plist and the value that you are using to get a configuration for FCM
- In the Capabilities section, make sure that Push Notifications is checked.
- Take not of the Team ID (App ID Prefix)
- Click Continue and Register to create the App ID.
- A provisioning profile for that App ID (Can skip this section?). You need one for each app you want to publish. Note: it has an expiry date.
- Create one for your app here.
- Select App Store under Distribution, then select your existing App ID.
- Return to the profiles dashboard and check that your app has platform iOS and type App Store.
- Download and install double clicking on it.
- Using the Firebase Console add an iOS app to your project: Follow the assistant, download the generated GoogleService-Info.plist file, open ios/Runner.xcworkspace with Xcode, and within Xcode place the file inside ios/Runner.
- Don't follow the steps named Add Firebase SDK and Add initialization code in the Firebase assistant.
- In Xcode, select Runner in the Project Navigator. In the Capabilities Tab turn on Push Notifications and Background Modes,
- Bnder Background Modes enable Background fetch and Remote notifications.
- Inside your project in the Firebase console, select the gear icon, select Project Settings, and then select the Cloud Messaging tab.
- In APNs authentication key under iOS app configuration, click the Upload button
- Browse to the location where you saved your key, select it, and click Open. Add the key ID for the key and Team ID for your App ID, then click Upload
- Add the following lines to the
func application(_ application: UIApplication,didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool
method in the AppDelegate.swift of your iOS project:
if #available(iOS 10.0, *) { UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate }
- Flutter integration:
`@override void initState() { _configureMessaging(); super.initState(); }
Future _configureMessaging() async { _firebaseMessaging.configure( onMessage: (Map<String, dynamic> message) async { print("onMessage: $message"); }, onLaunch: (Map<String, dynamic> message) async { print("onLaunch: $message"); }, onResume: (Map<String, dynamic> message) async { print("onResume: $message"); }, ); _firebaseMessaging.requestNotificationPermissions( const IosNotificationSettings(sound: true, badge: true, alert: true)); _firebaseMessaging.onIosSettingsRegistered .listen((IosNotificationSettings settings) { print("Settings registered: $settings"); }); _firebaseMessaging.getToken().then((String token) async { print("Push Messaging getToken token: $token"); }); _firebaseMessaging.onTokenRefresh.listen((token) { print("Push Messaging onTokenRefresh token: $token"); }); }`