firebase / firebase-ios-sdk

Firebase SDK for Apple App Development
https://firebase.google.com
Apache License 2.0
5.48k stars 1.44k forks source link

Messaging.messaging().deleteData don't work #13022

Closed chekmari closed 1 month ago

chekmari commented 2 months ago

Description

Messaging.messaging().deleteData don't work

I do deleteData during a logout. My server sends a push after logout and firebase instead of giving an error to the server sends a push to the phone. Why is this happening.

`

 func resetInstanceId() -> Single<Void?> {
    return Single.create { single in
        Messaging.messaging().deleteData { error in
            #if targetEnvironment(simulator)

            return single(.success(()))

            #else

            guard let error = error else {
                single(.success(()))
                return
            }

            let nsError = error as NSError

            if nsError.domain == "NSURLErrorDomain", nsError.code == -1009 {
                single(.failure(NSError.PushNotificationServiceError.connectionRequired))
            } else {
                single(.failure(error))
            }

            #endif
        }

        return Disposables.create()
    }
}

`

Reproducing the issue

` input.logoutTrigger .drive( onNext: { [weak self] in let noAction = UIAlertAction(title: NSLocalizedString("No", comment: ""), style: .cancel, handler: nil)

                let yesAction = UIAlertAction(title: NSLocalizedString("Yes", comment: ""), style: .destructive) { _ in
                    guard let self = self else {
                        return
                    }

                    self.pushNotificationService.deletePushToken()
                        .trackActivity(activityTracker)
                        .trackError(errorTracker)
                        .asDriver(onErrorJustReturn: nil)
                        .ignoreNil()
                        .drive()
                        .disposed(by: self.disposeBag)

                    self.pushNotificationService.resetInstanceId()
                        .trackActivity(activityTracker)
                        .trackError(errorTracker)
                        .asDriver(onErrorJustReturn: nil)
                        .ignoreNil()
                        .drive(
                            onNext: { [weak self] in
                                SmartYardSharedDataUtilities.clearSharedData()
                                self?.accessService.logout()
                            }
                        )
                        .disposed(by: self.disposeBag)
                }

                self?.router.trigger(
                    .dialog(
                        title: NSLocalizedString("Exiting the application", comment: ""),
                        message: NSLocalizedString("Are you sure you want to log out of your account?", comment: ""),
                        actions: [noAction, yesAction]
                    )
                )
            }
        )
        .disposed(by: disposeBag)

`

Firebase SDK Version

10.24 and 10.23

Xcode Version

15.4

Installation Method

Swift Package Manager

Firebase Product(s)

Messaging

Targeted Platforms

iOS

Relevant Log Output

