I am planning to implement silent notifications via FCM in my iOS app. I found many articles and SO posts describing how to achieve this. But my question stems from the fact that I found this code snippet in the FCM documentation. Please note the first line of the comment.
func application(_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult)
-> Void) {
// If you are receiving a notification message while your app is in the background,
// this callback will not be fired till the user taps on the notification launching the application.
// TODO: Handle data of notification
// With swizzling disabled you must let Messaging know about the message, for Analytics
// Messaging.messaging().appDidReceiveMessage(userInfo)
// Print message ID.
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: \(messageID)")
}
// Print full message.
print(userInfo)
completionHandler(UIBackgroundFetchResult.newData)
}
This code is provided under the heading Handle silent push notifications. As per my understanding, silent notifications do not appear on the screen or alert the user in any way, no matter in what state the app is in. Then why is there a mention about tapping the notification ?
My intention is to send a silent notification to the iOS device and perform some background task without any user interaction. The limitations of background notifications are acceptable. As I do not currently have the permissions to a apple developer account to test this out, could any one tell me if this can be achieved with FCM ? Or should I consider using APNS directly ?