Mobile/iOS

iOS FCM 푸시 알림 #1 - FCM 프로젝트 생성

WonYoungJae 2023. 1. 14. 15:41

💡 FCM 푸시는 솔직히 이런저런 세팅 해주는게 대부분이다. 코드는 문서에 나와있는것만 써도 일반적으로 사용하기 충분하다.

FCM 프로젝트 생성

  1. FCM 콘솔에 로그인 후 프로젝트 추가 클릭

https://console.firebase.google.com/

  1. 프로젝트 이름 입력 후 계속 클릭

  1. 계속 클릭 후 계정선택 → Default Account for Firebase 선택 → 프로젝트 만들기 클릭

프로젝트에 앱 추가

  1. iOS 앱 추가 버튼 클릭

  1. xcode에서 Bundle Id 확인

  1. Bundle Id 입력 후 앱 등록 클릭

  1. .plist 파일 다운로드 → xcode에서 프로젝트 루트 디렉토리에 추가 후 다음 클릭

  1. firebase 라이브러리 추가
# pod 파일이 없을 경우 프로젝트 최상단에서 명령어 실행

pod init
# Podfile 수정
target 프로젝트명 do
    use_frameworks!

# --- 아래 두줄 추가 ---
    pod 'FirebaseAnalytics'
    pod 'FirebaseMessaging'
# -------------------

end
# pod init 했던 위치에서 실행

pod install --repo-update

open 프로젝트명.xcworkspace
  1. 초기화 코드 추가

Swift

// 프로젝트명App.swift

import UIKit
// --- FirebaseCore 임포트 ---
import FirebaseCore

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(_ application: UIApplication,
                     didFinishLaunchingWithOptions launchOptions: [UIApplication
                        .LaunchOptionsKey: Any]?) -> Bool {
         // --- Firebase 초기화 ---
        FirebaseApp.configure()

        return true
    } 

    ...
}

Objective-C

// AppDelegate.m

#import "AppDelegate.h"

// --- FirebaseCore 임포트 ---
@import FirebaseCore;

@interface AppDelegate ()

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
     // --- Firebase 초기화 ---
    [FIRApp configure];

    return YES;
}

💡 이걸로 FCM 쪽 설정은 끝났다. 다음 포스트에선 apple developer 쪽 설정을 할거다. 위에서 말 했듯이 세팅이 대부분이라 순서대로 따라오면 문제 없을거다.

728x90