在Xcode 8中更改用于推送通知的捆绑包标识符并集成Firebase,可以按照以下步骤进行操作:
Command + S
保存更改。GoogleService-Info.plist
文件:GoogleService-Info.plist
文件。GoogleService-Info.plist
文件已添加到项目中,并且其目标设置为你的应用目标。GoogleService-Info.plist
文件被包含在“Copy Bundle Resources”阶段。Info.plist
文件:
在项目导航器中找到并打开Info.plist
文件。Podfile
中添加以下行:
pod 'Firebase/Core' pod 'Firebase/Messaging'
然后在终端运行pod install
。AppDelegate.swift
文件中,导入Firebase并初始化它:
import Firebase func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { FirebaseApp.configure() return true }AppDelegate.swift
中,添加以下代码以注册推送通知:
import UserNotifications func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { FirebaseApp.configure() UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { granted, error in print("Permission granted: \(granted)") } application.registerForRemoteNotifications() return true } func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { Messaging.messaging().apnsToken = deviceToken } func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) { print("Failed to register for remote notifications with error: \(error)") }领取专属 10元无门槛券
手把手带您无忧上云