我需要迅速接收数据通知,并且不使用通知消息。仅使用数据消息。
这是我给邮递员的杰森
{
"to": "e32uafd....","data": {
"urlImage": "https://upload.wikimedia.org/wikipedia/commons/8/80/image.jpg","title": "title","body": "****body****.","mutable_content": true
}
}
这是我的快速代码
@available(iOS 10.0,*)
func userNotificationCenter(_ center: UNUserNotificationCenter,willPresent notification: UNNotification,withCompletionHandler completionHandler: @escaping (_ options: UNNotificationPresentationOptions) -> Void)
{
switch UIApplication.shared.applicationState
{
case .active:
completionHandler( [.alert,.sound])
break
default:
completionHandler( [.alert,.sound])
break
}
}
}
}