Firebase -'isDirectChannelEstablished' is deprecated: FCM direct channel is deprecated, please use APNs channel for downstream message delivery
It sounds like you should just remove that line. According to the API documentation:
When set to YES, Firebase Messaging will automatically establish a
socket-based, direct channel to the FCM server. Enable this only if
you are sending upstream messages or receiving non-APNS, data-only
messages in foregrounded apps. Default is NO.
So, unless your app is doing either of the things described here, it's not necessary. According to the release notes:
Deprecated FCM direct channel messaging via
shouldEstablishDirectChannel. Instead, use APNs for downstream message
delivery. Add content_available key to your payload if you want to
continue use legacy APIs, but we strongly recommend HTTP v1 API as it
provides full APNs support. The deprecated API will be removed in
Firebase 7 (#4710).
Update deprecated Firebase functions in Swift
The question is whether you are simply sending display/alert notifications and background notifications? Or are you using direct channel to send some hidden data message for real time updates?
MessagingRemoteMessage is data message object sent and handled through direct channel. If you only want to push notifications, and you also don't seem to enable direct channel in your code above. You can use Apple's API UNUserNotificationCenterDelegate to handle alert message or AppDelegate application:didReceiveRemoteNotification:fetchCompletionHandler:
to handle background notifications.
FCM - Cannot find type 'MessagingRemoteMessage' in scope
MessagingRemoteMessage
was removed from Firebase in the 7.0.0 release.
More info at Update deprecated Firebase functions in Swift
FCM iOS Push Notification cannot receive any notification
Please check if you have activated Push Notifications in your Project Capabilities
Create Development APNs certificate and add it to Firebase Console Project Settings
In your App Delegate
import FirebaseMessaging
import UserNotifications
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate,
UNUserNotificationCenterDelegate, MessagingDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
//REMOTE NOTIFICATION
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()
Messaging.messaging().delegate = self
let token = Messaging.messaging().fcmToken
print("FCM token: \(token ?? "")")
//Added Code to display notification when app is in Foreground
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self
} else {
// Fallback on earlier versions
}
return true
}
func application(_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken as Data
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
// Print full message.
print(userInfo)
}
// This method will be called when app received push notifications in foreground
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)
{ completionHandler([UNNotificationPresentationOptions.alert,UNNotificationPresentationOptions.sound,UNNotificationPresentationOptions.badge])
}
// MARK:- Messaging Delegates
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
InstanceID.instanceID().instanceID { (result, error) in
if let error = error {
print("Error fetching remote instange ID: \(error)")
} else if let result = result {
print("Remote instance ID token: \(result.token)")
}
}
}
func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) {
print("received remote notification")
}
}
FCM - why no longer support FCM direct channel in newer Firebase Admin SDK?
If I'm not mistaken FCM sender-side APIs never explicitly supported a direct channel option. As a sender your options were to either specify a device registration token or a topic. These options are present in the newer FCM sender-side APIs (i.e. Admin SDK) as well.
Direct channel is a receiver-end option. I see this option was recently deprecated in the iOS SDK. Folks who work on that repo should be able to provide you more context around that decision. Also if you're experiencing issues with background notifications on iOS I'd recommend you file a bug for the iOS SDK, and try to get it fixed.
iOS12 / swift / Received FCM PUSH Message not working
This code is work well.
My mistake is adding wrong certification ( APNS Key Id was wrong )
if you use this code and FCM PUSH isn't received.
check you certification or APNS Key
Related Topics
Saving Highscores with Nsuserdefaults
Drag a Cgrect Using Uipangesturerecognizer
Inline Kvo of a Property in Another View Controller
Remove \\U{E2} Characters from String
How to Display an Int Without Commas
How to Avoid Duplicate Key Error in Swift When Iterating Over a Dictionary
Cast Any to Float Always Fails in Swift4.1
Hovering a Modelentity in Front of Arcamera
Swift Delegate Beetween Two Vc Without Segue
How to Set Scrollview Content Size in Swift 3.0
What Are the Fundamental Differences Between Set and Didset
Swift - Encode and Decode a Dictionary [String:Any] into Plist
Swift: Accessing Computed Property Through Pointer