小编EQO*_*123的帖子

iOS Firebase推送通知:如何提供Firebase用户的设备令牌和发送通知

最近在谷歌I/O活动中谷歌重新装修了Firebase并增加了许多新功能,并触及了其余的功能.我一直在尝试通过Firebase将iOS推送通知实现到我的应用程序中,通过最基本的级别,所以我创建了一个非常简单的应用程序除了接收远程推送通知之外什么都不做.

在Firebase内部,我上传了我的证书,在Xcode中,我的配置文件已添加到目标和项目中,而在Firebase中我已上传了正确的证书.下面是我的AppDelegate.swift文件中包含的代码,但因为我ViewController.swift的"空",我没有包含它.

虽然没有崩溃或运行时错误,但当我加载应用程序时,我接受通知.然后,我退出应用程序并关闭我的设备.在Firebase中,我将通知发送到正确的应用.几分钟后,在Firebase中,它说通知是"已完成".

但是,我从未收到过设备上的通知.因此,总之,我需要一个解决方案来发送Firebase deviceToken,然后使用"Firebase Notifications"发送推送通知消息.

我的代码或一般的任何帮助将不胜感激,我希望这有助于未来的观众.谢谢!我的代码在AppDelegate.swift:

import UIKit
import Firebase
import FirebaseMessaging

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

        FIRApp.configure()

        let notificationTypes : UIUserNotificationType = [UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound]

        let notificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: nil)

        application.registerForRemoteNotifications()
        application.registerUserNotificationSettings(notificationSettings)

        return true
    }

    func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {

        print("Device Token: \(deviceToken)")

    }

    func applicationWillResignActive(application: UIApplication) {

    }

    func applicationDidEnterBackground(application: UIApplication) { …
Run Code Online (Sandbox Code Playgroud)

push-notification ios firebase

17
推荐指数
3
解决办法
5万
查看次数

标签 统计

firebase ×1

ios ×1

push-notification ×1