簡體   English   中英

應用程序收到推送通知iOS時如何在后台進行服務請求

[英]How to do service request in background when app receives push notification iOS

當應用程序收到推送通知時,我想在后台執行服務請求。 我能夠在前台和后台收到通知,在前台我使用下面的方法來執行服務請求,

func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
    completionHandler([.alert,.sound])
}

但是在后台我不知道如何進行服務請求,當應用程序在后台時沒有調用上述方法。 我怎樣才能做到這一點?

  1. 在功能選項卡中為推送通知啟用后台模式

  2. 實現 didReceiveRemoteNotification 方法並在那里添加您的服務請求代碼。

  3. 確保通知有效負載具有 "content-available": 1 用於靜默推送通知。

    就是這樣。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM