我有个问题要用推消息来解决。如果我向Firebase
,发送一条推送消息,我将很好地接收到它,并且我会很好地看到消息。
当我单击push消息时,将执行AppDelegate
文件中的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])
}
我的目的是在从Firebase发送特定消息(Ex: push = "noShowPush")
时,在不向用户显示推送消息的情况下执行函数。
EDit
我曾尝试过"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:
我正在复习的东西是对的吗?
我怎么能解决这个问题?
发布于 2019-11-04 06:08:02
我解决了问题。下面是我计算出来的顺序:
当您发送push "content_available": true"
时,
body
.title
,Firebase中的6.10.0 - [Firebase/Messaging][I-FCM002019] FIRMessaging received data-message, but FIRMessagingDelegate's-messaging:didReceiveMessage: not implemented
FirebaseAppDelegateProxyEnabled
设置为No,所以我将其添加到Info.list
.中
func应用程序(_ application: UIApplication,didFinishLaunchingWithOptions launchOptions: UIApplication.LaunchOptionsKey: Any?) -> Bool { FirebaseApp.configure() //让它先运行。Messaging.messaging().delegate = self self.window =UIWindow(框架: UIScreen.main.bounds) .
'Firebase/Analytics'
。pod 'Firebase/Analytics'
MessagingDelegate
并实现了Messaging
函数。func消息传递(消息传递:消息传递,didReceiveRegistrationToken fcmToken: String) { print("fcmToken (fcmToken)") } func消息传递(消息传递:消息传递,didReceive remoteMessage: MessagingRemoteMessage) { Log.Info("remort ( remoteMessage.appData )")让userInfo =remoteMessage.appData }
此配置允许您在发送推送消息时将推送消息数据接收到messaging
函数中。这是一条推消息,其“contentAvailable
”值为True
,没有title
和body
。
https://stackoverflow.com/questions/58654420
复制相似问题