urbanairship / airship-flutter

Flutter integration
Other
17 stars 17 forks source link

iOS push messages in foreground not working #178

Closed mcs-nuuk closed 1 year ago

mcs-nuuk commented 1 year ago

Preliminary Info

What Airship dependencies are you using?

We have implemented version 7.0.0 of the Airship Flutter plugin.

Report

What unexpected behavior are you seeing?

On iOS devices, notifications work as expected when the app is in background but in foreground it is not working. We have followed the instructions provided in the documentation to set the foreground presentation options.

What is the expected behavior?

We should receive push notifications when the iOS app is in foreground.

What are the steps to reproduce the unexpected behavior?

  1. Set foreground presentation options
Airship.push.iOS.setForegroundPresentationOptions([
  IOSForegroundPresentationOption.banner,
  IOSForegroundPresentationOption.list,
  //IOSForegroundPresentationOption.sound
]);

in main()

  1. Open iOS app in foreground
  2. Send push message to device

Is there something we may have overlooked, or is this feature broken in the latest release?

rlepinski commented 1 year ago

If you are setting those options it should be working. I thought I verified this but maybe I missed something on a fresh install. We will take a look today

Apekka commented 1 year ago

Hello @mcs-nuuk , I just tested myself on a fresh install with the same foreground presentations as you (IOSForegroundPresentationOption.banner and IOSForegroundPresentationOption.list), and it worked properly when the app is in foreground or background.

Do you have by any chance some logs when you try to send a push message while the app is in background?

mcs-nuuk commented 1 year ago

Thanks for your quick replies.

@Apekka

I only get these logs from Airship in iOS:

[<private>] AirshipKit/AirshipKeychainAccess.swift updateThisDeviceOnly(identifier:service:) [Line 295] <private>
[<private>] AirshipKit/MessageCenterList.swift syncMessageList(user:channelID:) [Line 522] Retrieve list message failed
[<private>] AirshipKit/Config.swift usesProductionPushServer [Line 140] No profile found, but not a simulator. Defaulting to inProduction = true
[<private>] AirshipKit/URLAllowList.swift allowListWithConfig(_:) [Line 114] 🚨Airship Implementation Error🚨: The Airship config options is missing URL allow list rules for SCOPE_OPEN that controls what external URLs are able to be opened externally or loaded in a web view by Airship. By default, all URLs will be allowed. To suppress this error, specify the config urlAllowListScopeOpenURL = [*] to keep the defaults, or by providing a list of rules that your app expects. See https://docs.airship.com/platform/mobile/setup/sdk/ios/#url-allow-list for more information.

How could we debug this better?

[...]
    <key>inProduction</key>
    <false/>
    <key>developmentLogLevel</key>
    <integer>5</integer>
    <key>productionLogLevel</key>
    <integer>5</integer>
[...]

AirshipConfig.plist

mcs-nuuk commented 1 year ago

@Apekka More logs

Foreground -> Background

