I'm using FCM to send push notifs to single iOS devices, triggered on http request to Firebase Cloud Functions. After following the FCM and APNs docs, everything is working nominally when app is running in background. I successfully receive the notification in all cases.
The only problem: push notifs are not lighting up my lock screen from sleeping. I still receive the push notif and can see it when I press the home button to manually wake the device up. But the notif itself does not wake up my device.
How To Replicate
- Open app
- Press home button (now app is now in background)
- Lock phone
- Send push notif
- Notif is received but does not light up lock screen.
I've turned on 'Background Modes' capability > Selected both 'Remote notifications' and 'Background fetch'. My deployment target is 10.0. Lock screen notifications are allowed for my app.
(Most of the answers to similar questions have been, "turn on Background modes" or "set content-available to 1," of which I've done both.)
My cloud function that sends payload to APNs:
exports.pushMatchNotif = functions.https.onRequest((req, res) => {
let receiverToken = req.receiverToken
var msg = {
'apns': {
'header': {
'apns-priority': '10'
},
'payload': {
'aps': {
'alert': {
'title': 'Hi',
'body': 'Hello',
},
'badge': 2,
'sound': 'default'
'content-available': 1
}
}
},
'token': receiverToken
};
admin.messaging().send(msg)
.then((response) => {
// Response is a message ID string.
console.log('Successfully sent message:', response);
let json = {"Response": response}
res.send(json)
})
.catch((error) => {
console.log('Error sending message:', error);
let json = {"Error": error}
res.send(json)
});
})
My didFinishLaunchingWithOptions method:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
Messaging.messaging().delegate = self
UNUserNotificationCenter.current().delegate = self
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.alert, .badge , .sound]) {
(granted, error) in
print("granted is \(granted)")
}
application.registerForRemoteNotifications()
return true
}
My didReceiveRegistrationToken method (FCM delegate method):
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
print("Firebase deviced token: \(fcmToken)")
}
My didReceiveRemoteNotification method:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
// Print message ID.
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: \(messageID)")
}
// Print full message.
print(userInfo)
}
What am I missing?