推送通知无法在Firebase 4.0中使用 [英] Push Notifications not working in Firebase 4.0

查看:362
本文介绍了推送通知无法在Firebase 4.0中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我今天更新了我的豆荚,将其添加到新的Firebase 4.0中。我完成了建议的更改,并从Github示例中获取了代码。我会说实话我很茫然,我拿FCM令牌,并从firebase控制台发送消息,我什么都没有。



我刷新,它说消息被发送,但我检查控制台和设备,没有什么。这是我的appdelegate:

  / / 
//由Erik Grosskurth在4/24/17创建。
//

导入UIKit
导入FirebaseAnalytics
导入FirebaseInstanceID
导入FirebaseMessaging
导入UserNotifications
导入SystemConfiguration
import MobileCoreServices
import Quickblox
import QuickbloxWebRTC

$ b let kQBApplicationID:UInt = 3545252534
let kQBAuthKey =udfgsegsetrgsextr
let kQBAuthSecret = setbsetbsetbsetrbset
let kQBAccountKey =sbrtsbrtbsrtbsrtbrt

@UIApplicationMain $ b $ class AppDelegate:UIResponder,UIApplicationDelegate {

var window:UIWindow?
let gcmMessageIDKey =gcm.message_id

func application(_ application:UIApplication,didFinishLaunchingWithOptions launchOptions:[UIApplicationLaunchOptionsKey:Any]?) - > Bool {

// [START register_for_notifications]

FirebaseApp.configure()

Messaging.messaging()。delegate = self

if #available(iOS 10.0,*){
//对于iOS 10显示通知(通过APNS发送)
UNUserNotificationCenter.current()。delegate = self

让authOptions:UNAuthorizationOptions = [.alert,.badge,.sound]
UNUserNotificationCenter.current()。requestAuthorization(options:authOptions,completionHandler:{_,_in})
} else {
设置:UIUserNotificationSettings = UIUserNotificationSettings(类型:[.alert,.badge,.sound],类别:nil)
application.registerUserNotificationSettings(设置)
}

应用程序如果(Messaging.messaging()。fcmToken!= nil){
DataModel.sharedInstance.sessionInfo.Firebas eAccessToken = Messaging.messaging()。fcmToken!
print(FCM token:\(DataModel.sharedInstance.sessionInfo.FirebaseAccessToken))
} else {
print(token was nil)
}

// [END register_for_notifications]

// Quickblox config
QBSettings.setApplicationID(kQBApplicationID)
QBSettings.setAuthKey(kQBAuthKey)
QBSettings.setAuthSecret (kQBAuthSecret)
QBSettings.setAccountKey(kQBAccountKey)

//设置区域
的设置QBSettings.setApiEndpoint(https://api.quickblox.com,chatEndpoint: chat.quickblox.com,forServiceZone:.production)
//激活区域
QBSettings.setServiceZone(.production)

QBSettings.setKeepAliveInterval(30)
QBSettings .setAutoReconnectEnabled(true)
QBRTCConfig.setStatsReportTimeInterval(1)
QBRTCConfig.setDialingTimeInterval(5)
QBRTCConfig.setAnswerTimeInter val(60)

返回true
}

// [START receive_message]
func应用程序(_ application:UIApplication,didReceiveRemoteNotification userInfo:[AnyHashable :任何]){

如果让messageID = userInfo [gcmMessageIDKey] {
print(Message ID: \(messageID))
}

print(userInfo)



func应用程序(_ application:UIApplication,didReceiveRemoteNotification userInfo:[AnyHashable:Any],fetchCompletionHandler completionHandler:@escaping(UIBackgroundFetchResult) - >无效){

message message = userInfo [gcmMessageIDKey] {
print(Message ID:\ (messageID))
}

print(userInfo)

completionHandler(UIBackgroundFetchResult.newData)




//当APN为设备分配一个唯一的令牌
func application(_ application:UIApplication,didRegisterForRemoteNotificationsWithDeviceToken deviceToken:Data){

print(didRegisterForRemoteNotificationsWithDeviceToken() )

Messaging.messaging()。apnsToken = deviceToken
$ b //Messaging.messaging().setAPNSToken(deviceToken,type:MessagingAPNSTokenType.sandbox)
/ /Messaging.messaging().setAPNSToken(deviceToken,type:MessagingAPNSTokenType.prod)
//Messaging.messaging().setAPNSToken(deviceToken,type:MessagingAPNSTokenType.unknown)

let deviceTokenString = deviceToken.reduce(,{$ 0 + String(format:%02X,$ 1)})
DataModel.sharedInstance.sessionInfo.APNSAccessToken = deviceTokenString
print(APNS Access Token: \(deviceTokenString))

}


// [END receive_message]
func应用程序(_ application:UIApplication,didFailToRegisterForRemoteNotificationsWithError error:Error ){
print(无法注册远程通知:\(error.localizedDescription))
}


func applicationWillResignActive(_ application:UIApplication) {
//当应用程序即将从活动状态转移到非活动状态时发送。对于某些类型的临时中断(例如来电或SMS消息)或用户退出应用程序并开始转换到后台状态时,可能会发生这种情况。
//使用此方法暂停正在进行的任务,禁用定时器,并使图形呈现回调无效。游戏应该使用这种方法来暂停游戏。

$ b $ func applicationDidEnterBackground(_ application:UIApplication){
QBChat.instance()。disconnect {(error)in
if error!= nil {
print(error:\(String(describe:error)))
} else {
print(applicationDidEnterBackground成功)




func applicationWillEnterForeground(_ application:UIApplication){
let qbUser = QBUUser()
qbUser.id = DataModel.sharedInstance.qbLoginParams.id
qbUser .password = DataModel.sharedInstance.sessionInfo.QBPassword
QBChat.instance()。connect(with:qbUser){(error)in
if error!= nil {
print(error: \(String(describe:error)))
} else {
print(success for applicationWillEnterForeground)
}
}
}

func ap plicationDidBecomeActive(_ application:UIApplication){
//在应用程序处于非活动状态时,重新启动暂停(或尚未启动)的任何任务。如果应用程序以前位于后台,则可以选择刷新用户界面。

$ b func applicationWillTerminate(_ application:UIApplication){
QBChat.instance()。disconnect {(error)in
if error!= nil {
print(error:\(String(describe:error)))
} else {
print(applicationWillTerminate成功)
}
}

$ b //锁定肖像模式
func application(_ application:UIApplication,supportedInterfaceOrientationsFor window:UIWindow?) - > UIInterfaceOrientationMask {
返回UIInterfaceOrientationMask(rawValue:UIInterfaceOrientationMask.portrait.rawValue)
}


$ b $ // [START ios_10_message_handling]
@可用(iOS 10,*)
扩展程序AppDelegate:UNUserNotificationCenterDelegate {

//接收iOS 10设备显示的通知。
func userNotificationCenter(_ center:UNUserNotificationCenter,willPresent notification:UNNotification,withCompletionHandler completionHandler:@escaping(UNNotificationPresentationOptions) - > Void){
let userInfo = notification.request.content.userInfo

//使用swizzling功能时,必须让Messaging知道关于消息的信息,对于Analytics
Messaging.messaging()。appDidReceiveMessage(userInfo)
//打印消息ID。
如果让messageID = userInfo [gcmMessageIDKey] {
print(Message ID:\(messageID))
}

//打印完整信息。
print(userInfo)

//将其更改为您的首选演示文稿选项
completionHandler([])
}

func userNotificationCenter UNUserNotificationCenter,didReceive响应:UNNotificationResponse,withCompletionHandler completionHandler:@escaping() - > Void){
let userInfo = response.notification.request.content.userInfo
//打印消息ID。
如果让messageID = userInfo [gcmMessageIDKey] {
print(Message ID:\(messageID))
}

//打印完整信息。
print(userInfo)

completionHandler()
}
}
// [END ios_10_message_handling]

扩展名AppDelegate: MessagingDelegate {
// [START refresh_token]
func messaging(_ messaging:Messaging,didRefreshRegistrationToken fcmToken:String){
DataModel.sharedInstance.sessionInfo.FirebaseAccessToken = fcmToken
print( Firebase注册令牌:\(fcmToken))
}
// [END refresh_token]
// [START ios_10_data_message]
//直接在iOS 10+上接收数据信息从FCM(绕过APN),当应用程序在前台。
//要启用直接数据消息,可以将Messaging.messaging()。shouldEstablishDirectChannel设置为true。
func messaging(_ messaging:Messaging,didReceive remoteMessage:MessagingRemoteMessage){
print(Received data message:\(remoteMessage.appData))
}
// [结束ios_10_data_message]
}

以下是日志:
Firebase Analytics应用委托代理服务器是现在的Firebase / Analytics [I-ACS003016]禁用。要手动记录深层链接活动,请在FIRAnalytics + AppDelegate.h中调用方法。
2017-05-31 16:49:56.937 Telemed [1843]<警告> [Firebase / Analytics] [I-ACS003016] Firebase Analytics App Delegate Proxy已禁用。要手动记录深层链接活动,请在FIRAnalytics + AppDelegate.h中调用方法。
2017-05-31 16:49:57.023568-0400 Telemed [1843:937706] [Firebase / Analytics] [I-ACS005000] AdSupport框架目前未链接。某些功能将无法正常工作。了解更多详情,请点击
2017-05-31 16:49:57.023 Telemed [1843]<警告> [Firebase / Analytics] [I-ACS005000] AdSupport框架当前未链接。某些功能将无法正常工作。了解更多详情,请访问
2017-05-31 16:49:57.028454-0400 Telemed [1843:937697] [Firebase / Analytics] [I-ACS023007] Firebase Analytics v.4000000开始
2017-05-31 16:49:57.028 Telemed [1843]< Notice> [Firebase / Analytics] [I-ACS023007] Firebase Analytics v.4000000开始
2017-05-31 16:49:57.029042-0400 Telemed [1843:937697] [Firebase / Analytics] [I-ACS023008]调试日志记录设置以下应用程序参数:-FIRAnalyticsDebugEnabled(请参阅)
2017-05-31 16:49:57.029 Telemed [1843]< Notice> [Firebase / Analytics] [I-ACS023008]要启用调试日志记录,请设置以下应用程序参数:-FIRAnalyticsDebugEnabled(请参阅)
FCM令牌:myTokenIsHere
2017-05-31 16:49:57.101756-0400 Telemed [1843:937699] [Firebase / Analytics] [I-ACS032003] iAd框架未链接。搜索广告属性报告器已禁用。
2017-05-31 16:49:57.102 Telemed [1843]<警告> [Firebase / Analytics] [I-ACS032003] iAd框架未链接。搜索广告属性报告器已禁用。
2017-05-31 16:49:57.103700-0400 Telemed [1843:937697] [Firebase / Analytics] [I-ACS023012]启用Firebase Analytics
2017-05-31 16:49:57.103 Telemed <通知> [Firebase / Analytics] [I-ACS023012]已启用Firebase Analytics
已销毁会话,但已保存登录
2017-05-31 16:49:57.158678-0400 Telemed [1843:937637] [MC]系统组容器for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2017-05-31 16:49:57.159102-0400 Telemed [1843:937637] [MC]从公共有效的用户设置中读取。
didRegisterForRemoteNotificationsWithDeviceToken()
APNS访问令牌:091F01B ...

>>> ------> **已解决 <------- <<<<<<<<深入潜水问题解决方案和最后的面孔...跟随这条线:
https://github.com/firebase/quickstart-ios/issues/290



特别感谢 THE RIZ 为了解决问题!

Firebase Cloud Messaging在iOS上正确设置非常复杂,因为您必须确保APNs配置正常,然后在其上添加FCM。 p>

APNs安装程序



APN认证密钥对于苹果来说也非常好,因为它们不会过期,和亲可以使用相同的密钥(如 .p8 文件)将推送通知发送到Apple Developer帐户下的所有应用程序。

这也为潜在的失败提供了一个新的领域:错别字。你可以输入一个随机的捆绑ID,只要在Xcode中配置了正确的团队,你的应用就会愉快地获得一个APN设备令牌。



发送通过APN通知该设备令牌(我使用此脚本通过HTTP / 2 +验证密钥发送测试通知)会产生 DeviceTokenNotForTopic 错误,所以这应该可以帮助您找出问题所在。

清单


  • 确保您的应用捆绑ID与您要发送的捆绑ID匹配

  • 确保你有一个授权文件,至少有一个 aps-environment 键设置为 development (这会自动更新为如果在其他SDK(如Firebase)中使用自动配置(即,改变配置),请确保您获取应用:didRegisterForRemoteNotificationsWithDeviceToken:。至少证实您的APN设置正常(但您可能还有错字)



FCM设置



请确保您使用的 GoogleService-Info.plist 文件与 BUNDLE_ID 键在plist中。我已经看到开发人员认为,因为APNs Keys应该可以在所有应用程序中正常工作,所以在应用程序中同样的 GoogleService-Info.plist 没有问题,但这不是我还建议使用自己的测试通知来发送测试通知。从终端 FCM的HTTP API 来帮助调试问题。与Firebase通知控制台不同,它会为您提供遇到的任何原始错误。这里有一个例子:

  curl -XPOSThttps://fcm.googleapis.com/fcm/send\\ \\ 
-HAuthorization:key = SERVER_KEY\
-HContent-Type:application / json\
-d $'{
notification:
body:使用直接FCM API测试,
title:测试消息,
badge:0,
声音: default
},
registration_ids:[
FCM_TOKEN
]
}'

使用您的Firebase控制台>项目设置>云消息传送>服务器密钥中的值填写您的 SERVER_KEY 。用你的FCM令牌替换 FCM_TOKEN 我使用爪子将测试通知发送到我的应用程序。


I updated my pods today to the new Firebase 4.0. I went through the suggested changes and grabbed code from the Github example. I will be honest I am at a loss, I take the FCM Token and send a message from the firebase console and I get nothing.

I refresh and it says the message was sent but I check the console and the device and nothing is there. What am I missing?

Here is my appdelegate:

//
//  Created by Erik Grosskurth on 4/24/17.
//

import UIKit
import FirebaseAnalytics
import FirebaseInstanceID
import FirebaseMessaging
import UserNotifications
import SystemConfiguration
import MobileCoreServices
import Quickblox
import QuickbloxWebRTC


let kQBApplicationID:UInt = 3545252534
let kQBAuthKey = "udfgsegsetrgsextr"
let kQBAuthSecret = "setbsetbsetbsetrbset"
let kQBAccountKey = "sbrtsbrtbsrtbsrtbrt"

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    let gcmMessageIDKey = "gcm.message_id"

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

        // [START register_for_notifications]

        FirebaseApp.configure()

        Messaging.messaging().delegate = self

        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: {_, _ in })
        } else {
            let settings: UIUserNotificationSettings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
            application.registerUserNotificationSettings(settings)
        }

        application.registerForRemoteNotifications()

        if (Messaging.messaging().fcmToken != nil) {
            DataModel.sharedInstance.sessionInfo.FirebaseAccessToken = Messaging.messaging().fcmToken!
            print("FCM token: \(DataModel.sharedInstance.sessionInfo.FirebaseAccessToken)")
        }else {
            print("token was nil")
        }

        // [END register_for_notifications]

        //Quickblox config
        QBSettings.setApplicationID(kQBApplicationID)
        QBSettings.setAuthKey(kQBAuthKey)
        QBSettings.setAuthSecret(kQBAuthSecret)
        QBSettings.setAccountKey(kQBAccountKey)

        // Set settings for zone
        QBSettings.setApiEndpoint("https://api.quickblox.com", chatEndpoint: "chat.quickblox.com", forServiceZone: .production)
        // Activate zone
        QBSettings.setServiceZone(.production)

        QBSettings.setKeepAliveInterval(30)
        QBSettings.setAutoReconnectEnabled(true)
        QBRTCConfig.setStatsReportTimeInterval(1)
        QBRTCConfig.setDialingTimeInterval(5)
        QBRTCConfig.setAnswerTimeInterval(60)

        return true
    }

    // [START receive_message]
    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {

        Messaging.messaging().appDidReceiveMessage(userInfo)

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

        print(userInfo)

    }

    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {

        Messaging.messaging().appDidReceiveMessage(userInfo)

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

        print(userInfo)

        completionHandler(UIBackgroundFetchResult.newData)

    }


    // when APNs has assigned the device a unique token
    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {

        print("didRegisterForRemoteNotificationsWithDeviceToken()")

        Messaging.messaging().apnsToken = deviceToken

        //Messaging.messaging().setAPNSToken(deviceToken, type: MessagingAPNSTokenType.sandbox)
        //Messaging.messaging().setAPNSToken(deviceToken, type: MessagingAPNSTokenType.prod)
        //Messaging.messaging().setAPNSToken(deviceToken, type: MessagingAPNSTokenType.unknown)

        let deviceTokenString = deviceToken.reduce("", {$0 + String(format: "%02X", $1)})
        DataModel.sharedInstance.sessionInfo.APNSAccessToken = deviceTokenString
        print("APNS Access Token: \(deviceTokenString)")

    }


    // [END receive_message]
    func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
        print("Unable to register for remote notifications: \(error.localizedDescription)")
    }


    func applicationWillResignActive(_ application: UIApplication) {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
    }

    func applicationDidEnterBackground(_ application: UIApplication) {
        QBChat.instance().disconnect { (error) in
            if error != nil {
                print("error: \(String(describing: error))")
            } else {
                print("success for applicationDidEnterBackground")
            }
        }
    }

    func applicationWillEnterForeground(_ application: UIApplication) {
        let qbUser = QBUUser()
        qbUser.id = DataModel.sharedInstance.qbLoginParams.id
        qbUser.password = DataModel.sharedInstance.sessionInfo.QBPassword
        QBChat.instance().connect(with: qbUser) { (error) in
            if error != nil {
                print("error: \(String(describing: error))")
            } else {
                print("success for applicationWillEnterForeground")
            }
        }
    }

    func applicationDidBecomeActive(_ application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }

    func applicationWillTerminate(_ application: UIApplication) {
        QBChat.instance().disconnect { (error) in
            if error != nil {
                print("error: \(String(describing: error))")
            } else {
                print("success for applicationWillTerminate")
            }
        }
    }

    // LOCK IN PORTRAIT MODE
    func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
        return UIInterfaceOrientationMask(rawValue: UIInterfaceOrientationMask.portrait.rawValue)
    }

}

// [START ios_10_message_handling]
@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

        // 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)

        // Change this to your preferred presentation option
        completionHandler([])
    }

    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
        let userInfo = response.notification.request.content.userInfo
        // Print message ID.
        if let messageID = userInfo[gcmMessageIDKey] {
            print("Message ID: \(messageID)")
        }

        // Print full message.
        print(userInfo)

        completionHandler()
    }
}
// [END ios_10_message_handling]