[Airship] [V] AirshipKit/WorkBackgroundTasks.swift beginTask(_:expirationHandler:) [Line 32] Requesting task: AirshipWorkManager
[Airship] [V] AirshipKit/WorkBackgroundTasks.swift beginTask(_:expirationHandler:) [Line 54] Task granted: AirshipWorkManager
[Airship] [D] AirshipKit/Analytics.swift applicationDidEnterBackground() [Line 275] Application did enter background.
[Airship] [D]  -[UAAutomationEngine updateTriggersWithScheduleID:type:argument:incrementAmount:] [Line 666] Updating triggers with type: 1
[Airship] [V]  -[UAAutomationEngine updateTriggersWithScheduleID:type:argument:incrementAmount:]_block_invoke_2 [Line 721] Automation execution time: 0.006188 seconds, triggers: 0, triggered schedules: 0
[Airship] [D] AirshipKit/Analytics.swift addEvent(_:) [Line 419] Adding event with type app_background
[Airship] [V] AirshipKit/Analytics.swift addEvent(_:) [Line 420] Adding event AirshipEventData(body: AirshipKit.AirshipJSON.object(["connection_type": AirshipKit.AirshipJSON.string("wifi")]), id: "...", date: 2023-09-04 15:25:53 +0000, sessionID: "...", type: "app_background")
[Airship] [D] AirshipKit/EventStore.swift saveEvent(event:context:) [Line 253] Event saved: AirshipEventData(body: AirshipKit.AirshipJSON.object(["connection_type": AirshipKit.AirshipJSON.string("wifi")]), id: "...", date: 2023-09-04 15:25:53 +0000, sessionID: "...", type: "app_background")
[Airship] [V] AirshipKit/Push.swift updateAuthorizedNotificationTypes(alwaysUpdateChannel:) [Line 586] Updating authorized types.
[Airship] [V] AirshipKit/WorkBackgroundTasks.swift beginTask(_:expirationHandler:) [Line 32] Requesting task: Airship: EventUploadScheduler.upload(7)
[Airship] [V] AirshipKit/WorkBackgroundTasks.swift beginTask(_:expirationHandler:) [Line 54] Task granted: Airship: EventUploadScheduler.upload(7)
[Airship] [V] AirshipKit/EventAPIClient.swift uploadEvents(_:channelID:headers:) [Line 52] Sending to server: https://combine.asnapieu.com
[Airship] [V] AirshipKit/EventAPIClient.swift uploadEvents(_:channelID:headers:) [Line 53] Sending analytics headers: ["X-UA-Sent-At": "1693841154.609089", "X-UA-Notification-Prompted": "true", "X-UA-Timezone": "Europe/Berlin", "X-UA-Channel-ID": "...", "X-UA-Package-Name": "...", "X-UA-Device-Model": "iPhone8,1", "X-UA-Locale-Country": "DE", "X-UA-Channel-Background-Enabled": "true", "X-UA-Package-Version": "5.0.12", "X-UA-OS-Version": "15.5", "X-UA-Locale-Language": "de", "X-UA-App-Key": "...", "X-UA-Lib-Version": "17.1.2", "X-UA-Channel-Opted-In": "true", "X-UA-Push-Address": "...", "X-UA-Permission-display_notifications": "granted", "X-UA-Device-Family": "iOS", "Content-Type": "application/json"]
[Airship] [V] AirshipKit/EventAPIClient.swift uploadEvents(_:channelID:headers:) [Line 54] Sending analytics events: [AirshipKit.AirshipEventData(body: AirshipKit.AirshipJSON.object(["carrier": AirshipKit.AirshipJSON.string("Vodafone.de"), "lib_version": AirshipKit.AirshipJSON.string("17.1.2"), "time_zone": AirshipKit.AirshipJSON.number(7200.0), "notification_types": AirshipKit.AirshipJSON.array([AirshipKit.AirshipJSON.string("badge"), AirshipKit.AirshipJSON.string("sound"), AirshipKit.AirshipJSON.string("alert"), AirshipKit.AirshipJSON.string("lock_screen"), AirshipKit.AirshipJSON.string("notification_center")]), "daylight_savings": AirshipKit.AirshipJSON.string("true"), "connection_type": AirshipKit.AirshipJSON.string("wifi"), "notification_authorization": AirshipKit.AirshipJSON.string("authorized"), "os_version": AirshipKit.AirshipJSON.string("15.5"), "package_version": AirshipKit.AirshipJSON.string("5.0.12")]), id: "...", date: 2023-09-04 15:25:18 +0000, sessionID: "...", type: "app_foreground"), AirshipKit.AirshipEventData(body: AirshipKit.AirshipJSON.object(["connection_type": AirshipKit.AirshipJSON.string("wifi")]), id: "...", date: 2023-09-04 15:25:53 +0000, sessionID: "...", type: "app_background")]
[Airship] [V] AirshipKit/EventManager.swift uploadEvents() [Line 121] Analytic upload success
[Airship] [V] AirshipKit/Worker.swift process(pendingRequest:attempt:onCancel:) [Line 160] Work EventUploadScheduler.upload(7) finished

Background -> Foreground:

