gpt4 book ai didi

ios - 如何在发送时不显示推送消息的情况下运行该功能?

转载 作者:行者123 更新时间:2023-12-01 16:13:24 25 4
gpt4 key购买 nike

我有一个问题要通过推送消息解决。如果我向 发送推送消息Firebase ,我会很好地收到它,我会很好地看到消息。

当我点击推送消息时,userNotificationCenter AppDelegate 中的函数执行文件并执行函数中的操作列表。

我可以在不接收特定消息并显示消息的情况下执行功能吗?

我目前在哪里接收和处理推送消息。

    @available(iOS 10, *)
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
let data = response.notification.request.content.userInfo

guard
let push = data[AnyHashable("push")] as? String,
let getdata = data[AnyHashable("getdata")] as? String,
let pushdata = data[AnyHashable("pushdata")] as? String
else {
print("it's not good data")
return
}
print(push)
print(getdata)
print(pushdata)
}

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

我的目的是在发送特定消息时执行该功能而不向用户显示推送消息 (Ex: push = "noShowPush")来自 Firebase。

编辑

我试过 "content_available": true但获取日志 6.10.0 - [Firebase/Messaging][I-FCM002019] FIRMessaging received data-message, but FIRMessagingDelegate's-messaging:didReceiveMessage: not implemented
 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

self.window = UIWindow(frame: UIScreen.main.bounds)
// Override point for customization after application launch.
//create the notificationCenter
Messaging.messaging().delegate = self
FirebaseApp.configure()

//Register App For Push Notification
// self.registerAppForPushNotificaition()
let center = UNUserNotificationCenter.current()
let inviteCategory = UNNotificationCategory(identifier: "Notification", actions: [], intentIdentifiers: [], options: UNNotificationCategoryOptions.customDismissAction)
let categories = NSSet(objects: inviteCategory)

center.delegate = self
center.setNotificationCategories(categories as! Set<UNNotificationCategory>)
DispatchQueue.main.async(execute: {
UIApplication.shared.registerForRemoteNotifications()
})
application.registerForRemoteNotifications()
self.updateAppViewUI()
self.window?.makeKeyAndVisible()
return true
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
// If you are receiving a notification message while your app is in the background,
// this callback will not be fired till the user taps on the notification launching the application.
// TODO: Handle data of notification

// With swizzling disabled you must let Messaging know about the message, for Analytics

Messaging.messaging().appDidReceiveMessage(userInfo)

// Print message ID.
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: \(messageID)")
}

// Print full message.
print(userInfo)
}

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
Messaging.messaging().appDidReceiveMessage(userInfo)
if Auth.auth().canHandleNotification(userInfo) {
completionHandler(UIBackgroundFetchResult.noData)
return
}
completionHandler(UIBackgroundFetchResult.newData)
}

我已经有了 Messaging.messaging().delegate = self .
Firebase 中的日志已警告您设置 FirebaseAppDelegateProxyEnabledNo ,所以我添加到 Info.list .
enter image description here

Firebase日志已更改 [Firebase/Core][I-COR000003] The default Firebase app has not yet been configured. Add '[FIRApp configure];' ('FirebaseApp.configure()' in Swift) to your application initialization. Read more:
我正在修改的事情进展顺利吗?

我该如何解决这个问题?

最佳答案

我解决了这个问题。这是我制定的顺序:

  • 发送推送时写"content_available": true" .并且不要
    包括 titlebody .
  • 当我收到这些错误日志时,6.10.0 -
    [Firebase/Messaging][I-FCM002019] FIRMessaging received
    data-message, but
    FIRMessagingDelegate's-messaging:didReceiveMessage: not implemented
  • Firebase 中的日志已警告您设置FirebaseAppDelegateProxyEnabled为否,所以我添加到Info.list .

    ㅎㅎ
  • 并改变了函数的执行顺序。
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

    FirebaseApp.configure() // Let it run first.
    Messaging.messaging().delegate = self
    self.window = UIWindow(frame: UIScreen.main.bounds)
    ...
  • 我安装了'Firebase/Analytics'在 pods 上。pod 'Firebase/Analytics'
  • 并继承了MessagingDelegate并实现了Messaging功能。
    func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
    print("fcmToken \(fcmToken)")
    }

    func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) {
    Log.Info("remort \(remoteMessage.appData)")
    let userInfo = remoteMessage.appData
    }

  • 此配置允许您将推送消息数据接收到 messaging发送推送消息时的功能。这是一 strip 有“ contentAvailable”的推送消息' True 的值没有 titlebody .

    关于ios - 如何在发送时不显示推送消息的情况下运行该功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58654420/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com