250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- front-end
- IOS
- 백엔드
- 프론트엔드
- 자바스크립트
- 비전공 개발자
- hover
- php
- 개발자
- iPhone
- button
- HTML
- CSS
- css3
- jQuery
- keyframes
- Animation
- image
- ipad
- effect
- html5
- SWIFT
- 애니메이션
- iOS 개발자
- MAC
- 비전공자
- 풀스택
- react
- javascript
- xcode
Archives
- Today
- Total
비전공자 개발일기
Remote Push Notification(APNs, FCM) 본문
728x90
SMALL
Remote Notification 전송 방식
Provider(Server) -> APNs -> iOS, watchOS, tvOS, macOS -> ClientApp
APNs
Apple Push Notification Service (애플 개발자 계정 필요)
https://developer.apple.com/kr/
FCM
Firebase Cloud Message
// AppDelegate.swift
import UIKit
import Firebase
import UserNotifications
import FirebaseMessaging
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
UNUserNotificationCenter.current().delegate = self
return true
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
Messaging.messaging().delegate = self
// FCM Current Registration Token Verification
Messaging.messaging().token { token, error in
if let error = error {
print("Error FCM Token: \(error.localizedDescription)")
} else if let token = token {
print("FCM Token: \(token)")
}
}
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(options: authOptions) { _, error in
print("Error, Request Notifications Authrization: \(error.debugDescription)")
}
application.registerForRemoteNotifications()
return true
}
// MARK: UISceneSession Lifecycle
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}
}
extension AppDelegate: UNUserNotificationCenterDelegate {
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler([.list, .banner, .badge, .sound])
}
}
extension AppDelegate: MessagingDelegate {
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
guard let token = fcmToken else { return }
print("Renew FCM registration token: \(token)")
}
}
// SceneDelegate.swift
import UIKit
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
guard let _ = (scene as? UIWindowScene) else { return }
}
func sceneDidDisconnect(_ scene: UIScene) {
// Called as the scene is being released by the system.
// This occurs shortly after the scene enters the background, or when its session is discarded.
// Release any resources associated with this scene that can be re-created the next time the scene connects.
// The scene may re-connect later, as its session was not necessarily discarded (see `application:didDiscardSceneSessions` instead).
}
func sceneDidBecomeActive(_ scene: UIScene) {
if UIApplication.shared.applicationIconBadgeNumber != 0 {
UIApplication.shared.applicationIconBadgeNumber = 0
}
}
func sceneWillResignActive(_ scene: UIScene) {
// Called when the scene will move from an active state to an inactive state.
// This may occur due to temporary interruptions (ex. an incoming phone call).
}
func sceneWillEnterForeground(_ scene: UIScene) {
// Called as the scene transitions from the background to the foreground.
// Use this method to undo the changes made on entering the background.
}
func sceneDidEnterBackground(_ scene: UIScene) {
// Called as the scene transitions from the foreground to the background.
// Use this method to save data, release shared resources, and store enough scene-specific state information
// to restore the scene back to its current state.
}
}
728x90
LIST
'SWIFT' 카테고리의 다른 글
Real Time Notice' s modal (Firebase Remote Config & A/B Test) (0) | 2022.12.20 |
---|---|
Local Push Notification (0) | 2022.12.19 |
Diary (0) | 2022.12.18 |
Status of COVID-19 outbreak(CocoaPods, Alamfire, Charts) (0) | 2022.12.17 |
Do not Work pod init in workspace (0) | 2022.12.17 |