I am using Compose Multiplatform to develop a mobile app, and I need to obtain the Apple APNs token to submit it to the server. I have been searching for examples, and I found that in Swift, you can write the following code in the AppDelegate to get the token:
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let token = deviceToken.map { String(format: "%02.2hhx", $0) }.joined()
print("\(token)")
}
However, I need guidance on how to achieve this in kotlin Multiplatform.
I have written the following code in Kotlin for registration APNs.
actual suspend fun fetchNotifyToken(tokenFun: (String) -> Unit) {
UIApplication.sharedApplication.registerForRemoteNotifications()
}
I'm trying to find a Kotlin equivalent for a method similar to 'didRegisterForRemoteNotificationsWithDeviceToken' in order to listen for the successful registration and receive a callback with the token.
Is there something similar to 'didRegisterForRemoteNotificationsWithDeviceToken' in platform.UIKit to listen for the token?
If I can only obtain this token value within the Swift's AppDelegate, how should I pass the token back to KMP (KMM) so that I can use the KMP framework to submit the token to the server?