10.23.0 - [FirebaseAnalytics][I-ACS023105] Event is not subject to real-time event count daily limit. Marking an event as real-time. Event name, parameters: screen_view (_vs), {
    ga_debug (_dbg) = 1;
    ga_event_origin (_o) = auto;
    ga_previous_class (_pc) = CommonSettingsViewController;
    ga_previous_id (_pi) = -2597384335633240837;
    ga_realtime (_r) = 1;
    ga_screen_class (_sc) = UIAlertController;
    ga_screen_id (_si) = -2597384335633240836;
}
10.23.0 - [FirebaseAnalytics][I-ACS023087] User property set. Name, value: lifetime_user_engagement (_lte), 1358798
10.23.0 - [FirebaseAnalytics][I-ACS023087] User property set. Name, value: session_user_engagement (_se), 148272
10.23.0 - [FirebaseAnalytics][I-ACS012018] Saving bundle. size (bytes): 618
10.23.0 - [FirebaseAnalytics][I-ACS023116] Bundle added to the upload queue. BundleID, timestamp (ms): 72, 1716810447120
10.23.0 - [FirebaseAnalytics][I-ACS023039] Measurement data sent to network. Timestamp (ms), data: 1716810447493, <APMPBMeasurementBatch: 0x301148e30>
10.23.0 - [FirebaseAnalytics][I-ACS900000] Uploading data. Host: https://app-analytics-services.com/a
10.23.0 - [FirebaseAnalytics][I-ACS901006] Received SSL challenge for host. Host: https://app-analytics-services.com/a
10.23.0 - [FirebaseAnalytics][I-ACS023044] Successful upload. Got network response. Code, size: 204, 0
10.23.0 - [FirebaseAnalytics][I-ACS002002] Measurement timer scheduled to fire in approx. (s): 0.4625779390335083
10.23.0 - [FirebaseAnalytics][I-ACS002003] Measurement timer canceled
10.23.0 - [FirebaseAnalytics][I-ACS031010] Tracking view controller. Class, ID: CommonSettingsViewController, -2597384335633240837
10.23.0 - [FirebaseAnalytics][I-ACS002003] Engagement timer canceled
10.23.0 - [FirebaseAnalytics][I-ACS002002] Engagement timer scheduled to fire in approx. (s): 3600
10.23.0 - [FirebaseAnalytics][I-ACS023051] Logging event: origin, name, params: auto, user_engagement (_e), {
    engagement_time_msec (_et) = 3643;
    ga_event_origin (_o) = auto;
    ga_screen_class (_sc) = UIAlertController;
    ga_screen_id (_si) = -2597384335633240836;
}
10.23.0 - [FirebaseAnalytics][I-ACS023073] Debug mode is enabled. Marking event as debug and real-time. Event name, parameters: user_engagement (_e), {
    engagement_time_msec (_et) = 3643;
    ga_debug (_dbg) = 1;
    ga_event_origin (_o) = auto;
    ga_realtime (_r) = 1;
    ga_screen_class (_sc) = UIAlertController;
    ga_screen_id (_si) = -2597384335633240836;
}
10.23.0 - [FirebaseInstallations][I-FIS002000] -[FIRInstallationsIDController createGetInstallationItemPromise], appName: __FIRAPP_DEFAULT
10.23.0 - [FirebaseAnalytics][I-ACS023072] Event logged. Event name, event params: user_engagement (_e), {
    engagement_time_msec (_et) = 3643;
    ga_debug (_dbg) = 1;
    ga_event_origin (_o) = auto;
    ga_realtime (_r) = 1;
    ga_screen_class (_sc) = UIAlertController;
    ga_screen_id (_si) = -2597384335633240836;
}
10.23.0 - [FirebaseInstallations][I-FIS002001] -[FIRInstallationsIDController installationWithValidAuthTokenForcingRefresh:0], appName: __FIRAPP_DEFAULT
10.23.0 - [FirebaseMessaging][I-FCM041000] Unregister request to https://fcmtoken.googleapis.com/register content: X-osv=17.4.1&device=4699369092095926262&X-scope=*&plat=2&app=com.sesameware.smartyard.oem&app_ver=1.3.22&X-cliv=fiid-10.23.0&delete=true&iid-operation=delete&sender=*&appid=c9CSTTI2yUB9swqqlma-mM
10.23.0 - [FirebaseAnalytics][I-ACS002002] Measurement timer scheduled to fire in approx. (s): 0.9569069147109985
10.23.0 - [FirebaseAnalytics][I-ACS023051] Logging event: origin, name, params: auto, screen_view (_vs), {
    ga_event_origin (_o) = auto;
    ga_previous_class (_pc) = UIAlertController;
    ga_previous_id (_pi) = -2597384335633240836;
    ga_screen_class (_sc) = CommonSettingsViewController;
    ga_screen_id (_si) = -2597384335633240837;
}
10.23.0 - [FirebaseAnalytics][I-ACS023073] Debug mode is enabled. Marking event as debug and real-time. Event name, parameters: screen_view (_vs), {
    ga_debug (_dbg) = 1;
    ga_event_origin (_o) = auto;
    ga_previous_class (_pc) = UIAlertController;
    ga_previous_id (_pi) = -2597384335633240836;
    ga_realtime (_r) = 1;
    ga_screen_class (_sc) = CommonSettingsViewController;
    ga_screen_id (_si) = -2597384335633240837;
}
10.23.0 - [FirebaseAnalytics][I-ACS023072] Event logged. Event name, event params: screen_view (_vs), {
    ga_debug (_dbg) = 1;
    ga_event_origin (_o) = auto;
    ga_previous_class (_pc) = UIAlertController;
    ga_previous_id (_pi) = -2597384335633240836;
    ga_realtime (_r) = 1;
    ga_screen_class (_sc) = CommonSettingsViewController;
    ga_screen_id (_si) = -2597384335633240837;
}
request: url=https://rbt-demo.lanta.me/mobile/user/registerPushToken body={"type":3,"pushToken":"","production":"f","platform":"ios"} headers=Accept-Language: ru
Authorization: Bearer ed532f8c-кцукцкцукцу1b1-2149cbf0a8cd
Content-Type: application/json
response(204): <empty>
DEBUG: Push token successfully reset on backend
10.23.0 - [FirebaseMessaging][I-FCM028009] Deleted checkin plist file.
10.23.0 - [FirebaseMessaging][I-FCM027006] Checkin parameters: {
    checkin =     {
        iosbuild =         {
            model = "iPhone12,5";
            "os_version" = "IOS_17.4.1";
        };
        "last_checkin_msec" = 0;
        type = 2;
        "user_number" = 0;
    };
    digest = "";
    fragment = 0;
    id = 0;
    locale = "ru_RU";
    "security_token" = 0;
    "time_zone" = "Europe/Moscow";
    "user_serial_number" = 0;
    version = 2;
}
10.23.0 - [FirebaseMessaging][I-FCM027002] Invalid last checkin timestamp 2024-05-27 11:47:30 +0000 in future.
10.23.0 - [FirebaseMessaging][I-FCM027003] Checkin successful with authId: 5194954043714114015, digest: lREgEOmdi5Qb8UhzNdCklQ==, lastCheckinTimestamp: 1716810450000
10.23.0 - [FirebaseMessaging][I-FCM025004] Successfully got checkin credentials
10.23.0 - [FirebaseMessaging][I-FCM028010] Checkin plist file is saved
10.23.0 - [FirebaseMessaging][I-FCM043002] Couldn't delete item from Keychain OSStatus: -25300 with the keychain query {
    acct = "com.sesameware.smartyard.oem";
    class = genp;
    gena = "com.google.iid";
    nleg = 1;
    svce = "com.google.iid.checkin";
}
10.23.0 - [FirebaseInstallations][I-FIS002000] -[FIRInstallationsIDController createGetInstallationItemPromise], appName: __FIRAPP_DEFAULT
10.23.0 - [FirebaseInstallations][I-FIS002001] -[FIRInstallationsIDController installationWithValidAuthTokenForcingRefresh:0], appName: __FIRAPP_DEFAULT
10.23.0 - [FirebaseMessaging][I-FCM043000] Info is not found in Keychain. OSStatus: -25300. Keychain query: {
    acct = "com.sesameware.smartyard.oem";
    class = genp;
    gena = "com.google.iid-tokens";
    "m_Limit" = "m_LimitAll";
    nleg = 1;
    "r_Attributes" = 1;
    "r_Data" = 1;
    svce = "90696ку27830:*";
}
10.23.0 - [FirebaseMessaging][I-FCM034000] Fetch new token for authorizedEntity: 906еук827830, scope: *
10.23.0 - [FirebaseInstallations][I-FIS002001] -[FIRInstallationsIDController installationWithValidAuthTokenForcingRefresh:0], appName: __FIRAPP_DEFAULT
10.23.0 - [FirebaseInstallations][I-FIS002000] -[FIRInstallationsIDController createGetInstallationItemPromise], appName: __FIRAPP_DEFAULT
10.23.0 - [FirebaseMessaging][I-FCM040000] Register request to https://fcmtoken.googleapis.com/register content: X-osv=17.4.1&device=5194954043714114015&X-scope=*&plat=2&app=com.sesameware.smartyard.oem&app_ver=1.3.22&X-cliv=fiid-10.23.0&sender=906963827830&X-subtype=906963827830&appid=c9CSTTI2yUB9swqqlma-mM&apns_token=s_b72c5b9bb8b9c82c6446107839e62491421aad5041021af03c4ffcb922d433b6&gmp_app_id=1:906963827830:ios:9cfef38c8a8c3dbdeb3357
10.23.0 - [FirebaseAnalytics][I-ACS002001] Measurement timer fired
10.23.0 - [FirebaseAnalytics][I-ACS002003] Measurement timer canceled
10.23.0 - [FirebaseAnalytics][I-ACS023105] Event is not subject to real-time event count daily limit. Marking an event as real-time. Event name, parameters: user_engagement (_e), {
    engagement_time_msec (_et) = 3643;
    ga_debug (_dbg) = 1;
    ga_event_origin (_o) = auto;
    ga_realtime (_r) = 1;
    ga_screen_class (_sc) = UIAlertController;
    ga_screen_id (_si) = -2597384335633240836;
}
10.23.0 - [FirebaseAnalytics][I-ACS023105] Event is not subject to real-time event count daily limit. Marking an event as real-time. Event name, parameters: screen_view (_vs), {
    ga_debug (_dbg) = 1;
    ga_event_origin (_o) = auto;
    ga_previous_class (_pc) = UIAlertController;
    ga_previous_id (_pi) = -2597384335633240836;
    ga_realtime (_r) = 1;
    ga_screen_class (_sc) = CommonSettingsViewController;
    ga_screen_id (_si) = -2597384335633240837;
}
10.23.0 - [FirebaseAnalytics][I-ACS023087] User property set. Name, value: lifetime_user_engagement (_lte), 1362441
10.23.0 - [FirebaseAnalytics][I-ACS023087] User property set. Name, value: session_user_engagement (_se), 151915
10.23.0 - [FirebaseAnalytics][I-ACS012018] Saving bundle. size (bytes): 577
10.23.0 - [FirebaseAnalytics][I-ACS023116] Bundle added to the upload queue. BundleID, timestamp (ms): 73, 1716810450113
10.23.0 - [FirebaseAnalytics][I-ACS023039] Measurement data sent to network. Timestamp (ms), data: 1716810451190, <APMPBMeasurementBatch: 0x30117bd30>
10.23.0 - [FirebaseAnalytics][I-ACS900000] Uploading data. Host: https://app-analytics-services.com/a
10.23.0 - [FirebaseAnalytics][I-ACS901006] Received SSL challenge for host. Host: https://app-analytics-services.com/a
10.23.0 - [FirebaseAnalytics][I-ACS023044] Successful upload. Got network response. Code, size: 204, 0
10.23.0 - [FirebaseAnalytics][I-ACS002002] Measurement timer scheduled to fire in approx. (s): -0.2511540651321411
10.23.0 - [FirebaseAnalytics][I-ACS002003] Measurement timer canceled
DEBUG / PUSH NOTIFICATIONS / Firebase registration token: Optional("c9CSTTI2yUB9swqqlma-mM:APA91bHklOzDFka1_EHf5Alu3IBniI0tt_hJGWAfsdfyYphrgjHGCbFsdfsMpXbFaGeaVCOwKeameiqP")
DEBUG / REGISTER WITH VOIP TOKEN nil
10.23.0 - [FirebaseMessaging][I-FCM043002] Couldn't delete item from Keychain OSStatus: -25300 with the keychain query {
    acct = "com.sesameware.smartyard.oem";
    class = genp;
    gena = "com.google.iid-tokens";
    nleg = 1;
    svce = "906963827830:*";
}
10.23.0 - [FirebaseMessaging][I-FCM034001] Token fetch successful, token: c9CSTTI2yUB9swqqlma-mM:APA91bHklOzDFka1_fsdt_hJGWAKlSFzYu_9a9SKBPzc2zeHdBjGZCi8qFlxjbYM3SMLMEXTLE2HH3NwOjyYphrgjHGCbFhNfS9mGdA0I3oMpXbFaGeaVCOwKeameiqP, authorizedEntity: 90fsdf27830, scope:*
request: url=https://sdfsdme/providers.json?_=966fsdfers=
response(200): yes
response(204): <empty>
DEBUG: Successfully subscribed to push notifications
10.23.0 - [FirebaseAnalytics][I-ACS031010] Tracking view controller. Class, ID: SelectProviderViewController, -2597384335633240835
10.23.0 - [FirebaseAnalytics][I-ACS002003] Engagement timer canceled

