我试图修复firebase云消息的设置。
我得到了令牌,所有的日志消息看起来都很好。但当我在firebase的云消息网站上测试时;新通知";让我测试一下。我从未收到任何通知。
你能告诉我我缺了什么吗?或者我还能试试通知吗?
2021-06-21 10:41:03.029738+0100 Alxxxxx[7123:1968057] 8.1.0 - [Firebase/Messaging][I-FCM028009] Deleted checkin plist file.
2021-06-21 10:41:03.031312+0100 Alxxxxx[7123:1968057] 8.1.0 - [Firebase/Messaging][I-FCM002000] FIRMessaging library version 8.1.0
2021-06-21 10:41:03.043112+0100 Alxxxxx[7123:1968067] 8.1.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. Follow the instructions at:
https://firebase.google.com/docs/cloud-messaging/ios/client#method_swizzling_in_firebase_messaging
to ensure proper integration.
2021-06-21 10:41:03.320349+0100 Alxxxxx[7123:1968072] 8.1.0 - [Firebase/Messaging][I-FCM033002] Removed cached checkin preferences from Keychain because this is a fresh install.
2021-06-21 10:41:03.320432+0100 Alxxxxx[7123:1968072] 8.1.0 - [Firebase/Messaging][I-FCM033006] App reset detected. Will delete server registrations.
2021-06-21 10:41:03.325578+0100 Alxxxxx[7123:1968058] 8.1.0 - [Firebase/Messaging][I-FCM023012] Provisioning profile has specifically provisioned devices, most likely a Dev profile.
didRegisterForRemoteNotificationsWithDeviceToken
2021-06-21 10:41:03.327044+0100 Alxxxxx[7123:1968058] 8.1.0 - [Firebase/Messaging][I-FCM023013] APNS Environment in profile: development
2021-06-21 10:41:03.327423+0100 Alxxxxx[7123:1968058] 8.1.0 - [Firebase/Messaging][I-FCM034011] Invalidating cached token for 226232852962 (*) due to APNs token change.
2021-06-21 10:41:03.339595+0100 Alxxxxx[7123:1968075] 8.1.0 - [Firebase/Messaging][I-FCM043000] Info is not found in Keychain. OSStatus: -25300. Keychain query: {
acct = "com.xxx.xxx";
class = genp;
gena = "com.google.iid-tokens";
"m_Limit" = "m_LimitAll";
"r_Attributes" = 1;
"r_Data" = 1;
}
2021-06-21 10:41:03.341176+0100 Alxxxxx[7123:1968075] 8.1.0 - [Firebase/Messaging][I-FCM027006] Checkin parameters: {
checkin = {
iosbuild = {
model = "iPhone11,8";
"os_version" = "IOS_14.6";
};
"last_checkin_msec" = 0;
type = 2;
"user_number" = 0;
};
digest = "";
fragment = 0;
id = 5584406772885541290;
locale = "en_GB";
"security_token" = 3213773942865469096;
"time_zone" = "Europe/London";
"user_serial_number" = 0;
version = 2;
}
2021-06-21 10:41:03.343762+0100 Alxxxxx[7123:1968075] 8.1.0 - [Firebase/Messaging][I-FCM034000] Fetch new token for authorizedEntity: 226232852962, scope: *
2021-06-21 10:41:03.344027+0100 Alxxxxx[7123:1968075] 8.1.0 - [Firebase/Messaging][I-FCM034000] Fetch new token for authorizedEntity: 226232852962, scope: *
2021-06-21 10:41:03.834982+0100 Alxxxxx[7123:1968062] 8.1.0 - [Firebase/Messaging][I-FCM027002] Invalid last checkin timestamp 2021-06-21 09:41:03 +0000 in future.
2021-06-21 10:41:03.835127+0100 Alxxxxx[7123:1968062] 8.1.0 - [Firebase/Messaging][I-FCM027003] Checkin successful with authId: 5584406772885541290, digest: XPjsxwmSt4bPL+btyjeLLw==, lastCheckinTimestamp: 1624268463000
2021-06-21 10:41:03.835627+0100 Alxxxxx[7123:1968062] 8.1.0 - [Firebase/Messaging][I-FCM025004] Successfully got checkin credentials
2021-06-21 10:41:03.836667+0100 Alxxxxx[7123:1968062] 8.1.0 - [Firebase/Messaging][I-FCM028010] Checkin plist file is saved
2021-06-21 10:41:03.837511+0100 Alxxxxx[7123:1968062] 8.1.0 - [Firebase/Messaging][I-FCM034000] Fetch new token for authorizedEntity: 226232852962, scope: *
2021-06-21 10:41:04.094542+0100 Alxxxxx[7123:1968062] 8.1.0 - [Firebase/Messaging][I-FCM041000] Unregister request to https://fcmtoken.googleapis.com/register content: X-osv=14.6&device=5584406772885541290&plat=2&app=com.xxx.xxx&app_ver=1.4&X-cliv=fiid-8.1.0&delete=true
2021-06-21 10:41:04.721312+0100 Alxxxxx[7123:1968062] 8.1.0 - [Firebase/Messaging][I-FCM034007] Successfully deleted GCM server registrations on app reset
2021-06-21 10:41:05.166251+0100 Alxxxxx[7123:1968062] 8.1.0 - [Firebase/Messaging][I-FCM040000] Register request to https://fcmtoken.googleapis.com/register content: X-osv=14.6&device=5584406772885541290&X-scope=*&plat=2&app=com.xxx.xxx&app_ver=1.4&X-cliv=fiid-8.1.0&sender=226232852962&X-subtype=226232852962&appid=dTQYr-nfN0OqhZvXY5IeTu&apns_token=s_ebdad3f53a17699dc219d09a676095198433798161f8d3e283e12b9445012560&gmp_app_id=1:226232852962:ios:35d4a06420a68e72
2021-06-21 10:41:06.026788+0100 Alxxxxx[7123:1968066] 8.1.0 - [Firebase/Messaging][I-FCM043002] Couldn't delete item from Keychain OSStatus: -25300 with the keychain query {
acct = "com.xxx.xxx";
class = genp;
gena = "com.google.iid-tokens";
svce = "226232852962:*";
}
2021-06-21 10:41:06.349116+0100 Alxxxxx[7123:1968058] 8.1.0 - [Firebase/Messaging][I-FCM040000] Register request to https://fcmtoken.googleapis.com/register content: X-osv=14.6&device=5584406772885541290&X-scope=*&plat=2&app=com.xxx.xxx&app_ver=1.4&X-cliv=fiid-8.1.0&sender=226232852962&X-subtype=226232852962&appid=dTQYr-nfN0OqhZvXY5IeTu&apns_token=s_ebdad3f53a17699dc219d09a676095198433798161f8d3e283e12b9445012560&gmp_app_id=1:226232852962:ios:35d4a06420a68e72
2021-06-21 10:41:06.351359+0100 Alxxxxx[7123:1968058] 8.1.0 - [Firebase/Messaging][I-FCM034001] Token fetch successful, token: dTQYr-nfN0OqhZvXY5IeTu:APA91bF_9vLMVtU33ogoPmug5l3S8XPP7_GHW-HSDzUDk1StJEMI6ZZ5RZUJur5An9OnPx625HtQ8-r3FrLe1-dwEKy6vNj0I3j2TuJCUXFYY4RNuy6vjOCSLv-bEO1S-2JzRdOAA7aw, authorizedEntity: 226232852962, scope:*
2021-06-21 10:41:06.552044+0100 Alxxxxx[7123:1968057] 8.1.0 - [Firebase/Messaging][I-FCM017000] Topic subscription request: sender=dTQYr-nfN0OqhZvXY5IeTu:APA91bF_9vLMVtU33ogoPmug5l3S8XPP7_GHW-HSDzUDk1StJEMI6ZZ5RZUJur5An9OnPx625HtQ8-r3FrLe1-dwEKy6vNj0I3j2TuJCUXFYY4RNuy6vjOCSLv-bEO1S-2JzRdOAA7aw&app=com.xxx.xxx&device=5584406772885541290&app_ver=1.4&X-gcm.topic=/topics/test&X-scope=/topics/test&delete=true
2021-06-21 10:41:06.716876+0100 Alxxxxx[7123:1968058] 8.1.0 - [Firebase/Messaging][I-FCM040000] Register request to https://fcmtoken.googleapis.com/register content: X-osv=14.6&device=5584406772885541290&X-scope=*&plat=2&app=com.xxx.xxx&app_ver=1.4&X-cliv=fiid-8.1.0&sender=226232852962&X-subtype=226232852962&appid=dTQYr-nfN0OqhZvXY5IeTu&apns_token=s_ebdad3f53a17699dc219d09a676095198433798161f8d3e283e12b9445012560&gmp_app_id=1:226232852962:ios:35d4a06420a68e72
2021-06-21 10:41:06.721506+0100 Alxxxxx[7123:1968066] 8.1.0 - [Firebase/Messaging][I-FCM034001] Token fetch successful, token: dTQYr-nfN0OqhZvXY5IeTu:APA91bF_9vLMVtU33ogoPmug5l3S8XPP7_GHW-HSDzUDk1StJEMI6ZZ5RZUJur5An9OnPx625HtQ8-r3FrLe1-dwEKy6vNj0I3j2TuJCUXFYY4RNuy6vjOCSLv-bEO1S-2JzRdOAA7aw, authorizedEntity: 226232852962, scope:*
2021-06-21 10:41:06.827332+0100 Alxxxxx[7123:1968058] 8.1.0 - [Firebase/Messaging][I-FCM004002] Successfully unsubscribed from topic /topics/test
2021-06-21 10:41:06.838283+0100 Alxxxxx[7123:1968067] 8.1.0 - [Firebase/Messaging][I-FCM034001] Token fetch successful, token: dTQYr-nfN0OqhZvXY5IeTu:APA91bF_9vLMVtU33ogoPmug5l3S8XPP7_GHW-HSDzUDk1StJEMI6ZZ5RZUJur5An9OnPx625HtQ8-r3FrLe1-dwEKy6vNj0I3j2TuJCUXFYY4RNuy6vjOCSLv-bEO1S-2JzRdOAA7aw, authorizedEntity: 226232852962, scope:*
2021-06-21 10:41:12.278599+0100 Alxxxxx[7123:1968058] 8.1.0 - [Firebase/Messaging][I-FCM017000] Topic subscription request: sender=dTQYr-nfN0OqhZvXY5IeTu:APA91bF_9vLMVtU33ogoPmug5l3S8XPP7_GHW-HSDzUDk1StJEMI6ZZ5RZUJur5An9OnPx625HtQ8-r3FrLe1-dwEKy6vNj0I3j2TuJCUXFYY4RNuy6vjOCSLv-bEO1S-2JzRdOAA7aw&app=com.xxx.xxx&device=5584406772885541290&app_ver=1.4&X-gcm.topic=/topics/test&X-scope=/topics/test
2021-06-21 10:41:12.819803+0100 Alxxxxx[7123:1968213] 8.1.0 - [Firebase/Messaging][I-FCM004003] Successfully subscribed to topic /topics/test
AppDelegate.swift
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var orientationLock = UIInterfaceOrientationMask.all
private let onboardingContentVM = OnboardingContentViewModel()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
// GeneratedPluginRegistrant.register(with: self)
Messaging.messaging().delegate = self
Messaging.messaging().isAutoInitEnabled = true
// self.registerForFirebaseNotification(application: application);
if #available(iOS 10.0, *) {
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.current().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: {isGranted, error in
print("UNUserNotificationCenter requestAuthorization isGranted: (isGranted)")
})
} else {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
application.registerUserNotificationSettings(settings)
}
application.registerForRemoteNotifications()
UIApplication.shared.statusBarUIView?.backgroundColor = #colorLiteral(red: 0, green: 0.2509803922, blue: 0.6117647059, alpha: 1)
self.window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
switch onboardingContentVM.getState() {
case .walkthrough: showWalkthrough()
case .updates:
let navigationController = UINavigationController.init(rootViewController: UpdatesViewController.instantiate(from: "Onboarding"))
navigationController.setNavigationBarHidden(true, animated: false)
window?.rootViewController = navigationController
case .complete:
window?.rootViewController = WebViewController()
}
NotificationAuthManager.notificationSubscriptionSetup()
// Lock the phones to portrait
if UIDevice().userInterfaceIdiom == .phone {
AppUtility.lock(orientation: .portrait)
}
return true
}
func showWalkthrough() {
let steps = [WalkthroughStep.init(image: UIDevice().userInterfaceIdiom == .phone ? #imageLiteral(resourceName: "img_onboarding_mobile_device_1") : #imageLiteral(resourceName: "img_onboarding_tablet_device_1"), title: "Welcome", subtitle: "Welcome to the Aldridge Security App.nWe deliver the right product, at thenright price, on time every time."),
WalkthroughStep.init(image: UIDevice().userInterfaceIdiom == .phone ? #imageLiteral(resourceName: "img_onboarding_mobile_device_2") : #imageLiteral(resourceName: "img_onboarding_tablet_device_2"), title: "About Us", subtitle: "Trade Only Security Wholesaler.nSame day despatch until 6pm.nBirmingham, London & Manchester branches."),
WalkthroughStep.init(image: UIDevice().userInterfaceIdiom == .phone ? #imageLiteral(resourceName: "img_onboarding_mobile_device_3") : #imageLiteral(resourceName: "img_onboarding_tablet_device_3"), title: "Our Portfolio", subtitle: "20,000+ products held in stock.nOver 290 brands stocked.nAll available for delivery or collection.")]
let walkthroughViewController = DEGWalkthroughViewController(datasource: steps)
walkthroughViewController.register(nib: UINib(nibName: "WalkthroughCollectionViewCell", bundle: nil), reuseIdentifier: WalkthroughCollectionViewCell.cellId)
walkthroughViewController.set(backgroundColor: UIColor(hexString: "00409c"))
walkthroughViewController.set(isButtonPaginateEnabled: false)
let actionWalkthroughVw = walkthroughViewController.getActionView() as? DEGSingleWalkthroughActionView
actionWalkthroughVw?.set(backgroundColor: .clear)
actionWalkthroughVw?.setButton(font: UIFont.init(name: "Lato-Bold", size: 17)!)
actionWalkthroughVw?.set(top: 50)
let calculatedSizePadding = (UIScreen.main.bounds.width - 295) / 2
actionWalkthroughVw?.set(left: calculatedSizePadding)
actionWalkthroughVw?.set(right: -calculatedSizePadding) // todo: update library to do the inverse
// todo: tweak depending on device and orientation & update library to do the inverse
UIDevice().userInterfaceIdiom == .phone ? actionWalkthroughVw?.set(bottom: -40) : actionWalkthroughVw?.set(bottom: UIDevice.current.orientation.isLandscape ? -50 : -100)
actionWalkthroughVw?.setButton(title: "Okay, Got It")
actionWalkthroughVw?.setButton(backgroundColor: UIColor(hexString: "fed80a"))
actionWalkthroughVw?.setButton(titleColor: .black)
let pagingControl = walkthroughViewController.getPagingControlView()
pagingControl.set(backgroundColor: .clear)
pagingControl.set(top: 15)
walkthroughViewController.configure { collectionView, indexPath, dataSource in
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: WalkthroughCollectionViewCell.cellId, for: indexPath) as! WalkthroughCollectionViewCell
cell.configure(with: dataSource[indexPath.row] as! WalkthroughStep)
return cell
}
actionWalkthroughVw?.getButton().clipsToBounds = true
actionWalkthroughVw?.getButton().setHighlight(color: UIColor(hexString: "c8b937"), forState: .highlighted)
walkthroughViewController.actionDidTouch { [weak self] _,_,_ in
let updatesVC = UpdatesViewController.instantiate(from: "Onboarding")
walkthroughViewController.navigationController?.pushViewController(updatesVC, animated: true)
self?.onboardingContentVM.set(true, for: .walkthrough)
}
walkthroughViewController.viewOrientationDidChange { (size, transition) in
let calculatedSizePadding = (UIScreen.main.bounds.width - 295) / 2
actionWalkthroughVw?.set(left: calculatedSizePadding)
actionWalkthroughVw?.set(right: -calculatedSizePadding) // todo: update library to do the inverse
}
let navigationController = UINavigationController.init(rootViewController: walkthroughViewController)
navigationController.setNavigationBarHidden(true, animated: false)
window?.rootViewController = navigationController
}
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return self.orientationLock
}
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let userInfo = notification.request.content.userInfo
// With swizzling disabled you must let Messaging know about the message, for Analytics
// Messaging.messaging().appDidReceiveMessage(userInfo)
// ...
// Print full message.
print("willPresent - userInfo: (userInfo)")
// Change this to your preferred presentation option
// completionHandler([[.alert, .sound]])
completionHandler([.alert, .badge, .sound])
}
}
extension AppDelegate: MessagingDelegate {
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
print("Firebase registration token: (String(describing: fcmToken))")
let dataDict:[String: String] = ["token": fcmToken ?? ""]
NotificationCenter.default.post(name: Notification.Name("FCMToken"), object: nil, userInfo: dataDict)
// TODO: If necessary send token to application server.
// Note: This callback is fired at each app startup and whenever a new token is generated.
Messaging.messaging().token { token, error in
if let error = error {
print("Firebase, Error fetching FCM registration token: (error)")
} else if let token = token {
print("Firebase, FCM registration token: (token)")
// self.fcmRegTokenMessage.text = "Remote FCM registration token: (token)"
}
}
}
}
@available(iOS 10, *)
extension AppDelegate: UNUserNotificationCenterDelegate {
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
print("didRegisterForRemoteNotificationsWithDeviceToken")
Messaging.messaging().apnsToken = deviceToken as Data
// Messaging.messaging().setAPNSToken(deviceToken, type: MessagingAPNSTokenType.unknown)
}
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
print("didFailToRegisterForRemoteNotificationsWithError: (error)")
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
// 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("didReceiveRemoteNotification - userInfo: (userInfo)")
completionHandler(UIBackgroundFetchResult.newData)
}
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
// ...
// With swizzling disabled you must let Messaging know about the message, for Analytics
// Messaging.messaging().appDidReceiveMessage(userInfo)
// Print full message.
print("didReceive - userInfo: (userInfo)")
// completionHandler()
if let deepLinkURL = response.notification.request.content.userInfo["url"] as? String {
if deepLinkURL.contains("aldridgesecurity") {
NotificationCenter.default.post(name: .deepLink, object: nil, userInfo: ["deeplink": deepLinkURL])
}
}
completionHandler()
}
}
根据您的问题,我无法生成问题。但我附上了我的代码,它正在按预期工作。我收到来自Firebase服务器的通知。
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
print("I am (UIDevice.current.model) and my height is (UIScreen.main.bounds.height)")
// Override point for customisation after application launch.
FirebaseApp.configure()
registerForRemoteNotifications(application: application)
return true
}
extension AppDelegate
{
func registerForRemoteNotifications(application: UIApplication){
Messaging.messaging().delegate = self
UNUserNotificationCenter.current().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: {_, _ in })
application.registerForRemoteNotifications()
}
}
// MARK: - UNUserNotificationCenterDelegate
extension AppDelegate: UNUserNotificationCenterDelegate {
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
var token = ""
for i in 0..<deviceToken.count
{
token = token + String(format: "%02.2hhx", arguments: [deviceToken[i]])
}
print("DeviceToken========n(token)n=========")
Messaging.messaging().apnsToken = deviceToken
}
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
print("didFailToRegisterForRemoteNotificationsWithError = (error.localizedDescription)")
}
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler([.alert])
}
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
completionHandler()
}
}
// MARK : - MessagingDelegate
extension AppDelegate: MessagingDelegate {
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
guard let fcmToken = fcmToken else {
return
}
print("fcmToken========n(fcmToken)n=========")
}
}
借助这个FCM TOKEN,您可以从Firebase消息传递工具发出通知。若你们并没有得到通知,那个么问题必须在你们的firebase配置中。