iOS/설명

[iOS] Push Notification callback함수들

Sky Titan 2022. 4. 24. 14:28
728x90
 

[iOS] application(_:didReceiveRemoteNotification..)과 userNotificationCenter(_:didReceive..) 이 같이 있을 때 주의사항

# notification을 눌렀을 때 들어오는 메소드 1) application(_:didReceiveRemoteNotification:fetchCompletionHandler:) - remote notification을 눌렀을 때 들어오는 메소드 2) userNotificationCenter(_:didRec..

eunjin3786.tistory.com

 

iOS Push Notification / Silent Push 에 대해 Araboza

굿데이 여러분 2021 잘 보내구 계신가여 올해 첫글을 2월에 쓰게 되다니 반성합니다 오늘은 Push Notification 에 대해서 알아보게씀니다 iOS 10 이상 기준으로 진행할건데여 카카오톡도 12.0 이상 부터

hryang.tistory.com

Push Notification callback함수들

    • push notification을 사용할 때 AppDelegate에 선언하는 콜백 함수들은 크게 아래 3종류가 있다.
      • func application(_didReceiveRemoteNotification: fetchCompletionHandler:)
      • func userNotificationCenter(_:willPresent:WithCompletionHandler)
      • func userNotificationCenter(_:didReceive:WithCompletionHandler)
    • userNotificationCenter라고 이름 붙은 메서드들은 UNUserNotificationCenter의 delegate 함수들이고 application은 AppDelegate의 함수이다.

 

func application(_didReceiveRemoteNotification: fetchCompletionHandler:)

  • iOS10이전부터 사용되던 함수이고 remote push에 대해서만 동작을 하게 된다.
  • 아래의 함수들과 다르게 silent push가 오는 경우의 로직을 처리할 수 있다.
  • background상태에서 일반 push가 오면 푸쉬 배너를 click했을 때 호출된다.
    • silent push가 오는 경우에는 도착 즉시 메서드가 호출된다.

 

func userNotificationCenter(_:willPresent:WithCompletionHandler)

  • iOS10부터 사용되고 local, remote push 둘 다 동작한다.
  • foreground상태에서 push가 실행될 때 호출된다.
    • 만약 application(:didReceive)와 동시에 선언되어있는 상태에서 silent push가 도착하면 둘 다 호출된다.

 

func userNotificationCenter(_:didReceive:WithCompletionHandler)

  • iOS10부터 사용되고 local, remote push 둘 다 동작한다.
  • background상태에서  push를 클릭했을 때 호출된다.
    • 만약 application(:didReceive)와 동시에 선언되어있는 상태에서 remote push를 클릭 시 둘 다 호출된다.
항목 application(_:didReceiveRemoteNotification:fetchCompletionHandler:)  userNotificationCenter(_:willPresent:withCompletionHandler:)  userNotificationCenter(_:didReceive:withCompletionHandler:)
iOS 버전 iOS 7+ (iOS10 이전부터 존재) iOS 10+ iOS 10+
동작 대상 Remote Push만 Local + Remote Push Local + Remote Push
호출 시점 / 상황 - Silent Push: 도착 즉시 호출
- 일반 Push: 배너 클릭 시 호출
- Foreground 상태에서 푸시 도착 시 호출 - Background/Terminated 상태에서 푸시 클릭 시 호출
Silent Push 처리 ✅ 가능 ⚠️ (application(:didReceive)와 함께 호출될 수 있음) ⚠️ (application(:didReceive)와 함께 호출될 수 있음)
Foreground 상태
Background 상태 ✅ (배너 클릭 시 호출) ✅ (푸시 클릭 시 호출)
비고 iOS10 이후에도 동작하나, UNUserNotificationCenter 사용 권장 Foreground 시 알림 표시 여부 제어 가능 알림 클릭 시 특정 화면 이동 처리에 주로 사용
728x90