Apple Develper Site Setting
1. APNs key ์ค๋น
Apple Developer ์ฌ์ดํธ > ์ผ์ชฝ ๋ฉ๋ด > Keys ์ ํ
Keys + ๋ฒํผ์ ๋๋ฌ ์๋ก์ด ํค ๋ฑ๋ก
Apple Push Notification service ๋ฒํผ์ ๋๋ฅด๊ณ , key name์ ์ง์
Continue ๋ฒํผ์ด ํ์ฑํ ๋๋ฉด ๋๋ฌ ์ค
์ ๋ณด๋ฅผ ํ์ธํ ๋ค Register์ ๋๋ฌ ํค๋ฅผ ๋ฑ๋กํจ
2. Key ID ํ์ธ
์ธ์ฆ ํค์ Key ID ํ์ธ
์ถํ Firebase ์ค์ ์ ํ์ํจ
3. Team ID ํ์ธ
apple developer ์ธ์ฆ์, ์๋ณ์ ๋ฐ ํ๋กํ์ผ ๊ด๋ฆฌ ํ์ด์ง์์ ์ค๋ฅธ์ชฝ ์๋จ์ ํ ์์ด๋๊ฐ ๋์ ์์ง๋ง ํด๋น ์ฌ์ดํธ๋ก๋ ํ์ธ ๊ฐ๋ฅ
๋ก๊ทธ์ธ - Apple
idmsa.apple.com
๋ก๊ทธ์ธ ํ ์คํฌ๋กค ํ๊ฒ ๋๋ฉด ๋ฉค๋ฒ์ญ ์ธ๋ถ ์ฌํญ ์น์ ์ด ์๊ณ ์ฌ๊ธฐ์ ํ ID๋ฅผ ํ์ธ ํ ์ ์์
Firebase Setting
iOS ํ๋ซํผ ์ ํ ํ ์ฑ ๋ฑ๋ก ์ ๋ณด ์ ๋ ฅ
GoogleService info plist ํ์ผ์ ํ๋ก์ ํธ์ ํฌํจ ์ํด
๊ฐ๋ฐ๊ณผ ์ด์์ ๋ฒ๋ค ์์ด๋๊ฐ ๋ค๋ฅด๋ค๋ฉด ์์ ๊ฐ์ด ๋ถ๋ฆฌํ์ฌ ํด๋์ ๋ด์์ค
ํ๋ก์ ํธ ๋ฉ์ธ ํ์ด์ง์์ ๋ฑ๋กํด ์ค ์ฑ์ ํฑ๋ ๋ฐํด ๋ฒํผ์ ๋๋ฌ ์ค์ ํ์ด์ง๋ก ์ด๋
ํด๋ผ์ฐ๋ ๋ฉ์ธ์ง ํญ ์ง์
์ค์ ํ ์ฑ์ ์ ํํ๊ณ APN ์ธ์ฆ ํค ์ธ์ ์์ ์ ๋ก๋ ๋ฒํผ ํด๋ฆญ
์ด์ ๋จ๊ณ์์ ์์ฑ ํด ๋ key์ ํค ID, ํ ID๋ฅผ ์์ฑ ํ ํ ์ ๋ก๋ ๋ฒํผ์ ๋๋ฌ ์ค์ ์๋ฃ
ํ ID๋ ์ผ๋ฐ ํญ์์ ๋ด ์ฑ ์น์ > ํ ID์์๋ ์ค์ ํ ์ ์์ผ๋ฉฐ ์ด๋ ํค ๋ฑ๋ก์ ํ ID๊ฐ ์์ ๋ถ๊ฐ๋ฅํ ํํ๋ก ์ด๋ฏธ ์์ฑ๋์ด ์์
Xcode Setting
pod 'Firebase/Analytics'
pod 'Firebase/Messaging'
pod file์ Firebase ๋ฅผ ์ถ๊ฐํด ์ค ๋ค install ํน์ update
์ด๋ฏธ ํ๋ก๋น์ ๋์ด ๋ฑ๋ก๋์ด ์๋ค๋ฉด Push Notifications๋ฅผ ๋๋ฌ ์ถ๊ฐํด ์ฃผ๊ณ ์๋จ Save ๋ฒํผ์ ๋๋ฌ ์ ์ฅ
์ฌ ๋ค์ด๋ก๋ ๋ฐ์ XCode ํ๋ก์ ํธ์ ์ ์ฉ ์ํด
Signing&Capabilities์์ +Capability๋ฅผ ๋๋ฌ ๋ํ๋๋ ํ๋ฉด์์ Push Notifications๋ฅผ ๋๋ฌ ๋ฑ๋ก
Code Side
AppDelegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
application.registerForRemoteNotifications()
Messaging.messaging().delegate = self
Messaging.messaging().isAutoInitEnabled = true
return true
}
/// ํ ํฐ ์ค์
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken
}
/// ํ ํฐ ํ๋
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
Messaging.messaging().token { token, error in
if let error = error {
print("๐๐๐๐๐ Error fetching FCM registration token: \(error)")
} else if let token = token {
print("๐๐๐๐๐ FCM registration token: \(token)")
}
}
}
extension HomeViewController: UNUserNotificationCenterDelegate { }
Remote Notification์ด ์ค๋ฉด ์ฒ๋ฆฌํ ํด๋์ค์์ UNUserNotifiationCenterDelegate๋ฅผ ์ฑํ
// Foreground
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler([.alert, .sound, .badge])
}
// Background
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
}
์ฑ์ด Foreground, Background์ ๊ฒฝ์ฐ ์ ๋ฉ์๋๊ฐ ํธ์ถ๋จ
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// remote notification
if let response = connectionOptions.notificationResponse {
let userInfo = response.notification
.request.content.userInfo
}
}
์ฑ์ด ์์ ํ ์ข ๋ฃ๋ ์ํ์์ ํธ์๋ฅผ ๋๋ฌ ์ฑ์ ์คํํ๋ ๊ฒฝ์ฐ SceneDeleate์์๋ ์์ ๊ฐ์ด ๋ฐ์ดํฐ๋ฅผ ๋ฐ์ ์ ์์
GoogleService Info Plist ํ์ผ์ ์ด๋ฆ์ ๋ณ๊ฒฝํ ๊ฒฝ์ฐ AppDelegate์์ ์ค์ ํ์
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
var filePath: String!
#if DEBUG
filePath = Bundle.main.path(forResource: "GoogleService-Info-dev", ofType: "plist")
#else
filePath = Bundle.main.path(forResource: "GoogleService-Info-release", ofType: "plist")
#endif
let options = FirebaseOptions.init(contentsOfFile: filePath)!
FirebaseApp.configure(options: options)
}
์ถํ ๋ฐ์ดํฐ ํธ๋ค๋ง ํฌ์คํ
Firebase Cloud message
(๊ธ ์์ฑ ์์ 2023.03.08 / ํ์ด์ด๋ฒ ์ด์ค ํ๋ก์ ํธ ํ์ด์ง๋ ์์๋ก ๋ณ๊ฒฝ๋๋ฏ๋ก ๋ ์ง ํ์ธ ํ์)
์ผ์ชฝ ๋ฉ๋ด์์ ๋ชจ๋ ์ ํ์ ๋๋ฅธ ํ ๊ฐฑ์ ๋๋ ํ๋ฉด์์ Cloud Messaging์ ๋๋ฌ์ค
๊ทธ ํ ์ผ์ชฝ ๋ฉ๋ด์ Messaging ๋ ธ์ถ ๋๋ฉฐ ์ดํ์๋ ์ด ๋ฉ๋ด๋ฅผ ๋๋ฌ ์ ๊ทผํ๋ฉด ๋จ
์ฒซ ๋ฒ์งธ ์บ ํ์ธ ๋ง๋ค๊ธฐ ์ ํ
Firebase ์๋ฆผ ๋ฉ์์ง๋ฅผ ์ ํ
์ ๋ณด๋ฅผ ์ ๋ ฅ ํด ์ค ๋ค ๋ค์ ๋ฒํผ ๋๋ฆ
ํธ์๋ฅผ ๋ณด๋ผ ํ๊ฒ ์ฑ์ ์ ํ ํ ๋ค ๋ค์
์๊ฐ ์ค์ ํ ๋ค์ ๋๋ฅธ ๋ค ๊ฒ์ํด ์ฃผ๋ฉด ์บ ํ์ธ์ด ์ ์ฅ๋๊ณ ํธ์๊ฐ ๊ฐ
์ด๋ฏธ์ง ์ถ์ฒ : https://www.pexels.com/ko-kr/photo/15007786/
'๐ iOS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Swift] ๊ณ ์ฐจ ํจ์ CompactMap (2) | 2023.03.09 |
---|---|
[iOS/Swift] Dynamic Link ์ ๋ฆฌ (0) | 2023.03.08 |
[iOS/Swift] Localization ์ฝ๋๋ก ๋ค๊ตญ์ด ์ฒ๋ฆฌ (0) | 2023.02.23 |
[iOS/Swift] SafeArea ๋์ด ๊ตฌํ๊ธฐ (0) | 2023.02.05 |
[iOS/Swift] UIDevice ๋ฒ์ , UUID, ๊ธฐ๊ธฐ ์ ๋ณด ๊ฐ์ ธ์ค๊ธฐ (0) | 2023.02.04 |
๋๊ธ