ios - IOS 应用程序中的 Firebase 云消息传递 (FCM) 无法正常工作

标签 ios iphone swift firebase firebase-cloud-messaging

我按照 firebase 网站中的文档指南进行操作,并执行了以下所有操作:

1.实现了AppDelegate.swift中的代码。

2. 将 pod 添加到我的 podfile 中并安装。

3. 在证书、标识符和中创建 APN 身份验证 key 配置文件在我的developer.apple帐户中并将其粘贴到FCM设置中。

4.在项目功能中启用推送通知(选中两个 v)。

5. 创建的证书类型:用于生产的 Apple Push Services

我从 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
    }

最佳答案

您必须添加一些方法。

只需将您的 AppDelegate.swift 与 this one 进行比较即可:)

这是来自 firebase-guys 的“官方”样本(我想是的:D)

关于ios - IOS 应用程序中的 Firebase 云消息传递 (FCM) 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46392508/

相关文章:

ios - 横向模式下小部件的问题

iOS PhoneGap 应用卡住了

iPhone/Android SMS 截获并重定向到应用程序

ios - Swift:自定义 View 层次结构

iphone - UIGraphicsGetImageFromCurrentImageContext 提供质量差/低分辨率的图像,我该如何改善?

iphone - 如何对选择器的引用进行编码/解码?

xcode - swift 泛型 : More specialized than generic?

iOS链接两个firebase帐户错误

iOS:模式转换到黑屏?

ios - 正则表达式返回整个字符串 iOS NSRegularExpression