【发布时间】:2018-05-25 21:48:25
【问题描述】:
我使用 Firebase 通过我的 iOS 应用发送通知,我已按照文档中的所有步骤操作:
Apple 开发者帐户配置
生成 CSR 文件
正在上传 CSF 文件
准备 APNs 证书
为推送通知配置 Firebase
在我的应用中构建 Firebase 通知
当我尝试发送通知时,对于某个特定用户或所有 iOS 设备,在 Firebase 中都没有发现问题。但是我的设备(显然是真实设备)都没有收到通知。
我使用了好的 Bundle,我在我的应用程序中启用了通知,并且我的 AppDelegate 中有代码:
import UIKit
import UserNotifications
import Firebase
import FirebaseInstanceID
import FirebaseMessaging
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, MessagingDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
UINavigationBar.appearance().barTintColor = Design.blue_es
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName:UIColor.white]
UINavigationBar.appearance().tintColor = UIColor.white
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 })
// For iOS 10 data message (sent via FCM
Messaging.messaging().remoteMessageDelegate = self
} else {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
application.registerUserNotificationSettings(settings)
}
application.registerForRemoteNotifications()
FirebaseApp.configure()
return true
}
func application(received remoteMessage: MessagingRemoteMessage) {
print(remoteMessage.appData)
}
// Called when APNs failed to register the device for push notifications
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
// Print the error to console (you should alert the user that registration failed)
print("APNs registration failed: \(error)")
}
func messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String) {
print("Firebase registration token: \(fcmToken)")
}
}
【问题讨论】:
-
您是否在 Firebase 控制台上上传了无密钥的推送通知证书的 P12 证书?
-
我上传了P12证书,但是我不明白你说的“没有密钥”是什么意思
-
当您从 Keychain 导出证书时,您会看到 Apple Push 名称左侧的一个下拉箭头 展开它您将看到 Key 图标
-
好的,我已经上传了带有钥匙串的 P12 证书用于生产和开发通知,但我使用相同的 CSR 来生成它们
标签: ios firebase swift3 push-notification