【发布时间】:2019-11-01 05:17:20
【问题描述】:
我有一个问题需要通过推送消息来解决。如果我向Firebase发送推送消息,我会很好地收到它,我会很好地看到消息。
当我点击推送消息时,AppDelegate文件中的userNotificationCenter函数被执行,函数中的动作列表被执行。
我可以在不接收特定消息并显示消息的情况下执行功能吗?
我目前在哪里接收和处理推送消息。
@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])
}
我的目的是在从 Firebase 发送特定消息(Ex: push = "noShowPush") 时执行该功能而不向用户显示推送消息。
编辑
我试过"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 中的日志已经警告你将FirebaseAppDelegateProxyEnabled 设置为No,所以我添加到Info.list。
和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:
我正在修改的事情进展顺利吗?
我该如何解决这个问题?
【问题讨论】:
-
您真正想要达到的目标是什么?您的问题似乎不清楚。
-
我的问题很难理解吗?我的目的是在从 Firebase 发送特定消息(例如:push = "noShowPush")时执行该功能而不向用户显示推送消息。
-
@FrankvanPuffelen 我认为您可以在 firebase 中解决问题。你能帮我解决我的问题吗?
标签: ios swift firebase push-notification