firebase / flutterfire

🔥 A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.58k stars 3.94k forks source link

[firebase_messaging]: After turning off the device and turn back on, onBackgroundMessage is not fired on iOS. #13073

Open ViniciusSossela opened 1 month ago

ViniciusSossela commented 1 month ago

Is there an existing issue for this?

Are you aware of the differences between iOS and Android background message handling?

Do you have an active Apple Developer account?

Are you using a physical iOS device to test background messages?

Have you enabled "Remote Notifications" & "Background Mode" (Checking options for "Background Processing" & "Remote Notifications") in your app's Xcode project?

Screenshot 2024-07-16 at 08 47 07

Have you created an APNs key in your Apple Developer account & uploaded this APNs key to your Firebase console?

Screenshot 2024-07-16 at 08 48 37

Have you disabled method swizzling for Firebase in your app?

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CADisableMinimumFrameDurationOnPhone</key>
    <true/>
    <key>CFBundleDevelopmentRegion</key>
    <string>$(DEVELOPMENT_LANGUAGE)</string>
    <key>CFBundleExecutable</key>
    <string>$(EXECUTABLE_NAME)</string>
    <key>CFBundleIdentifier</key>
    <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>XXXXXX</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>$(FLUTTER_BUILD_NAME)</string>
    <key>CFBundleSignature</key>
    <string>????</string>
    <key>CFBundleVersion</key>
    <string>$(FLUTTER_BUILD_NUMBER)</string>
    <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>sms</string>
        <string>tel</string>
        <string>https</string>
        <string>whatsapp</string>
        <string>instagram</string>
        <string>instagram-stories</string>
        <string>comgooglemaps</string>
        <string>baidumap</string>
        <string>iosamap</string>
        <string>waze</string>
        <string>yandexmaps</string>
        <string>yandexnavi</string>
        <string>citymapper</string>
        <string>mapswithme</string>
        <string>osmandmaps</string>
        <string>dgis</string>
        <string>qqmap</string>
        <string>here-location</string>
        <string>tomtomgo</string>
        <string>copilot</string>
        <string>com.sygic.aura</string>
        <string>nmap</string>
        <string>kakaomap</string>
        <string>tmap</string>
        <string>szn-mapy</string>
    </array>
    <key>LSRequiresIPhoneOS</key>
    <true/>
    <key>NSCameraUsageDescription</key>
    <string>We ask for camera permission because when you send a new promotion you can then take a picture using the camera.</string>
    <key>NSLocationWhenInUseUsageDescription</key>
    <string>This app needs access to location to shows local offers.</string>
    <key>NSPhotoLibraryUsageDescription</key>
    <string>We ask for photo library permission because when you send a new promotion you can then choose a picture from your gallery.</string>
    <key>UIApplicationSupportsIndirectInputEvents</key>
    <true/>
    <key>UIBackgroundModes</key>
    <array>
        <string>fetch</string>
        <string>processing</string>
        <string>remote-notification</string>
    </array>
    <key>UILaunchStoryboardName</key>
    <string>LaunchScreen</string>
    <key>UIMainStoryboardFile</key>
    <string>Main</string>
    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    <key>UISupportedInterfaceOrientations~ipad</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationPortraitUpsideDown</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    <key>UIViewControllerBasedStatusBarAppearance</key>
    <false/>
    <key>io.flutter.embedded_views_preview</key>
    <true/>
    <key>BGTaskSchedulerPermittedIdentifiers</key>
    <array>
        <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
    </array>
</dict>
</plist>

Are you sending messages to your app from the Firebase Admin SDK?

let message_filters = &message.filters;

let mut req = SendMessageRequest::default();
let mut android_config = AndroidConfig::default();
android_config.priority = Some(String::from("high"));

let mut apn_config = ApnsConfig::default();
apn_config.headers = Some(HashMap::from([(
    String::from("apns-priority"),
    String::from("10"),
)]));

apn_config.payload = Some(HashMap::from([(
    String::from("aps"),
    json!({
        "content-available": 1
    }),
)]));

req.message = Some(Message {
    android: Some(android_config),
    apns: Some(apn_config),
    condition: None,
    data: if message_data.is_empty() {
        None
    } else {
        Some(message_data)
    },
    fcm_options: None,
    name: None,
    notification: Some(Notification {
        body: Some(message.body.to_string()),
        image: None,
        title: Some(message.title.to_string()),
    }),
    /// Registration token to send a message to.
    token: if token.is_none() {
        None
    } else {
        Some(token.unwrap())
    },
    topic: if message_filters.is_empty() {
        Some(to_all)
    } else {
        None
    },
    webpush: None,
});
req

