![](/img/trans.png)
[英]Http request from iOS push notification action when app is in background
[英]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])
}
但是在后台我不知道如何進行服務請求,當應用程序在后台時沒有調用上述方法。 我怎樣才能做到這一點?
在功能選項卡中為推送通知啟用后台模式
實現 didReceiveRemoteNotification 方法並在那里添加您的服務請求代碼。
確保通知有效負載具有 "content-available": 1 用於靜默推送通知。
就是這樣。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.