我根据Firebase控制台中提供的说明创建了一个示例ios应用程序,用于在ios设备上接收云消息。通知消息从控制台发送,并打印在应用程序控制台上。但即使在给予必要的许可后,设备上也不会收到推送通知。
我正在使用swift 3和xCode 10.3版本。在Firebase控制台中注册了该应用程序,并通过该应用程序接收所需的FCM令牌,并添加该令牌以向设备发送测试消息。尝试通过控制台发送大量消息,但没有一条消息显示在设备上。它显示消息正在控制台上成功发送。
以下是我编写的用于接收消息推送的AppDelegate.swift文件。
import UIKit
import UserNotifications
import Firebase
import FirebaseMessaging
import FirebaseInstanceID
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
let gcmMessageIDKey = "gcm.message_id"
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
if #available(iOS 10.0, *) {
FirebaseApp.configure()
Messaging.messaging().delegate = self
Messaging.messaging().shouldEstablishDirectChannel = true
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: {_, _ in })
} else {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
application.registerUserNotificationSettings(settings)
}
// request permission from user to send notification
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound], completionHandler: { authorized, error in
if authorized {
DispatchQueue.main.async(execute: {
application.registerForRemoteNotifications()
})
}
else{
print("Notification access denied")
}
})
return true
}
// [START receive_message]
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: \(messageID)")
}
print(userInfo)
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: \(messageID)")
}
print(userInfo)
completionHandler(UIBackgroundFetchResult.newData)
}
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
print("Unable to register for remote notifications: \(error.localizedDescription)")
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken
print("APNs token retrieved: \(deviceToken)")
}
}
@available(iOS 10, *)
extension AppDelegate : UNUserNotificationCenterDelegate {
// Receive displayed notifications for iOS 10 devices.
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let userInfo = notification.request.content.userInfo
print(userInfo)
print("Message ID: \(userInfo["gcm.message_id"]!)")
completionHandler(UNNotificationPresentationOptions.alert)
}
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
print("Do what ever you want")
// Print full message.
print("tap on on forground app",userInfo)
completionHandler()
}
}
extension AppDelegate : MessagingDelegate {
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
print("Firebase registration token: \(fcmToken)")
Messaging.messaging().subscribe(toTopic: "/topics/nutriewell_live")
Messaging.messaging().shouldEstablishDirectChannel = true
}
func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) {
print("Received data message: \(remoteMessage.appData)")
}
}
我希望ios设备上有推送通知,但我没有收到任何通知。我得到了以下输出,其中打印了从控制台发送的通知消息。
2019-08-15 11:20:32.548066+0530 FirebaseIos[800:207059] - <AppMeasurement>[I-ACS036002] Analytics screen reporting is enabled. Call +[FIRAnalytics setScreenName:setScreenClass:] to set the screen name or override the default screen class name.
To disable screen reporting, set the flag FirebaseScreenReportingEnabled to NO (boolean) in the Info.plist
2019-08-15 11:20:32.949393+0530 FirebaseIos[800:207068] 6.2.0 - [Firebase/Messaging][I-FCM001000] FIRMessaging Remote Notifications proxy enabled, will swizzle remote notification receiver handlers. If you'd prefer to manually integrate Firebase Messaging, add "FirebaseAppDelegateProxyEnabled" to your Info.plist, and set it to NO.
Firebase registration token: fsyB51mCvbg:APA91bFvRFPIxauHfKA-v-K29YTWl_TYFTgCpnvODrFA2rG8qN-F8vcLIWcZ-lOChkJw-pIBVhcxg2epBz7AYVALMNLC4Hs6M4ds_pQXytYymjr15KMqOt08_7PkmYkU1jHy6xcw5hvx
2019-08-15 11:20:34.914040+0530 FirebaseIos[800:207059] 6.2.0 - [Firebase/Messaging][I-FCM002024] Format '/topics/nutriewell_live' is deprecated. Only 'nutriewell_live' should be used in subscribeToTopic.
Notification access denied
2019-08-15 11:20:48.869741+0530 FirebaseIos[800:207068] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C7.1:2][0x101537e10] get output frames failed, state 8196
Received data message: [AnyHashable("notification"): {
body = "firebase ios";
e = 1;
tag = "campaign_collapse_key_3627158360856700759";
title = "firebase!";
}, AnyHashable("from"): 591363996390, AnyHashable("collapse_key"): com.combank.Firebase.Ios]
%@ [AnyHashable("notification"): {
body = "firebase ios";
e = 1;
tag = "campaign_collapse_key_3627158360856700759";
title = "firebase!";
}, AnyHashable("from"): 591363996390, AnyHashable("collapse_key"): com.combank.Firebase.Ios]
Received data message: [AnyHashable("collapse_key"): com.combank.Firebase.Ios, AnyHashable("from"): 591363996390, AnyHashable("notification"): {
body = "firebase ios";
e = 1;
tag = "campaign_collapse_key_750970355066402639";
title = "firebase!";
}]
%@ [AnyHashable("collapse_key"): com.combank.Firebase.Ios, AnyHashable("from"): 591363996390, AnyHashable("notification"): {
body = "firebase ios";
e = 1;
tag = "campaign_collapse_key_750970355066402639";
title = "firebase!";
}]
2019-08-15 11:22:34.475335+0530 FirebaseIos[800:207131] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C1.1:2][0x1015273f0] get output frames failed, state 8196
有什么可以帮我的吗?
接收通知有两种方式:
>
当应用程序处于关闭/非活动状态,并且您在didFinishLaunchingWithOptions中获得有效负载时:
当应用程序处于打开/活动状态且当前可见时,您将在didReceiveRemoteNotification中获得有效负载:
当你的应用程序关闭时,iOS会显示通知(如果未开发通知扩展),并在你点击时启动你的应用程序。
如果您的应用程序打开,您必须注意显示此通知或忽略它。
以下是官方文件的内容:
如果本地和远程通知不是由您的应用程序或用户直接处理的,则它们会显示在通知中心,以便稍后查看。使用getDeliveredNotificationsWithCompletionHandler:shared UNUserNotificationCenter对象的方法获取仍在通知中心显示的通知列表。如果发现任何现已过时且不应向用户显示的通知,可以使用removeDeliveredNotificationsWithIdentifiers:方法删除它们。
官方文件
我对FireBase云消息有一个问题,我从设备中获取令牌,并通过Google FireBase通知控制台发送通知测试。但是,通知从来没有被记录,也没有被推送到android虚拟设备。FCM的文档几乎与下面的代码完全相同,其他代码很少,您还需要做什么来获得使用FireBase的推送通知。我已经完成了所有的设置信息(build.gradle添加、安装google play服务等)如文档中所指定的,但仍
我已经试着调试Firebase推送通知相当长时间了,但没有得到任何运气。我相信我已经正确地设置了临时配置文件和APNs证书。当我不包含方法时 当应用程序从Firebase通知控制台发送时,它会在前台接收通知,因为它会被打印出来,但它不会在后台接收通知。
我使用FCM向单个iOS设备发送推送通知,触发http请求到Firebase云功能。在遵循FCM和APNs文档之后,当应用程序在后台运行时,一切都正常工作。我在所有情况下都成功地收到了通知。 唯一的问题是:推送通知不会从睡眠中点亮我的锁屏。我仍然收到推送通知,当我按下home按钮手动唤醒设备时,可以看到它。但是通知本身不会唤醒我的设备。 null 我已经打开了“后台模式”功能>同时选择了“远程通知
我在项目中使用Firebase身份验证。今天我决定将FCM集成到我的项目中。但是我无法从我的Firebase控制台收到任何通知。我还尝试重新下载. json文件,但没有成功。你们知道我的问题吗? Android清单.xml FirebaseMessageService.java FirebaseIDService.java 我认为这个问题不是由我的MainActiviy.java决定的,但以防万一
我正在接收令牌,但当我从Firebase控制台发送通知时,我的设备上不会发生任何事情,无论应用是否处于后地。与此同时,我的Android应用程序收到通知。 我遵循了这个指南: https://firebase.google.com/docs/cloud-messaging/ios/client 为了确保这一点,我还在 https://github.com/firebase/quickstart-i
Samsung正在成功获取应用程序在后台或前台被杀死, 我的目标是API27,这是我的代码 分级