extension AppDelegate : MessagingDelegate {
    // [START refresh_token]
    func messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String) {
        DataModel.sharedInstance.sessionInfo.FirebaseAccessToken = fcmToken
        print("Firebase registration token: \(fcmToken)")
    }
    // [END refresh_token]
    // [START ios_10_data_message]
    // Receive data messages on iOS 10+ directly from FCM (bypassing APNs) when the app is in the foreground.
    // To enable direct data messages, you can set Messaging.messaging().shouldEstablishDirectChannel to true.
    func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) {
        print("Received data message: \(remoteMessage.appData)")
    }
    // [END ios_10_data_message]
}

Here are the logs:

2017-05-31 16:49:56.937067-0400 Telemed[1843:937699] [Firebase/Analytics][I-ACS003016] Firebase Analytics App Delegate Proxy is disabled. To log deep link campaigns manually, call the methods in FIRAnalytics+AppDelegate.h.
2017-05-31 16:49:56.937 Telemed[1843] <Warning> [Firebase/Analytics][I-ACS003016] Firebase Analytics App Delegate Proxy is disabled. To log deep link campaigns manually, call the methods in FIRAnalytics+AppDelegate.h.
2017-05-31 16:49:57.023568-0400 Telemed[1843:937706] [Firebase/Analytics][I-ACS005000] The AdSupport Framework is not currently linked. Some features will not function properly. Learn more at 
2017-05-31 16:49:57.023 Telemed[1843] <Warning> [Firebase/Analytics][I-ACS005000] The AdSupport Framework is not currently linked. Some features will not function properly. Learn more at 
2017-05-31 16:49:57.028454-0400 Telemed[1843:937697] [Firebase/Analytics][I-ACS023007] Firebase Analytics v.4000000 started
2017-05-31 16:49:57.028 Telemed[1843] <Notice> [Firebase/Analytics][I-ACS023007] Firebase Analytics v.4000000 started
2017-05-31 16:49:57.029042-0400 Telemed[1843:937697] [Firebase/Analytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see )
2017-05-31 16:49:57.029 Telemed[1843] <Notice> [Firebase/Analytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see )
FCM token: myTokenIsHere
2017-05-31 16:49:57.101756-0400 Telemed[1843:937699] [Firebase/Analytics][I-ACS032003] iAd framework is not linked. Search Ad Attribution Reporter is disabled.
2017-05-31 16:49:57.102 Telemed[1843] <Warning> [Firebase/Analytics][I-ACS032003] iAd framework is not linked. Search Ad Attribution Reporter is disabled.
2017-05-31 16:49:57.103700-0400 Telemed[1843:937697] [Firebase/Analytics][I-ACS023012] Firebase Analytics enabled
2017-05-31 16:49:57.103 Telemed[1843] <Notice> [Firebase/Analytics][I-ACS023012] Firebase Analytics enabled
Destroyed Session but Saved Login
2017-05-31 16:49:57.158678-0400 Telemed[1843:937637] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2017-05-31 16:49:57.159102-0400 Telemed[1843:937637] [MC] Reading from public effective user settings.
didRegisterForRemoteNotificationsWithDeviceToken()
APNS Access Token: 091F01B...

