2017-05-05 1 views
3

Firebase admin SDK를 사용하여 노드 서버에서 푸시 알림을 전송합니다. 하지만 iOS에서 앱이 백그라운드에있을 때/포기할 때가 아니라 종료 될 때만 알림을 표시하려고합니다. 현재 알림이 항상 표시됩니다. 내 페이로드 뭔가포 그라운드에서 알림 표시 안 함

const payload = { 
    data: { 
    data: 'data', 
    more: 'moreData', 
    }, 
    notification: { 
    title: 'Incoming Call', 
    body: 'Someone is calling you', 
    text: 'This is some text', 
    sound: 'default', 
    click_action: 'com.example.INCOMING_CALL', 
    } 
}; 
const options = { 
    priority: 'high', 
    time_to_live: 30, 
    collapse_key: 'Video Call', 
    content_available: true, 
}; 

admin.messaging().sendToDevice(tokensList, payload, options); 

인가 아니면 내가 AppDelegate.swift에서해야 할 일이다

이 내 페이로드? iOS8의에서

당신은 applicationState를 사용하여 AppDelegate이 달성 할 수

답변

6

,

: iOS10에서

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) { 

    if !UIApplication.shared.applicationState == .active { 
    // Handle your push notification here 
    } 

} 

:

  1. import UserNotifications 프레임 워크
  2. UNUserNotificationCenterDelegate 방법을

    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { 
    
    
    if UIApplication.shared.applicationState == .active { // In iOS 10 if app is in foreground do nothing. 
        completionHandler([]) 
    } else { // If app is not active you can show banner, sound and badge. 
        completionHandler([.alert, .badge, .sound]) 
    } 
    
    } 
    

감사를 구현합니다.

2

iOS에서는 AppDelegate.swift에서 알림을 어떻게 처리할지 결정합니다. AppDelegate에서 해당 사례에 대한 알림을 처리하고 앱이 포 그라운드에있는 경우 삭제합니다. 응용 프로그램이 종료되고 당신은 통지에서 응용 프로그램을 실행할 때

는 아이폰 OS 10에서

, 통지를 처리하기 위해 사용, 전경에 대한 통지를 처리하기위한

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 

if launchOptions?[UIApplicationLaunchOptionsKey.remoteNotification] != nil { 
    if let remoteNotif = launchOptions?[UIApplicationLaunchOptionsKey.remoteNotification] as? NSDictionary 

    } 
} 

} 

에서이 방법을 그것을 처리

func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { 
    //handle notification here 

} 

백그라운드 알림을 처리하려면 다음 방법을 사용하십시오.

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping() -> Void) { 
    //handle notification here 

} 
관련 문제