-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: UNNotificationServiceExtension support on iOS? #24
Comments
@tamimattafi How it works in ios? You can change content even app is in background, and after you get push notification you can change content? |
In foreground when you get notification you can modify it currently, and show it as you wanted. For this when you initialize the library for configuration parameter (showPushNotification) you need to pass false, then on listeners, you can show user any modified notication. //Android NotifierManager.initialize(
configuration = NotificationPlatformConfiguration.Android(
notificationIconResId = R.drawable.ic_launcher_foreground,
showPushNotification = false,
)
) //ios NotifierManager.shared.initialize(configuration: NotificationPlatformConfigurationIos(showPushNotification: false)) https://github.com/mirzemehdi/KMPNotifier?tab=readme-ov-file#platform-setup |
@mirzemehdi Yes, the extension service is meant to work in the background |
However when app is in background, and when receiving notification type of message, notification title and body will be shown as it is to the user as this will be handled by the system, in android it is like that at least. But you can hack around by sending only data type of message, then based on that you can show to the user whatever you want. |
@mirzemehdi Is there a possibility of showing a notification from the background, using data type messages? I would be very thankful if you point out to an example. |
@tamimattafi Looks like using data type messages with ios when it is in background is tricky. For my case, I can get notification type of message both in background and foreground, but I also have a problem receiving data type of message when app is in background. I also checked this one https://stackoverflow.com/questions/38166203/ios-data-notifications-with-fcm, and even setting If you can find another solution, you can let us know here as well! |
@mirzemehdi I implemented
My experience with Push Notifications on iOS is kind of interesting but frustrating at the same time, not sure why they chose to have different entry points and different targets. |
@tamimattafi Thanks for detailed explanation. Look like very complicated thing :D. I need to research that for understanding better |
Hey Guys, |
@koushikvkk yeah this is currently issue, trying to work on that |
Ok. Thanks for the info @mirzemehdi. |
@koushikvkk for receiving data type message in ios, I wrote here #54 (comment) Basically main thing that is working for me to get data type only message in ios, is to add |
Hey @mirzemehdi, Thanks for the info. |
@Koushiktrimble yes, and no. So here is what happens when app is in background. I think this is limitation from ios side, but not sure if someone can find more information let us know please.
|
so this is called silent notification (sending data type message only), and as I see from documentation this is not guaranteed to be received always in ios. That's why I always send both data and notification type message together. |
@mirzemehdi Hello! If you want to guarantee that the user sees a notification (Display it on the UI), you should always send alerts with badge and sound properties. If you want to customize their text and style on the client side, you should implement Notification Service Extension, and add mutable-content: 1 to your aps payload. Clicking on a notification should trigger delegate function didFinishLaunchingWithOptions, with a dictionary of data from the push notification you clicked, so you should solely rely on this when you handle clicks and never rely on the data notification. |
@tamimattafi thank you for this info. Even printing something to the logs doesn't work. is this expected then? |
@Koushiktrimble |
@mirzemehdi @tamimattafi |
@Louisnil-AS You can write Check these docs: https://developer.apple.com/documentation/usernotifications/unnotificationserviceextension/ |
@tamimattafi |
@Louisnil-AS Yes, the Extension runs and allows HTTP requests and local storage operations. But the time should not exceed few seconds, and the total memory consumption of this process should not exceed 24MB. So if you can live with these limitations, it's possible to do what you are looking for. |
@mirzemehdi |
@tmdgh1592 onPayloadData functions is called in background if it contains both notification and data type message. But if it contains data type message (silent message), then it is not called. But check @tamimattafi 's comment too: #24 (comment) |
@mirzemehdi Thank you I tried it in postman
I checked your mentioned comments(#24) and tried including apns and badge instead of notification type, |
Correction to above request @tmdgh1592 would be adding apns -> .... badge also as below
|
@mirzemehdi I tried this format and the result is still the same |
@tmdgh1592 yes device_id is fcm token. in logs you will not see payload data when app is in background. But when you click notification, then after app comes foreground onPayloadData will be triggered and you will get data there |
@mirzemehdi |
@tmdgh1592 then make sure in ios https://github.com/mirzemehdi/KMPNotifier?tab=readme-ov-file#ios If you did that step too and all other steps in ReadMe, not sure what can be missing |
@mirzemehdi func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) async -> UIBackgroundFetchResult {
NotifierManager.shared.onApplicationDidReceiveRemoteNotification(userInfo: userInfo)
return UIBackgroundFetchResult.newData
} import SwiftUI
import ComposeApp
import FirebaseCore
import FirebaseMessaging
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
FirebaseApp.configure()
NotifierInitializer.shared.onApplicationStart()
return true
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) async -> UIBackgroundFetchResult {
NotifierManager.shared.onApplicationDidReceiveRemoteNotification(userInfo: userInfo)
return UIBackgroundFetchResult.newData
}
}
@main
struct iOSApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var delegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
} As of now, I don't really know... |
@tmdgh1592 Have you tried adding this flag? |
I implemented the ability to display push notifications in onPayloadData(). If it's okay, can you show me the json format you use in your fcm? I tried like below
|
@tmdgh1592 I don't use |
@tamimattafi Still, thank you for your helpful comment, bro. |
Hello Mr. @mirzemehdi |
Hello!
Thank you for this amazing library!
I'm wondering, is there a possibility we could have support for changing push notification content for iOS? In a native app, it's usually done using
UNNotificationServiceExtension
, is it technically possible we could have access to such functionality directly from the library and on the Kotlin side (iosMain for instance) without having to implement such extension in every project?The text was updated successfully, but these errors were encountered: