mirzemehdi / KMPNotifier

Kotlin Multiplatform Push Notification Library targetting android, iOS, Desktop and Web (JS and Wasm)
http://mirzemehdi.com/KMPNotifier/
Apache License 2.0
340 stars 19 forks source link

Error while getting token #38

Closed andiosdev closed 3 months ago

andiosdev commented 5 months ago

Hi,

Followed everything and got push notification working ion Android but in iOS I'm getting this error:

Error Domain=com.google.fcm Code=505 "No APNS token specified before fetching FCM Token" UserInfo={NSLocalizedFailureReason=No APNS token specified before fetching FCM Token}

mirzemehdi commented 5 months ago

@andiosdev Please check this issue, I wrote solution there: https://github.com/mirzemehdi/KMPNotifier/issues/3

chen-lihan commented 5 months ago

Add this line in info.plist will fix FirebaseAppDelegateProxyEnabled / Boolean / NO

スクリーンショット 2024-06-21 15 39 25

andiosdev commented 4 months ago

@chen-lihan still getting the error. Not sure if it's the reason for not receiving notification in iOS.

APNS device token not set before retrieving FCM Token for Sender ID '-----'.Be sure to re-retrieve the FCM token once the APNS device token is set.

Declining request for FCM Token since no APNS Token specified

Error while getting token: Error Domain=com.google.fcm Code=505 "No APNS token specified before fetching FCM Token" UserInfo={NSLocalizedFailureReason=No APNS token specified before fetching FCM Token}

chen-lihan commented 4 months ago

@andiosdev ,ohh! Could you check your ios code? i forgot it . i add this line on application block .

application.registerForRemoteNotifications()


class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

        FirebaseApp.configure()

        NotifierManager.shared.initialize(configuration: NotificationPlatformConfigurationIos(showPushNotification: true, askNotificationPermissionOnStart: false)

        )
        application.registerForRemoteNotifications()
`

And Notice Your APNS KEY Is Correct 
andiosdev commented 4 months ago

I have similar code in my AppDelegate and still error exists. Where do I check if my APNS Key is correct?

chen-lihan commented 4 months ago

@andiosdev Your Firebase And Apple Developer Account Page

andiosdev commented 4 months ago

@chen-lihan Thank you. I was to able to get this running.

@mirzemehdi I don't know what I missed but I'm getting this error "Cannot find 'NotifierManager' in scope" inside iOSApp.swift. I have the following imports:

import SwiftUI
import ComposeApp
import FirebaseCore
import FirebaseMessaging

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) async -> UIBackgroundFetchResult {

        NotifierManager.shared.onApplicationDidReceiveRemoteNotification(userInfo: userInfo)

        return UIBackgroundFetchResult.newData
    }
mirzemehdi commented 4 months ago

@andiosdev maybe for ios part you didn't export library in app build gradle file, that's why it is not visible in swift side


listOf(
        iosX64(),
        iosArm64(),
        iosSimulatorArm64()
    ).forEach { iosTarget ->
        iosTarget.binaries.framework {
            export(libs.kmpnotifier) 
            baseName = "sample"
            isStatic = true
        }
    }
mirzemehdi commented 3 months ago

Closing this issue due to inactivity. If this is still an issue or need a help, please feel free to reopen the issue and provide additional context or updates. Thank you.