我被困了好几天了,需要你的帮助。
\n我想接收静默推送通知(又称后台通知)来更新我的应用程序内容。
\nAppDelegate 中的以下部分不会被调用。
\nfunc application(_ application: UIApplication,\n didReceiveRemoteNotification userInfo: [AnyHashable: Any],\n fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult)\n -> Void) {\n \n if let messageID = userInfo[gcmMessageIDKey] {\n print("Message ID: \\(messageID)") // Does not get printed\n }\n\n print("success") // Does not get printed\n\n completionHandler(UIBackgroundFetchResult.newData)\n \n}\nRun Code Online (Sandbox Code Playgroud)\n下面是服务器端的Python代码。服务器端说向设备发送通知成功,所以我认为问题出在前端。
\ndef send_notifications_to_fcm_token(fcm_token):\n try:\n message = messaging.Message(\n apns=messaging.APNSConfig(\n headers={\n 'apns-push-type': 'background',\n 'apns-priority': '5',\n },\n payload=messaging.APNSPayload(\n aps=messaging.Aps(content_available=True)\n ),\n ),\n token=fcm_token,\n )\n response = messaging.send(message)\n except:\n response = False\n return response\nRun Code Online (Sandbox Code Playgroud)\n一些附加说明。
\n …当我尝试比较任务修改器中的值时,出现以下错误。
运算符函数“==”要求“Binding”符合“Equatable”
如何使 Binding 确认为 Equatable?非绑定普通NotificationDetail已经确认为Equatable。
@ObservedObject var notificationsViewModel = NotificationsViewModel.shared
//NotificationsViewModel does a API call and puts the fetched data in the Notifications Model
var body: some View {
VStack {
ForEach($notificationsViewModel.notifications.notificationsDetails) { $notificationsDetail in
VStack(alignment: .leading) {
if notificationsDetail.notificationsCategoriesId == 2 {
NotificationsFriendRequestCell(notificationsDetail: $notificationsDetail, viewModel: viewModel, notificationsViewModel: notificationsViewModel, tabSelection: $tabSelection) //ReceiveFriendRequestCell(user: user, viewModel: viewModel)
}
else if notificationsDetail.notificationsCategoriesId == 3 {
NotificationsFriendRequestApprovedCell(notificationsDetail: $notificationsDetail, viewModel: viewModel, notificationsViewModel: notificationsViewModel, tabSelection: $tabSelection)
}
}
.task { //task modifier for infinite scrolling …Run Code Online (Sandbox Code Playgroud)