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.44k stars 3.91k forks source link

[firebase_messaging]: iOS Background receive Message #12741

Closed hann-yun closed 2 days ago

hann-yun commented 2 weeks 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-05-03 at 4 58 34β€―PM

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

Screenshot 2024-05-03 at 5 03 55β€―PM

Have you disabled method swizzling for Firebase in your app?

image

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

package main

import (
    "context"
    "log"
    "path/filepath"

    firebase "firebase.google.com/go"
    "firebase.google.com/go/messaging"
    "google.golang.org/api/option"
)

func main() {
    ctx := context.Background()

    serviceAccountKeyFilePath, err := filepath.Abs("./key.json")
    // serviceAccountKeyFilePath, err := filepath.Abs("./test_key.json")
    if err != nil {
        panic("Unable to load serviceAccountKeys.json file")
    }

    opt := option.WithCredentialsFile(serviceAccountKeyFilePath)

    //Firebase admin SDK initialization
    app, err := firebase.NewApp(context.Background(), nil, opt)
    if err != nil {
        panic("Firebase load error")
    }

    message := &messaging.Message{
                Data: map[string]string{
            "title": "TEstNOTIF",
            "body":  "PLEASE!!",
            "data":  time.Now().GoString(),
        },
        Android: &messaging.AndroidConfig{
            Priority: "high",
        },
        APNS: &messaging.APNSConfig{
            Payload: &messaging.APNSPayload{
                Aps: &messaging.Aps{
                    ContentAvailable: true,
                },
            },
        },
        Token: "testToken",
    }
    //Messaging client
    client, _ := app.Messaging(ctx)
    res, err := client.Send(ctx, message)
    if err != nil {
        log.Fatal(res, err)
    }

}

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 17:34:51.455483+0900    SpringBoard Received incoming message on topic com.******.******.v2.dev at priority 5
default 17:34:51.467351+0900    SpringBoard [com.******.******.v2.dev] Received remote notification request 7A2D-1E36 [ waking: 0, hasAlertContent: 0, hasSound: 0 hasBadge: 0 hasContentAvailable: 1 hasMutableContent: 0 pushType: Background]
default 17:34:51.467674+0900    SpringBoard [com.******.******.v2.dev] Process delivery of push notification 7A2D-1E36
default 17:34:51.467915+0900    SpringBoard [com.******.******.v2.dev] Request DUET delivers content-available push notification to application
default 17:34:51.468139+0900    SpringBoard SUBMITTING: com.apple.pushLaunch.com.******.******.v2.dev:5ACA10
default 17:34:51.468465+0900    dasd    Submitted Activity: com.apple.pushLaunch.com.******.******.v2.dev:5ACA10 at priority 5 (Fri May  3 01:34:51 2024 - Sat May  4 01:34:51 2024)
default 17:34:54.840265+0900    locationd   {"msg":"#CLIUA Marking change", "clientKey":"icom.******.******.v2.dev:", "reason":"Decaying in-use status from process state", "assertionLevel":3, "coming":0}
default 17:34:54.840871+0900    locationd   {"msg":"#CLIUA updating AssertionRecord", "ClientKey":"icom.******.******.v2.dev:", "AssertionLevel":{"type":"decode failure","raw value":3,"expected type":"Generic"}}
default 17:34:54.841480+0900    locationd   {"msg":"#CLIUA AssertionRecord updated", "ClientKey":"icom.******.******.v2.dev:", "AssertionLevel":{"type":"decode failure","raw value":0,"expected type":"Generic"}}
default 17:34:54.841964+0900    locationd   {"msg":"#CLIUA in-use level changed for client", "ClientKey":"icom.******.******.v2.dev:"}
default 17:34:54.842495+0900    locationd   location disabled system-wide, denying executable icom.******.******.v2.dev:
default 17:34:54.843434+0900    locationd   {"msg":"computing freshAuthorizationContext", "Client":"icom.******.******.v2.dev:", "ClientDictionary":"{\n    BundleId = \"com.******.******.v2.dev\";\n    BundlePath = \"\/private\/var\/containers\/Bundle\/Application\/E2AF6B4D-6567-47ED-9989-440AFF0869E8\/Runner.app\";\n    Executable = \"\/private\/var\/containers\/Bundle\/Application\/E2AF6B4D-6567-47ED-9989-440AFF0869E8\/Runner.app\/Runner\";\n    ExistsInLSDatabase = 1;\n    InUseLevel = 0;\n    PluginBundleIds =     (\n    );\n    SuppressShowingInSettings = 1;\n}", "BigSwitch":0, "InUseLevel":{"type":"decode failure","raw value":0,"expected type":"Generic"}}
default 17:34:54.843969+0900    locationd   location disabled system-wide, denying executable icom.******.******.v2.dev:
error   17:35:06.950067+0900    symptomsd   COSMCtrl applyPolicyDelta unexpected absence of policy on appRecord com.******.******.v2.dev bg time + grace 2024-05-03 01:38:36.308 -0700  now 2024-05-03 01:35:06.948 -0700
error   17:35:06.951333+0900    symptomsd   COSMCtrl applyPolicyDelta unexpected absence of policy on appRecord com.******.******.v2.dev bg time + grace 2024-05-03 01:39:44.845 -0700  now 2024-05-03 01:35:06.948 -0700

