0

I am trying to set up push notifications for the iOS app written in Flutter. I have found the following package: firebase_messaging 6.0.9 (https://pub.dev/packages/firebase_messaging).

I am at the 5th point (iOS setup) which is not very clear to me. The part I am struggling with is:

Add the following lines to the (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method in the AppDelegate.m/AppDelegate.swift of your iOS project.

I have AppDelegate.swift file but I do not know where to put this line of the code. No matter where I put it, the app will crash.

My App Delegate file looks like this:

import UIKit
import Flutter

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}

My background is in JavaScript mostly React, I do not know much about iOS or swift so in an ideal world I would love to read much clearer documentation that would help a newbie like me use this package. I hope there is someone that knows exactly what to do or even used this package before.

Any help is welcome. Is this package any good? Maybe there is a much better package with clearer documentation that you have managed to use successfully? Thank you very much for all the help and comments!

1 Answer 1

3

If your file is AppDelegate.swift you just add the condition under in -> Bool {...}.

import UIKit
import Flutter

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
    if #available(iOS 10.0, *) {
       UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
    }
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.