[Airship] [D] AirshipKit/Analytics.swift applicationWillEnterForeground() [Line 266] Application will enter foreground.
[Airship] [V] AirshipKit/Channel.swift applicationDidTransitionToForeground() [Line 324] Application did become active. Updating registration.
[Airship] [D] AirshipKit/Analytics.swift applicationDidTransitionToForeground() [Line 248] Application transitioned to foreground.
[Airship] [V] AirshipKit/ChannelCapture.swift applicationDidTransitionToForeground() [Line 75] Channel Capture capturing foreground at time 2023-09-04 15:27:04 +0000
[Airship] [D]  -[UAAutomationEngine updateTriggersWithScheduleID:type:argument:incrementAmount:] [Line 666] Updating triggers with type: 0
[Airship] [D]  -[UAAutomationEngine updateTriggersWithScheduleID:type:argument:incrementAmount:] [Line 666] Updating triggers with type: 8
[Airship] [V]  -[UAAutomationEngine updateTriggersWithScheduleID:type:argument:incrementAmount:]_block_invoke_2 [Line 721] Automation execution time: 0.002369 seconds, triggers: 0, triggered schedules: 0
[Airship] [V]  -[UAAutomationEngine updateTriggersWithScheduleID:type:argument:incrementAmount:]_block_invoke_2 [Line 721] Automation execution time: 0.006874 seconds, triggers: 0, triggered schedules: 0
[Airship] [V] AirshipKit/Push.swift updateAuthorizedNotificationTypes(alwaysUpdateChannel:) [Line 586] Updating authorized types.
[Airship] [D] AirshipKit/Analytics.swift addEvent(_:) [Line 419] Adding event with type app_foreground
[Airship] [V] AirshipKit/Analytics.swift addEvent(_:) [Line 420] Adding event AirshipEventData(body: AirshipKit.AirshipJSON.object(["time_zone": AirshipKit.AirshipJSON.number(7200.0), "os_version": AirshipKit.AirshipJSON.string("15.5"), "daylight_savings": AirshipKit.AirshipJSON.string("true"), "lib_version": AirshipKit.AirshipJSON.string("17.1.2"), "notification_types": AirshipKit.AirshipJSON.array([AirshipKit.AirshipJSON.string("badge"), AirshipKit.AirshipJSON.string("sound"), AirshipKit.AirshipJSON.string("alert"), AirshipKit.AirshipJSON.string("lock_screen"), AirshipKit.AirshipJSON.string("notification_center")]), "carrier": AirshipKit.AirshipJSON.string("Vodafone.de"), "connection_type": AirshipKit.AirshipJSON.string("wifi"), "package_version": AirshipKit.AirshipJSON.string("5.0.12"), "notification_authorization": AirshipKit.AirshipJSON.string("authorized")]), id: "...", date: 2023-09-04 15:27:04 +0000, sessionID: "...", type: "app_foreground")
[Airship] [D] AirshipKit/EventStore.swift saveEvent(event:context:) [Line 253] Event saved: AirshipEventData(body: AirshipKit.AirshipJSON.object(["time_zone": AirshipKit.AirshipJSON.number(7200.0), "os_version": AirshipKit.AirshipJSON.string("15.5"), "daylight_savings": AirshipKit.AirshipJSON.string("true"), "lib_version": AirshipKit.AirshipJSON.string("17.1.2"), "notification_types": AirshipKit.AirshipJSON.array([AirshipKit.AirshipJSON.string("badge"), AirshipKit.AirshipJSON.string("sound"), AirshipKit.AirshipJSON.string("alert"), AirshipKit.AirshipJSON.string("lock_screen"), AirshipKit.AirshipJSON.string("notification_center")]), "carrier": AirshipKit.AirshipJSON.string("Vodafone.de"), "connection_type": AirshipKit.AirshipJSON.string("wifi"), "package_version": AirshipKit.AirshipJSON.string("5.0.12"), "notification_authorization": AirshipKit.AirshipJSON.string("authorized")]), id: "...", date: 2023-09-04 15:27:04 +0000, sessionID: "...", type: "app_foreground")
[Airship] [V] AirshipKit/WorkBackgroundTasks.swift beginTask(_:expirationHandler:) [Line 32] Requesting task: Airship: Airship.MessageCenterInbox#update(4)
[Airship] [V] AirshipKit/WorkBackgroundTasks.swift beginTask(_:expirationHandler:) [Line 54] Task granted: Airship: Airship.MessageCenterInbox#update(4)
[Airship] [V] AirshipKit/WorkBackgroundTasks.swift beginTask(_:expirationHandler:) [Line 32] Requesting task: Airship: UAChannelRegistrar.registration(5)
[Airship] [V] AirshipKit/WorkBackgroundTasks.swift beginTask(_:expirationHandler:) [Line 54] Task granted: Airship: UAChannelRegistrar.registration(5)
[Airship] [V] AirshipKit/WorkBackgroundTasks.swift beginTask(_:expirationHandler:) [Line 32] Requesting task: Airship: RemoteData.refresh(6)
[Airship] [V] AirshipKit/WorkBackgroundTasks.swift beginTask(_:expirationHandler:) [Line 54] Task granted: Airship: RemoteData.refresh(6)
[Airship] [D] AirshipKit/MessageCenterList.swift getOrCreateUser(forChannelID:) [Line 433] Updating Message Center user
[Airship] [V] AirshipKit/MessageCenterAPIClient.swift updateUser(_:channelID:) [Line 266] Request to perfom batch update user: https://device-api.asnapieu.com/api/user/... body: UpdateUserRequestBody(iOSChannels: AirshipKit.(unknown context at $107c209a4).UpdateUserRequestBody.UserOperation(add: ["..."]))
[Airship] [V] AirshipKit/RemoteDataProvider.swift refresh(changeToken:locale:randomeValue:) [Line 143] Checking app remote data
[Airship] [V] AirshipKit/RemoteDataProvider.swift refresh(changeToken:locale:randomeValue:) [Line 174] Requesting app remote data
[Airship] [D] AirshipKit/RemoteDataAPIClient.swift fetchRemoteData(url:auth:lastModified:remoteDataInfoBlock:) [Line 60] Request to update remote data: AirshipRequest(url: Optional(https://remote-data.asnapieu.com/api/remote-data/app/.../ios?language=de&country=DE&sdk_version=17.1.2&random_value=1056), headers: ["X-UA-Appkey": "...", "If-Modified-Since": "Fri, 09 Jul 2021 00:00:00 GMT"], method: Optional("GET"), auth: Optional(AirshipKit.AirshipRequestAuth.generatedAppToken), body: nil, compressBody: false)
[Airship] [V] AirshipKit/RemoteDataProvider.swift refresh(changeToken:locale:randomeValue:) [Line 143] Checking contact remote data
[Airship] [D] AirshipKit/ChannelRegistrar.swift handleRegistrationWorkRequest(_:) [Line 177] Ignoring registration request, registration is up to date.
[Airship] [V] AirshipKit/Worker.swift process(pendingRequest:attempt:onCancel:) [Line 160] Work UAChannelRegistrar.registration(5) finished
[Airship] [D] AirshipKit/MessageCenterList.swift getOrCreateUser(forChannelID:) [Line 439] Message Center update request finished with response: AirshipHTTPResponse<()>(result: nil, statusCode: 200, headers: ["Date": "Mon, 04 Sep 2023 15:27:05 GMT", "Content-Length": "0", "Alt-Svc": "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000", "Via": "1.1 google"])
[Airship] [V] AirshipKit/MessageCenterStore.swift fetchMessages(withPredicate:) [Line 331] Fetching messsage center with predicate: Optional(AirshipKit.AirshipCoreDataPredicate(format: "unreadClient == NO && unread == YES", args: nil))
[Airship] [V] AirshipKit/MessageCenterStore.swift fetchMessages(withPredicate:) [Line 331] Fetching messsage center with predicate: Optional(AirshipKit.AirshipCoreDataPredicate(format: "deletedClient == YES", args: nil))
[Airship] [V] AirshipKit/MessageCenterAPIClient.swift retrieveMessageList(user:channelID:lastModified:) [Line 106] Request to retrieve message list: https://device-api.asnapieu.com/api/user/.../messages/
[Airship] [V] AirshipKit/Worker.swift process(pendingRequest:attempt:onCancel:) [Line 160] Work Airship.MessageCenterInbox#update(4) finished
[Airship] [V] AirshipKit/MessageCenterStore.swift fetchMessages(withPredicate:) [Line 331] Fetching messsage center with predicate: Optional(AirshipKit.AirshipCoreDataPredicate(format: "(messageExpiration == nil || messageExpiration >= %@) && (deletedClient == NO || deletedClient == nil)", args: Optional([2023-09-04 15:27:05 +0000])))
[Airship] [V] AirshipKit/RemoteDataProvider.swift refresh(changeToken:locale:randomeValue:) [Line 183] Refresh result for app remote data: AirshipHTTPResponse<RemoteDataResult>(result: nil, statusCode: 304, headers: ["Via": "1.1 google", "Alt-Svc": "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000", "Date": "Mon, 04 Sep 2023 15:27:05 GMT"])
[Airship] [V] AirshipKit/Worker.swift process(pendingRequest:attempt:onCancel:) [Line 160] Work RemoteData.refresh(6) finished

Unfortunately, there are no logs when I send a push message.

mcs-nuuk commented 1 year ago

We found the reason 😃 We are also using the flutter_local_notifications plugin and the iOS setup breaks Airship.

https://pub.dev/packages/flutter_local_notifications#-ios-setup

Apekka commented 1 year ago

Glad to hear that ! Sorry to not have responded earlier, but I hope that your issue is fixed now :)