ํธ์์๋ฆผ์ ํตํด ์ฑ์ ๋ค์ด์ค๋ ๊ฒฝ์ฐ๋ ํฌ๊ฒ ๋๊ฐ์ง๋ก ๋๋ ์ ์์ด๋๋ค
- ์ฑ์ด ์์ ํ ์ข ๋ฃ๋ ์ํ
- inactive/active/background ์ํ
1๏ธโฃ ์ฑ์ด ์์ ํ ์ข ๋ฃ๋ ์ํ์์ ํธ์์๋ฆผ์ ํตํด ์ฑ์ ๋ค์ด์ค๋ ๊ฒฝ์ฐ
SceneDelegate์ willConnectTo์์ ์ฒ๋ฆฌ
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
...
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
...
// ์ฑ ์ข
๋ฃ ์ํ์์ ํธ์์๋ฆผ์ ํตํด ์ฑ์ ์ ์ํ๋ ๊ฒฝ์ฐ
if let notification = connectionOptions.notificationResponse {
// notification์ ํฌํจ๋์ด ์ ๋ฌ๋๋ content๋ ์๋์ ๊ฐ์ด ์ ๊ทผํ ์ ์์ต๋๋ค
let content = notification.notification.request.content
// dictionary ํํ๋ก, userInfo["key๊ฐ"] ์ผ๋ก ์ ๊ทผ ๊ฐ๋ฅ
let userInfo = content.userInfo
guard let recordId: String = userInfo["recordId"] as? String else { return }
// ์ํ๋ ๋ทฐ๋ก ์ ํ
}
}
...
}
2๏ธโฃ ์ฑ์ด ์์ ์ข ๋ฃ๋์ง ์์ ์ํ์์ ํธ์์๋ฆผ์ ํตํด ์ฑ์ ๋ค์ด์ค๋ ๊ฒฝ์ฐ (background / inactive / active)
์ด๋ฐ ์ํ์์ ์ฑ์ ์ ์ํ๋ ๊ฒฝ์ฐ, ์คํ๋์๋ฅผ ๊ฑฐ์น์ง ์๊ณ ๋ง์ง๋ง์ผ๋ก ์ฑ์ ์ฌ์ฉํ์๋ ๋ณธ ๋ทฐ๊ฐ ์ ์ง๋์ด ์์ต๋๋ค.
AppDelegate์ didReceive ์์ ์ฒ๋ฆฌ
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
...
// active / inactive / background
let applicationState = UIApplication.shared.applicationState
// ์ํ์ ๋ฐ๋ผ ์ํ๋ ๋ทฐ๋ก ์ ํ
if applicationState == .active || applicationState == .inactive {
// active ๋๋ inactive ์ํ์์ ํธ์์๋ฆผ์ ๋๋ฅธ ๊ฒฝ์ฐ ์ฒ๋ฆฌ
} else if applicationState == .background {
// background ์ํ์์ ํธ์์๋ฆผ์ ๋๋ฅธ ๊ฒฝ์ฐ ์ฒ๋ฆฌ
}
}
'iOS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[iOS] Compositional Layout ๐โโ๏ธ (0) | 2022.09.05 |
---|---|
[iOS] ์ปดํฌ๋ํธ๋ฅผ ์ฝ๋๋ฒ ์ด์ค, ์คํ ๋ฆฌ๋ณด๋์์ ๋๋ค ์ธ ์ ์๋๋ก ํ๋ ๋ฐฉ๋ฒ๐ฏ (1) | 2022.05.30 |
[iOS] RxDataSource ๐ก (0) | 2022.05.17 |
[iOS] Haptic ์ฌ์ฉ๋ฒ๐ (0) | 2022.04.23 |
[iOS] Diffable Datasourceโ (0) | 2022.03.18 |