If using Swift Package Manager, the project's Package.resolved

Expand Package.resolved snippet
```json Replace this line with the contents of your Package.resolved. ```

If using CocoaPods, the project's Podfile.lock

google-oss-bot commented 2 months ago

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

chekmari commented 2 months ago

What I'm experiencing is the following

after logout I delete the token on my server (register a push token with empty value) Then I apply the deleteData method.

In didReceiveRegistrationToken method updateFCMToken() is triggered in which Messaging.messaging().fcmToken is not deleted. Why?

func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
    print("DEBUG / PUSH NOTIFICATIONS / Firebase registration token: \(String(describing: fcmToken))")

    appCoordinator.updateFCMToken()
}

updateFCMToken() {
 /// Подписка на уведомления. Если прокинуты оба токена, звонки будут идти через VoIP пуши
        registerForPushNotifications(voipToken: String?) -> Single<Void?> {
            guard let fcmToken = Messaging.messaging().fcmToken else {
             return .error(NSError.PushNotificationServiceError.fcmTokenMissing)
           }

    print("DEBUG / REGISTER WITH VOIP TOKEN \(String(describing: voipToken))")

    return apiWrapper.registerPushToken(
        pushToken: fcmToken,
        voipToken: voipToken,
        clientId: nil,
        type: .fcmRepeating
    )
}

}

chekmari commented 2 months ago

AutoInitEnabled set to false FCM registration token successfully deleted AutoInitEnabled set to false FCM registration token: xxxxxxxxzeHdBjGZCi8qFlxjbYM3SxxxxphrgjHGCbFhNfS9mGxxxKeameiqP FCM registration token after logout: xxxxxxxxzeHdBjGZCi8qFlxjbYM3SxxxxphrgjHGCbFhNfS9mGxxxKeameiqP

rizafran commented 1 month ago

Thanks for waiting, @chekmari. I tried to reproduce the issue, and looks like I was able to encounter the same behavior. To make sure that we're on the same page, could you confirm if the didReceiveRegistrationToken method was being called and fcmToken has a value even after triggering the Messaging.messaging().deleteData?

google-oss-bot commented 1 month ago

Hey @chekmari. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot commented 1 month ago

Since there haven't been any recent updates here, I am going to close this issue.

@chekmari if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.