OGeek|极客世界-中国程序员成长平台

标题: ios - 在详细 Controller 中打开通知 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 19:57
标题: ios - 在详细 Controller 中打开通知

我在我的项目中使用 FireBase,并收到主题通知。就像点击通知打开并将数据传递给详细 Controller 时一样。

例如在 BBC 新闻节目中

这是 Storyboard

enter image description here

import UIKit  
import UserNotifications  
import Firebase  
import FirebaseInstanceID  
import FirebaseMessaging  
import SystemConfiguration

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate , UNUserNotificationCenterDelegate, MessagingDelegate{

var window: UIWindow?    

func messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String) {
    print("Firebase registration token: \(fcmToken)")
}

func application(_ application: UIApplication,
                 didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    Messaging.messaging().apnsToken = deviceToken as Data
}

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    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()


    DispatchQueue.main.async {

        Messaging.messaging().subscribe(toTopic: "news")
    }

    FirebaseApp.configure()


    return true
 }
}



Best Answer-推荐答案


Refer This

你需要重定向到你特定的详细 View Controller

关于ios - 在详细 Controller 中打开通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44756942/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) Powered by Discuz! X3.4