小编Hir*_*iro的帖子

iOS 15 应用程序未收到静默推送通知(=后台通知)

我被困了好几天了,需要你的帮助。

\n

我想接收静默推送通知(又称后台通知)来更新我的应用程序内容。

\n

AppDelegate 中的以下部分不会被调用。

\n
func 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}\n
Run Code Online (Sandbox Code Playgroud)\n

下面是服务器端的Python代码。服务器端说向设备发送通知成功,所以我认为问题出在前端。

\n
def 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\n
Run Code Online (Sandbox Code Playgroud)\n

一些附加说明。

\n …

apn apple-push-notifications swift

8
推荐指数
0
解决办法
2254
查看次数

如何在 SwiftUI 中使绑定值符合 Equatable

当我尝试比较任务修改器中的值时,出现以下错误。

运算符函数“==”要求“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)

ios swift swiftui

4
推荐指数
1
解决办法
4466
查看次数

标签 统计

swift ×2

apn ×1

apple-push-notifications ×1

ios ×1

swiftui ×1