Additional context and comments

I'm using Fcm to voip feature iOS and AOS both. in iOS follow this step happen bug. In foreground push , received well. => background (app still alive) push, received well. => terminated (app dead) push, sometime not received. => open app just received that background message. => go background again (app alive) push, not received. after this step background & terminated push not received.

but i chekcted console.app still received. but swift & dart not recieved any data. and after a few minute received again..

this bug just hannepend in

  firebase_core: ^2.30.1
  firebase_messaging: ^14.9.1
  firebase_analytics: ^10.10.1
  firebase_crashlytics: ^3.5.1

this version.

and i tested under version works well..

  # firebase_core: 2.21.0
  # firebase_analytics: ^10.6.3
  # firebase_crashlytics: ^3.4.3
  # firebase_messaging: 14.7.3

additional Data -- Fluter doctor

Doctor summary (to see all details, run flutter doctor -v):
[βœ“] Flutter (Channel stable, 3.19.6, on macOS 14.4.1 23E224 darwin-arm64 (Rosetta), locale en-KR)
[βœ“] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[βœ“] Xcode - develop for iOS and macOS (Xcode 15.3)
[βœ“] Chrome - develop for the web
[βœ“] Android Studio (version 2023.2)
[βœ“] VS Code (version 1.88.1)
[βœ“] Connected device (3 available)
    ! Error: Browsing on the local area network for λž­λ””κ°œλ°œνŒ€μ˜ iPhone. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code -27)
[βœ“] Network resources

β€’ No issues found

-- pod version 1.15.2

-- used dependencies

dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter

  i18next: ^0.7.2

  intl: ^0.18.1
  provider: ^6.1.2
  shared_preferences: ^2.2.2
  dio: ^5.3.3
  logger: ^2.0.2+1
  sentry_flutter: ^7.12.0
  xml: ^6.3.0
  kakao_flutter_sdk: ^1.6.1
  kakao_flutter_sdk_talk: ^1.6.1
  web_socket_channel: ^2.4.0
  flutter_inappwebview: ^6.0.0

  firebase_core: ^2.30.1
  firebase_messaging: ^14.9.1
  firebase_analytics: ^10.10.1
  firebase_crashlytics: ^3.5.1

  # firebase_core: 2.21.0
  # firebase_analytics: ^10.6.3
  # firebase_crashlytics: ^3.4.3
  # firebase_messaging: 14.7.3

  flutter_local_notifications: ^16.1.0
  device_info_plus: ^9.1.1
  package_info_plus: ^4.2.0
  flutter_svg: ^2.0.9
  permission_handler: ^11.2.0
  url_launcher: ^6.2.1
  fluttertoast: ^8.2.3
  image_picker: ^1.0.4
  flutter_foreground_task: ^6.1.2
  flutter_volume_controller: ^1.3.1

  flutter_native_splash: ^2.3.5
  cached_network_image: ^3.3.0
  carousel_slider: ^4.2.1
  flutter_markdown: ^0.6.18+2
  table_calendar: ^3.0.9
  flutter_timezone: ^1.0.8
  just_audio: ^0.9.35
  sound_mode: ^2.0.2
  headset_connection_event: ^3.1.0

  grouped_list: ^5.1.2
  youtube_player_flutter: ^9.0.0-beta.0
  flutter_widget_from_html_core: ^0.14.6
  cached_video_player: ^2.0.4
  lottie: ^2.7.0
  flutter_udid: ^3.0.0

  crypto: ^3.0.3
  tencent_trtc_cloud: ^2.7.6
  replay_kit_launcher: ^1.0.0
  audio_session: ^0.1.18

  equatable:
  flutter_tts: ^3.8.5
  expandable_page_view: ^1.0.17
  fpdart:
  pull_to_refresh: ^2.0.0

  iamport_flutter: ^0.10.15
  uni_links: ^0.5.1
  http:
  path:
  path_provider:

  custom_pop_up_menu: ^1.2.4

flutter_callkit_incoming: ^2.0.3

  keep_screen_on: ^3.0.0
  uuid: ^4.3.3

  hive_flutter:
  localstorage: ^4.0.0+1

thank you.

russellwheatley commented 1 week ago

Hi @hann-yun - we're going to need more logs from the console app to diagnose. That is a small snippet which doesn't show if the notifications were being allowed/disallowed. Thanks.

hann-yun commented 2 days ago

I just changed to apns. works well. thanks!