>>>------> **SOLVED <-------<<<**

FOR A DEEP DIVE INTO THE TROUBLESHOOTING AND THE ULTIMATE FACEPALM AT THE END... FOLLOW THIS THREAD: https://github.com/firebase/quickstart-ios/issues/290

SPECIAL THANKS TO THE RIZ FOR HIS TIME IN FIGURING OUT THE ISSUE!!

解决方案

Firebase Cloud Messaging is quite complex to get set up correctly on iOS, because you have to ensure that your APNs configuration is working, and then add FCM on top of that.

APNs Setup

APNs Authentication Keys are also really nice by apple because they don't expire, works in both sandbox and production environments, and the same key (as a .p8 file) can be used to send push notifications to all apps under that Apple Developer account.

It also introduces a new area for a potential failure: typos. You can type in a random bundle id, and as long as the right "team" is configured in Xcode, your app will happily get an APNs device token.

Sending a notification to that device token via APNs (I used this script to send test notifications over HTTP/2 + Auth Keys) will yield a DeviceTokenNotForTopic error, so that should help you figure out what went wrong.

Checklist

  • Ensure your app bundle id matches the bundle id you're sending to
  • Ensure you have an entitlements file, with at least an aps-environment key set to development (this is automatically updated for you in release builds, by Xcode)
  • If using "automatic" configuration (i.e. swizzling) in other SDKs like Firebase, make sure you're getting an APNs token in application:didRegisterForRemoteNotificationsWithDeviceToken:. That at least confirms that your APNs set up is okay (but still you might have a typo)

FCM Setup

Be sure that the GoogleService-Info.plist file you're using is for the same app as the BUNDLE_ID key in the plist. I've seen developers think that because APNs Keys should work just fine across all of their apps, that the same GoogleService-Info.plist is fine across apps, but that's not the case.

Testing

I'd also recommend sending yourself test notifications using FCM's HTTP API from Terminal, to help debug the issue. Unlike the Firebase Notifications Console, it will give you any raw errors it encounters. Here's an example:

curl -X "POST" "https://fcm.googleapis.com/fcm/send" \
     -H "Authorization: key=SERVER_KEY" \
     -H "Content-Type: application/json" \
     -d $'{
  "notification": {
    "body": "Testing with direct FCM API",
    "title": "Test Message",
    "badge": "0",
    "sound": "default"
  },
  "registration_ids": [
    "FCM_TOKEN"
  ]
}'

Fill in your SERVER_KEY with the value in your Firebase Console > Project Settings > Cloud Messaging > Server Key. Replace FCM_TOKEN with your FCM token.

I use Paw to send test notifications to my apps when I'm working on the FCM SDK.

这篇关于推送通知无法在Firebase 4.0中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