the same happens with nodejs sample, no difference

Have you requested permission from the user to receive notifications?

Have you used the 'Console' application on your macOS device to check if the iOS device's system is throttling your background messages?

default 09:07:43.194138-0300 SpringBoard Received incoming message on topic com.kodefy.sander at priority 5 default 09:07:43.226125-0300 SpringBoard [com.kodefy.sander] Received remote notification request C1A9-F481 [ waking: 0, hasAlertContent: 1, hasSound: 0 hasBadge: 0 hasContentAvailable: 1 hasMutableContent: 0 pushType: Alert] default 09:07:43.226176-0300 SpringBoard [com.kodefy.sander] Process delivery of push notification C1A9-F481 default 09:07:43.226233-0300 SpringBoard [com.kodefy.sander] Request DUET delivers content-available push notification to application default 09:07:43.226351-0300 SpringBoard SUBMITTING: com.apple.pushLaunch.com.kodefy.sander:DA4CB9 default 09:07:43.226629-0300 dasd Submitted Activity: com.apple.pushLaunch.com.kodefy.sander:DA4CB9 at priority 5 default 09:07:43.226768-0300 SpringBoard [com.kodefy.sander] Badge can be set for notification C1A9-F481: 0 [ canBadge: 1 badgeNumber: (null) ] default 09:07:43.226821-0300 SpringBoard Getting effectiveSectionInfo for section identifier: com.kodefy.sander default 09:07:43.226866-0300 SpringBoard [com.kodefy.sander] Getting effective section info default 09:07:43.228013-0300 SpringBoard [com.kodefy.sander] Got effective section info [ hasResult: 1 ] default 09:07:43.228142-0300 SpringBoard Getting effectiveSectionInfo for section identifier: com.kodefy.sander default 09:07:43.228177-0300 SpringBoard [com.kodefy.sander] Getting effective section info default 09:07:43.229456-0300 SpringBoard [com.kodefy.sander] Got effective section info [ hasResult: 1 ] default 09:07:43.229665-0300 SpringBoard [com.kodefy.sander] Saving notification C1A9-F481: YES [ hasAlertContent: YES, shouldPresentAlert: YES settingsShouldSave: YES] default 09:07:43.230329-0300 dasd Daemon Canceling Activities: {( com.apple.pushLaunch.com.kodefy.sander:C7CD10 )} default 09:07:43.230355-0300 dasd CANCELED: com.apple.pushLaunch.com.kodefy.sander:C7CD10 at priority 5 ! default 09:07:43.231193-0300 dasd com.apple.pushLaunch.com.kodefy.sander:DA4CB9:[ {name: ApplicationPolicy, policyWeight: 50.000, response: {Decision: Absolutely Must Not Proceed, Score: 0.00, Rationale: [{[pushDisallowed]: Required:0.00, Observed:1.00},]}} {name: ThunderingHerdPolicy, policyWeight: 1.000, response: {Decision: Must Not Proceed, Score: 0.00, Rationale: [{timeSinceThunderingHerdTriggerEvent < 300}]}} ], FinalDecision: Absolutely Must Not Proceed} default 09:07:43.231640-0300 SpringBoard [com.kodefy.sander] Delivered user visible push notification C1A9-F481 default 09:07:43.234946-0300 SpringBoard [com.kodefy.sander] Load 0 pending notification dictionaries default 09:07:43.235404-0300 SpringBoard [com.kodefy.sander] Adding notification C1A9-F481 [ hasAlertContent: 1, shouldPresentAlert: 1 hasSound: 0 shouldPlaySound: 1 ]; interruption-level: 1; destinations 398: ( NotificationCenter, LockScreen, Alert, Spoken, Forwarding ) default 09:07:43.236198-0300 SpringBoard BBDataProviderProxy com.kodefy.sander has enqueued a bulletin request default 09:07:43.236313-0300 SpringBoard BBDataProviderProxy com.kodefy.sander is now sending enqueued bulletin request to BBServer default 09:07:43.239384-0300 SpringBoard Publishing bulletin for section : subsectionIDs: (null), bulletinID = <97DACCD9-9094-4203-A5B6-EE64E920C6F5>, expiration date = <Tue Jul 23 09:07:42 2024>, expiration events <0> default 09:07:43.257658-0300 SpringBoard NCBulletinNotificationSource adding bulletin C1A9-F481 for feed 3115 in section com.kodefy.sander default 09:07:43.302423-0300 SpringBoard [com.apple.springboard.NCBulletinNotificationSource:D3C7A248-4070-4CE7-8007-CB3BCE6F845D] Resolving behavior for event, details=<DNDMutableClientEventDetails: 0x28138cfa0; identifier: 'DC366AE6-340B-4C71-BC50-DB5DCC37D472'; bundleIdentifier:: com.kodefy.sander; type: Default; urgency: Default; sender: (null); threadIdentifier: 490F3CCE53B11F24; notifyAnyway: 0; behavior: Default> default 09:07:43.302711-0300 SpringBoard [com.apple.springboard.NCBulletinNotificationSource:D3C7A248-4070-4CE7-8007-CB3BCE6F845D] Resolved event, details=<DNDMutableClientEventDetails: 0x28138cfa0; identifier: 'DC366AE6-340B-4C71-BC50-DB5DCC37D472'; bundleIdentifier:: com.kodefy.sander; type: Default; urgency: Default; sender: (null); threadIdentifier: 490F3CCE53B11F24; notifyAnyway: 0; behavior: Default> behavior=<DNDClientEventBehavior: 0x283c2e190; eventDetails: <DNDClientEventDetails: 0x28138da90; identifier: 'DC366AE6-340B-4C71-BC50-DB5DCC37D472'; bundleIdentifier:: com.kodefy.sander; type: Default; urgency: Default; sender: (null); threadIdentifier: 490F3CCE53B11F24; notifyAnyway: 0; behavior: Default>; interruptionSuppression: none; resolutionReason: disabled; activeModeUUID: (null)> default 09:07:43.302799-0300 SpringBoard Posting notification id: C1A9-F481; section: com.kodefy.sander; thread: 4445-05A9; category: ; timestamp: 2024-07-16 12:07:42 +0000; interruption-level: active; relevance-score: 0.00; actions: [ minimal: 0 (0 text), default: 0 (0 text) ]; destinations: [ {( BulletinDestinationCoverSheet, BulletinDestinationBanner, BulletinDestinationNotificationCenter, BulletinDestinationLockScreen )} ] default 09:07:43.303284-0300 SpringBoard Incoming Section [NCNotificationStructuredSectionList] inserting notification request C1A9-F481 in new group Group List [com.kodefy.sander:4445-05A9] default 09:07:43.303303-0300 SpringBoard Group List [com.kodefy.sander:4445-05A9] inserting notification request C1A9-F481 at index 0 default 09:07:43.304418-0300 donotdisturbd Event was resolved: resolution=<DNDSEventBehaviorResolution: 0x102450bb0; UUID: 2B744D5D-EFA4-4D93-8F41-A156F5DF6062; date: 2024-07-16 12:07:43 +0000; eventBehavior: <DNDClientEventBehavior: 0x10244ec60; eventDetails: <DNDClientEventDetails: 0x102456cc0; identifier: 'DC366AE6-340B-4C71-BC50-DB5DCC37D472'; bundleIdentifier:: com.kodefy.sander; type: Default; urgency: Default; sender: (null); threadIdentifier: 490F3CCE53B11F24; notifyAnyway: 0; behavior: Default>; interruptionSuppression: none; resolutionReason: disabled; activeModeUUID: (null)>; clientIdentifier: 'com.apple.springboard.NCBulletinNotificationSource'; outcome: allowed; reason: disabled> default 09:07:59.787452-0300 dasd com.apple.pushLaunch.com.kodefy.sander:DA4CB9:[ {name: ApplicationPolicy, policyWeight: 50.000, response: {Decision: Absolutely Must Not Proceed, Score: 0.00, Rationale: [{[pushDisallowed]: Required:0.00, Observed:1.00},]}} {name: ThunderingHerdPolicy, policyWeight: 1.000, response: {Decision: Must Not Proceed, Score: 0.00, Rationale: [{timeSinceThunderingHerdTriggerEvent < 300}]}} ], FinalDecision: Absolutely Must Not Proceed} default 09:08:10.765731-0300 dasd com.apple.pushLaunch.com.kodefy.sander:DA4CB9:[ {name: ApplicationPolicy, policyWeight: 50.000, response: {Decision: Absolutely Must Not Proceed, Score: 0.00, Rationale: [{[pushDisallowed]: Required:0.00, Observed:1.00},]}} {name: ThunderingHerdPolicy, policyWeight: 1.000, response: {Decision: Must Not Proceed, Score: 0.00, Rationale: [{deviceInUse == 1 AND timeSinceThunderingHerdTriggerEvent < 900}]}} ], FinalDecision: Absolutely Must Not Proceed} default 09:08:16.695473-0300 dasd com.apple.pushLaunch.com.kodefy.sander:DA4CB9:[ {name: ApplicationPolicy, policyWeight: 50.000, response: {Decision: Absolutely Must Not Proceed, Score: 0.00, Rationale: [{[pushDisallowed]: Required:0.00, Observed:1.00},]}} {name: ThunderingHerdPolicy, policyWeight: 1.000, response: {Decision: Must Not Proceed, Score: 0.00, Rationale: [{deviceInUse == 1 AND timeSinceThunderingHerdTriggerEvent < 900}]}} ], FinalDecision: Absolutely Must Not Proceed} default 09:08:38.009325-0300 dasd com.apple.pushLaunch.com.kodefy.sander:DA4CB9:[ {name: ApplicationPolicy, policyWeight: 50.000, response: {Decision: Absolutely Must Not Proceed, Score: 0.00, Rationale: [{[pushDisallowed]: Required:0.00, Observed:1.00},]}} {name: ThunderingHerdPolicy, policyWeight: 1.000, response: {Decision: Must Not Proceed, Score: 0.00, Rationale: [{deviceInUse == 1 AND timeSinceThunderingHerdTriggerEvent < 900}]}} ], FinalDecision: Absolutely Must Not Proceed} default 09:09:17.498073-0300 dasd com.apple.pushLaunch.com.kodefy.sander:DA4CB9:[ {name: ApplicationPolicy, policyWeight: 50.000, response: {Decision: Absolutely Must Not Proceed, Score: 0.00, Rationale: [{[pushDisallowed]: Required:0.00, Observed:1.00},]}} {name: ThunderingHerdPolicy, policyWeight: 1.000, response: {Decision: Must Not Proceed, Score: 0.00, Rationale: [{deviceInUse == 1 AND timeSinceThunderingHerdTriggerEvent < 900}]}} ], FinalDecision: Absolutely Must Not Proceed} default 09:10:05.097733-0300 runningboardd Acquiring assertion targeting application from originator [daemon:94] with description <RBSAssertionDescriptor| "DAS DYLD3 Closure Generation" ID:33-94-193 target:application attributes:[ <RBSDomainAttribute| domain:"com.apple.dasd" name:"DYLDLaunch" sourceEnvironment:"(null)"> ]> default 09:10:05.097891-0300 runningboardd Assertion 33-94-193 (target:application) will be created as active default 09:10:05.099044-0300 runningboardd [application:265] Resuming task. default 09:10:05.099205-0300 runningboardd [application:265] Set darwin role to: Background default 09:10:05.099451-0300 runningboardd Calculated state for application: running-active (role: Background) default 09:10:05.101737-0300 mediaserverd -CMSessionMgr- CMSessionMgrHandleApplicationStateChange: Client com.kodefy.sander with pid '265' is now Background Running. Background entitlement: NO ActiveLongFormVideoSession: NO WhitelistedLongFormVideoApp NO default 09:10:05.101969-0300 mediaserverd -CMSessionMgr- CMSessionMgrHandleApplicationStateChange: Sending stop command to com.kodefy.sander with pid '265' because client is not allowed to play in the background AND does not continue AirPlaying video when device locks default 09:10:05.120573-0300 runningboardd Executing launch request for application (DAS DYLD3 Closure Generation) default 09:10:05.123379-0300 runningboardd Acquiring assertion targeting application from originator [daemon:94] with description <RBSAssertionDescriptor| "DAS DYLD3 Closure Generation" ID:33-94-194 target:application attributes:[ <RBSDomainAttribute| domain:"com.apple.dasd" name:"DYLDLaunch" sourceEnvironment:"(null)"> ]> default 09:10:05.123645-0300 runningboardd Assertion 33-94-194 (target:application) will be created as active default 09:10:05.124802-0300 runningboardd Executing launch request for application (DAS DYLD3 Closure Generation) default 09:10:05.127497-0300 runningboardd Invalidating assertion 33-94-193 (target:application) from originator [daemon:94] default 09:10:05.128170-0300 runningboardd Acquiring assertion targeting application from originator [daemon:94] with description <RBSAssertionDescriptor| "DAS DYLD3 Closure Generation" ID:33-94-195 target:application attributes:[ <RBSDomainAttribute| domain:"com.apple.dasd" name:"DYLDLaunch" sourceEnvironment:"(null)"> ]> default 09:10:05.128354-0300 runningboardd Assertion 33-94-195 (target:application) will be created as active default 09:10:05.130220-0300 runningboardd Executing launch request for application (DAS DYLD3 Closure Generation) default 09:10:05.132958-0300 runningboardd Invalidating assertion 33-94-194 (target:application) from originator [daemon:94] default 09:10:06.009639-0300 runningboardd Invalidating assertion 33-94-195 (target:application) from originator [daemon:94] default 09:10:06.010144-0300 runningboardd Removed last relative-start-date-defining assertion for process application default 09:10:06.025808-0300 runningboardd [application:265] Suspending task. default 09:10:06.026129-0300 runningboardd [application:265] Shutdown sockets (SVC) default 09:10:06.026333-0300 runningboardd [application:265] Set darwin role to: None default 09:10:06.029445-0300 runningboardd Calculated state for application: running-suspended (role: None) default 09:10:06.029814-0300 runningboardd [application:265] check if suspended process is holding locks default 09:10:06.038036-0300 mediaserverd -CMSessionMgr- CMSessionMgrHandleApplicationStateChange: Client com.kodefy.sander with pid '265' is now Background Suspended. Background entitlement: NO ActiveLongFormVideoSession: NO WhitelistedLongFormVideoApp NO default 09:10:06.038073-0300 mediaserverd -CMSessionMgr- CMSessionMgrHandleApplicationStateChange: Sending stop command to com.kodefy.sander with pid '265' because client is background suspended and there is no AirPlay video session for it default 09:10:48.006253-0300 dasd com.apple.pushLaunch.com.kodefy.sander:DA4CB9:[ {name: ApplicationPolicy, policyWeight: 50.000, response: {Decision: Absolutely Must Not Proceed, Score: 0.00, Rationale: [{[pushDisallowed]: Required:0.00, Observed:1.00},]}} ], FinalDecision: Absolutely Must Not Proceed} default 09:11:30.261775-0300 dasd com.apple.pushLaunch.com.kodefy.sander:DA4CB9:[ {name: ApplicationPolicy, policyWeight: 50.000, response: {Decision: Absolutely Must Not Proceed, Score: 0.00, Rationale: [{[pushDisallowed]: Required:0.00, Observed:1.00},]}} ], FinalDecision: Absolutely Must Not Proceed} default 09:11:46.821629-0300 dasd com.apple.pushLaunch.com.kodefy.sander:DA4CB9:[ {name: ApplicationPolicy, policyWeight: 50.000, response: {Decision: Absolutely Must Not Proceed, Score: 0.00, Rationale: [{[pushDisallowed]: Required:0.00, Observed:1.00},]}} ], FinalDecision: Absolutely Must Not Proceed}

Additional context and comments

Steps: 1 - Turn off the iPhone real device 2 - Turn on the iPhone device (DO NOT OPEN YOUR APP) 3 - Send a push notification The DEVICE will receive the notification, but the APP will not. onBackgroundMessage is not fired on this situation

(After turning on the device and opening the APP at least once, it starts to fire the onBackgroundMessage handler). In other words, -->EVERY TIME<-- the device is turned off and on, the APP must be opened at least once, to start to fire onBackgroundMessage ?

Lyokone commented 1 month ago

Hello, thanks for the detailed issue, are you using a production version of your app. Meaning something from Testflight or AppStore

ViniciusSossela commented 1 month ago

Hello, thanks for the detailed issue, are you using a production version of your app. Meaning something from Testflight or AppStore

Hi, thanks for getting back. Yes, it's a production version

ViniciusSossela commented 1 month ago

Any news on this?

ViniciusSossela commented 1 month ago

@russellwheatley any idea on this? Please let me know if it also happens in our test/demo?