【发布时间】:2018-04-19 11:27:37
【问题描述】:
您好,我正在尝试实现 google firebase 推送通知并订阅主题。
我能够接收推送通知但没有订阅主题。错误提示 Cannot subscribe to topic: 000000005eb68872 with token: (null) 但我已经生成了令牌。
我正在使用 IOS 11 和 Xcode 9.0
Pod 文件
target 'VQ Smart Home' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for VQ Smart Home
pod 'SwiftyJSON'
pod 'NVActivityIndicatorView'
pod 'Firebase/Core', '4.0.4'
pod 'Firebase/Database', '4.0.4'
pod 'Firebase/Messaging', '4.0.4'
pod 'FirebaseInstanceID', '2.0.0'
end
AppDelegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
UINavigationBar.appearance().isTranslucent = true
/************************ FireBase Notification ************************************************************************/
FirebaseApp.configure()
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
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()
let token = Messaging.messaging().fcmToken
print("********* FCM token: \(token ?? "") *************")
hubId = (isKeyPresentInUserDefaults(key: "hubID")) ? (UserDefaults.standard.value(forKey: "hubID") as? String)! : "NohubId"
Messaging.messaging().subscribe(toTopic: hubId)
/************************ FireBase Notification ************************************************************************/
return true
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken
}
// Push Notification Methods
func messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String) {
print("Firebase registration token: \(fcmToken)")
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
print(userInfo)
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
print(userInfo)
let aps = userInfo["aps"] as! NSDictionary
print(aps["alert"] as? String ?? "")
completionHandler(UIBackgroundFetchResult.newData)
}
错误堆栈
[1022:258833] [Firebase/Analytics][I-ACS003016] Firebase Analytics App Delegate Proxy is disabled. To log deep link campaigns manually,调用 FIRAnalytics+AppDelegate.h 中的方法。 [1022] [Firebase/Analytics][I-ACS003016] Firebase Analytics 应用程序委托代理已禁用。记录深层链接活动 手动调用 FIRAnalytics+AppDelegate.h 中的方法。 ********* FCM 令牌:dLdjXagKJpA:APA91bH500MivUUFRUl-1mgqn7qrzp6lVG2divijtBR9RYBgQu4slIBE8W7FN_3VtM_lbyE7S-xcgK40dzrlw2h4fz0SzDrfyPF90KIrUUqE9qNDwOGGrtOLemV1qC1w
[1022:258837] [BoringSSL] Function boringssl_context_get_peer_sct_list: line 1754 received sct extension长度小于 sct 数据长度 [1022:258810] [MC] 延迟加载 NSBundle MobileCoreServices.framework [1022:258810] [MC] 加载 MobileCoreServices.framework [1022:258838] [Firebase/Messaging][I-FCM002010] 无法使用令牌订阅主题:000000005eb68872:(null) [1022:258810] [MC] systemgroup.com.apple.configurationprofiles 路径的系统组容器是 /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles ] [Firebase/Messaging][I-FCM002010] 无法使用令牌订阅主题:000000005eb68872:(null) [1022:258838] [Firebase/Analytics][I-ACS005000] AdSupport 框架当前未链接。某些功能将无法运行 适当地。在 http:// 了解更多信息 ] [Firebase/Analytics][I-ACS005000] AdSupport 框架当前未链接。某些功能将无法运行 适当地。在 http:// 了解更多信息 [1022:258810] 刷新首选项:HangTracerEnabled:0 [1022:258810] 刷新首选项:HangTracerDuration:500 [1022:258810] refreshPreferences: ActivationLoggingEnabled: 0 ActivationLoggingTaskedOffByDA:0 [1022:258832] [Firebase/Analytics][I-ACS023007] Firebase Analytics v.40002000 已启动 ] [Firebase/Analytics][I-ACS023007] Firebase Analytics v.40002000 已启动 [1022:258832] [Firebase/Analytics][I-ACS023008] 要启用调试日志记录,请设置以下应用程序参数: -FIRAnalyticsDebugEnabled(请参阅 ) ] [Firebase/Analytics][I-ACS023008] 要启用调试日志记录,请设置以下应用程序参数: -FIRAnalyticsDebugEnabled(请参阅 ) [1022:258839] [Firebase/Analytics][I-ACS032003] iAd 框架未链接。搜索广告归因报告器已停用。 ] [Firebase/Analytics][I-ACS032003] iAd 框架未链接。搜索广告归因报告器已停用。 [1022:258839] [Firebase/Analytics][I-ACS023012] Firebase 分析已启用 ] [Firebase/Analytics][I-ACS023012] Firebase 分析已启用 [1022:258833] TIC 读取状态 [1:0x0]: 1:57 [1022:258833] TIC 读取状态 [1:0x0]: 1:57
谁能帮我修复这个 tnx..
【问题讨论】:
标签: ios swift xcode push-notification