【发布时间】:2017-09-24 16:53:42
【问题描述】:
我按照 firebase 网站上的文档指南做了以下所有事情:
1.在AppDelegate.swift中实现代码。
2. 将 pod 添加到我的 podfile 并安装。
3. 在证书、标识符和 我的 developer.apple 帐户中的配置文件 并将其粘贴到 FCM 设置中。
4. 在项目功能中启用推送通知(选中两个 v)。
5. 创建的证书类型:Apple Push Services for production
我从 firebase 控制台发送了几个通知,但在我的 iPhone (IOS 10.3) 中没有收到任何通知。 有什么要检查的提示吗?我错过了什么?
Podfile:
use_frameworks!
# Pods for App
pod 'Firebase/Core'
pod 'Firebase/Crash'
pod 'Firebase/Messaging'
AppDelegate.swift:
import UIKit
import Firebase
import UserNotifications
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
// Use Firebase library to configure APIs.
FirebaseApp.configure()
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()
return true
}
【问题讨论】:
-
也许您可以尝试使用 Apple Push Services 进行开发,而不是生产,因为我认为您在调试模式下测试应用程序,而不是 Ad-hoc 版本。
-
其实我在生产中发现了问题。我应该启用后台模式远程通知吗?
-
你不需要。我在未启用后台模式远程通知的情况下收到推送通知。仅当您需要静默通知时才使用后台模式远程通知。
标签: ios iphone swift firebase firebase-cloud-messaging