I followed the documentation guide in firebase website and did all the following stuff:
1. Implemented the code in AppDelegate.swift.
2. Added the pods to my podfile and installed.
3. Created APN authentication key in Certifictes, Identifiers & Profiles in my developer.apple account and Paste it in the FCM settings.
4. Enabled Push Notification in project Capabilities (two v checked).
5. Created Certificate type: Apple Push Services for production
I sent couple of notifications from firebase console and didn't received any in my iPhone (IOS 10.3). Any tips what to check? what did i miss?
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
}
you have to add a few methods.
Just compare your AppDelegate.swift with this one :)
This is the "official" sample from the firebase-guys (I think so :D)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.