iOS app gets firebase push notification in iOS 14 but not receive in iOS 15.
this code is working for iOS 14 any new configuration about iOS 15:
Messaging.messaging().delegate = self
UNUserNotificationCenter.current().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(options: authOptions) { _, error in
if let error = error {
print("requestAuthorization Error: \(error.localizedDescription)")
}
}
application.registerForRemoteNotifications()
You might have to re-upload the apns token .p8 in your firebase project cloud messaging configuration. It's the second time its happened to me.
Related
I have this code to push app notifications.
It works well but I get this warning:
'MessagingRemoteMessage' is deprecated: FCM direct channel is deprecated, please use APNs for downstream message handling.
and this one 'appData' is deprecated
I made a research on Google but didn't find anything to fix this.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
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 })
// For iOS 10 data message (sent via FCM
Messaging.messaging().delegate = self
} else {
let settings: UIUserNotificationSettings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
application.registerUserNotificationSettings(settings)
}
application.registerForRemoteNotifications()
FirebaseApp.configure()
return true
}
// The callback to handle data message received via FCM for devices running iOS 10 or above.
func applicationReceivedRemoteMessage(_ remoteMessage: MessagingRemoteMessage) {
print(remoteMessage.appData)
}
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.
I'm facing this weird issue with a new project I've setup using firebase. Notifications are working, however there are two main issues I've noticed:
They never appear as a banner that pops-down when my phone is on/home screen, instead they only appear when viewing all my notifications in the notification center (swiping all the way left from home)
I can't get them to play a sound (adding a badge does indeed work).
Additionally, I tried this from both the firebase admin sdk (web, node js), and from their "Cloud Messaging" wizard - both with the same results, leading me to think its something I've set incorrectly in my project?
Here is how I register for notifications:
func requestNotificationsSystemAuth() {
let appDelegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.current().delegate = appDelegate as UNUserNotificationCenterDelegate
Messaging.messaging().delegate = appDelegate as MessagingDelegate
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: { _, _ in })
UIApplication.shared.registerForRemoteNotifications()
}
Other apps are playing sound in notifications.
Any idea?? I'm losing hope!
For those who were wondering, my issue was device related weirdly enough.
I just restarted my phone, and it started working again.
if #available(iOS 10.0, *) {
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: {_, _ in }
)
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.current().delegate = self
// For iOS 10 data message (sent via FCM)
FIRMessaging.messaging().remoteMessageDelegate = self //ERROR THIS LINE
}
else {
let settings: UIUserNotificationSettings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
application.registerUserNotificationSettings(settings)
}
Getting error when set the delegate to self.
"FIRMessing has no member remoteMessageDelegate"
It looks like the Google documentation is out of date.
Please run the following commands in your terminal:
pod repo update
Then go to your project folder and run
pod update
(please mark this as the solution if this helped you)
Try this:
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, FIRMessagingDelegate{
}
//MARK: FIRMessaging Delegate
func applicationReceivedRemoteMessage(remoteMessage: FIRMessagingRemoteMessage){
}
I am trying to use Firebase to handle push notifications. I have installed Firebase pod ('Firebase/Core' and 'FirebaseMessaging' pods).
And after I imported Firebase to the project
import Firebase
I have configured the Firebase app like this( code is copied from official docs ):
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?)
-> Bool {FIRApp.configure() }
After that I've tried to use this code ( code is copied from official docs ):
if #available(iOS 10.0, *) {
let authOptions : UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: {_,_ in })
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.current().delegate = self
// For iOS 10 data message (sent via FCM)
FIRMessaging.messaging().remoteMessageDelegate = self
} else {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
application.registerUserNotificationSettings(settings)
}
application.registerForRemoteNotifications()
But I got the error from the title which says:
Use of undeclared type UNAuthorizationOptions
also I am having the same error related to the UNUserNotificationCenter class.
I am using Swift 2.2 and Xcode 7.3.1
What is the cause of this error?
you need to import UserNotifications before calling those framework. And what Nirav D said is true, it is a new framework in iOS 10, should also remember to select the correct deployment target.
UserNotifications.framework is available from iOS 10 and you are working with Xcode 7.3 means with iOS 9 and lower, So there is no need for you to add that if #available(iOS 10.0, *) {, write only else part directly and register remote notifications.
let settings: UIUserNotificationSettings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
application.registerUserNotificationSettings(settings)
application.registerForRemoteNotifications()
I am using Firebase in my app. I have installed via the Cocoapods. To make support for push notification in iOS 10 I have updated the cocoa pods with the latest version of Firebase 3.7.0.
Please let me know does it support in iOS 7 and iOS 8.
Registeration of push notification like this
if #available(iOS 10.0, *) {
let authOptions : UNAuthorizationOptions = [.Alert, .Badge, .Sound]
UNUserNotificationCenter.currentNotificationCenter().requestAuthorizationWithOptions(
authOptions,
completionHandler: {_,_ in })
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.currentNotificationCenter().delegate = self
// For iOS 10 data message (sent via FCM)
FIRMessaging.messaging().remoteMessageDelegate = self
} else {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
application.registerUserNotificationSettings(settings)
application.registerForRemoteNotifications()
}
Thanks