dev/flutter

flutter - ios fcm 설정

wlrn566 2023. 7. 25. 10:51

ios에서 fcm 푸시 알람 기능을 구현하려면 애플 개발자 계정이 필요하다.

 

1. 애플 개발자 계정 로그인

 

 

2. Certificates, Identifiers & Profiles 페이지의 Keys 탭에서 Key 추가 

 

 

 

3. Apns 체크 후 완료 및 다운로드

** 한번 다운로드 받으면 다시 받을 수 없으니 보관 잘하기

 

 

4. Firebase 프로젝트 - 클라우드 메시징 탭 - Apple 앱 구성 - APN 인증 키 업로드

 

 

5. Xcode - Runner - Capability 추가

참고 : https://firebase.flutter.dev/docs/messaging/apple-integration/

 

FCM via APNs Integration | FlutterFire

iOS & macOS require additional configuration steps to be completed before you can receive messages.

firebase.flutter.dev

 

 

 

6. Backgroud fetch, Remote notifications 체크

 

 

 

7. AppDelegate.swift 푸시 알람 코드 추가

 

override func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 
    // ios 10.0 이후 UserNotificationCenter가 푸시 알람 관리
		if #available(iOS 10.0, *) {
      UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
    }

    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)

 

 

8. 포그라운드에서 푸시 알림 띄우기

안드로이드와 ios 둘 다 포그라운드 알림을 위해 따로 코드를 작성해줘야 한다.

 

await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions(
    alert: true, // Required to display a heads up notification
    badge: true,
    sound: true,
);