- APNS๋?
- ์๋์๋ฆฌ
- Push notification ์ค์
APNS๋?
- third party ๊ฐ๋ฐ์๊ฐ ์ฐ๋ฆฌ ์ฑ์ ํธ์ ์๋์ ๋ณด๋ผ ์ ์๋๋ก Apple์์ ๋ง๋ ์๋ฆผ ์๋น์ค ํ๋ซํผ
- ์ฆ, ๋ชจ๋ ํธ์ฌ์๋ฆผ์ ๋ณด๋ด๊ธฐ ์ํด ์ค์ฌ๋ฅผ ํ๊ณ ์๋ ์ผํฐ
- Apple์ Server๊ฐ ์ฑ์ ์ง์ ์๋์ ๋ณด๋ด๋ ๊ฒ์ ๋ถํํ๊ณ ํญ์ APNs๋ผ๋ ํ๋ซํผ์ ํตํด์๋ง ๋ณด๋ผ ์ ์๊ฒ ํจ
์๋๋ฐฉ์
1. App์ด APNs์๊ฒ remote notification ๋ฑ๋ก ์์ฒญ
2. APNs๊ฐ App์๊ฒ ์ฑ๊ณต์ ์ผ๋ก ๋์์์ ์๋ ค์ค๊ณผ ๋์์ Device Token ์ ๋ฌ
3. App์ด Push Server์๊ฒ Device Token์ ๋ณด๋ด๊ณ , Server๋ ํด๋น ํ ํฐ์ ์ ์ฅํ๊ณ ์๋๋ค. Server๋ ๋ด๊ฐ ๋ง๋ ์๋ฒ์ผ ์๋ ์๊ณ , ๋ค๋ฅธ ๊ธฐ์ ์์ ์ ๊ณตํ๋ ์๋ฒ๋ฅผ ์ด์ฉํ ์๋ ์๋ค (ex Firebase Cloud Messaging)
4. Server๋ ํธ์๋ฅผ ๋ณด๋ด๊ณ ์ถ์ ๋, APNs์๊ฒ Device Token๊ณผ ๋ฐ์ดํฐ๋ฅผ ๋ณด๋ธ๋ค. ์ด๋ APNs์ Server๋ TLS ํต์ ์ ํ๊ธฐ ๋๋ฌธ์, Server์๋ ์ธ์ฆ์๊ฐ ์ค๋น๋์ด ์์ด์ผ ํ๋ค.
5. APNs๋ ํด๋น Device Token์ผ๋ก ๋ฐ์ดํฐ๋ฅผ ๋ณด๋ธ๋ค.
๋ด Device๊ฐ Background ์ํ๋ฉด OS๊ฐ ์ฒ๋ฆฌํด์ ํธ์์๋ฆผ์ ๋์ฐ๊ณ , Foreground ์ํ๋ฉด AppDelegate์ ์ ์ํด๋์ ๋ฐฉ์ ๋๋ก APP ์์ ๋์์ง๋ค.
Push notification ์ค์
- ๊ฐ์ธ์ธ์ฆ์ ์์ฑ
- ํค์ฒด์ธ → ์ธ์ฆ์ ์ง์ → ์ธ์ฆ ๊ธฐ๊ด์์ ์ธ์ฆ์ ์์ฒญ
- ํธ์์ธ์ฆ์ ์์ฑ
- ๊ฐ๋ฐ์ ์ฌ์ดํธ → Identifiers → Create Certificate (๊ฐ๋ฐ์ฉ ๋ฐฐํฌ์ฉ ๋ฐ๋ก ์กด์ฌ) → ๊ฐ์ธ ์ธ์ฆ์(certSigningRequest) ์ฒจ๋ถ → ํธ์์ธ์ฆ์ ์์ฑ ๋ฐ ๋ค์ด๋ก๋
- ํธ์์ธ์ฆ์ ํค์ฒด์ธ์ ๋ฑ๋ก
- ๋ค์ด๋ฐ์ ํธ์์ธ์ฆ์ ๋๋ธํด๋ฆญ → ํค์ฒด์ธ๋ฑ๋ก → ํธ์์ธ์ฆ์์ ๊ฐ์ธํค๋ ๊ฐ์ธ์ธ์ฆ์์ ์ด๋ฆ์ผ๋ก ๋ฑ๋ก
- ์๋ฒ์ฉ ์ธ์ฆ์ ์์ฑ
- ํธ์์ธ์ฆ์์ ๊ฐ์ธํค๋ฅผ p12 ํ์ผ๋ก ์ ์ฅ → ๋๊ฐ์ p12ํ์ผ๋ก ๊ฐ๊ฐ pemํ์ผ ์์ฑ → ๋๊ฐ์ pem ํ์ผ์ ํฉ์ณ ํ๋์ pem ํ์ผ (์๋ฒ์ฉ ์ธ์ฆ์) ์์ฑ → ์๋ฒ์ ํด๋น ์ธ์ฆ์๋ฅผ ์ ์ฅ
- ํ๋ก์ ํธ ์ค์
- iOS ํ๋ก์ ํธ์์ Push Notification, Background Modes ํ์ฑํ
- AppDelegate ์์
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// APNs์๊ฒ remote notificaiton ๋ฑ๋ก์์ฒญ
application.registerForRemoteNotifications()
}
// APNS ์๋ฒ์ ๋๋ฐ์ด์ค ๋ฑ๋ก ์ฑ๊ณต
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
// ํ ํฐ์ ์๋ฒ์ ์๋ ค์ค๋ค
}
// APNS ์๋ฒ์ ๋ฑ๋ก ์คํจ
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
// do something
}
// foreground ์ํ์์ push notification ์์ ์
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
// do something
}
}
์ฐธ๊ณ
'iOS ๐ > iOS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
App Extension (0) | 2021.12.06 |
---|---|
Xcode Target, Project, Workspace (0) | 2021.12.06 |
Responder chain (1) (0) | 2021.12.06 |
[Objective-C] atomic vs nonatomic (0) | 2021.12.06 |
iOS Code Signing (0) | 2021.06.25 |