Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App crash when opening notification #557

Open
tharro opened this issue Nov 18, 2024 · 19 comments · May be fixed by #560
Open

App crash when opening notification #557

tharro opened this issue Nov 18, 2024 · 19 comments · May be fixed by #560
Assignees

Comments

@tharro
Copy link

tharro commented Nov 18, 2024

  • thread Verify Ably as publisher #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0x16d527fd0)
    frame #0: 0x0000000180aa5c18 CoreFoundation__CFStrAllocateMutableContents CoreFoundation:
    -> 0x180aa5c18 <+0>: stp x20, x19, [sp, #-0x20]!
    0x180aa5c1c <+4>: stp x29, x30, [sp, #0x10]
    0x180aa5c20 <+8>: add x29, sp, #0x10
    0x180aa5c24 <+12>: add x8, x0, #0x8

dependencies:
ably_flutter: ^1.2.35
firebase_core: ^2.12.0
firebase_messaging: ^14.6.0
firebase_analytics: ^10.4.0
firebase_crashlytics: ^3.3.0
flutter_local_notifications: ^17.2.1
device_info_plus: ^10.0.1

In android/src/main/AndroidManifest.xml

...
<meta-data
            android:name="com.google.firebase.messaging.default_notification_channel_id"
            android:value="test" />
        <meta-data
            android:name="com.google.firebase.messaging.default_notification_icon"
            android:resource="@mipmap/ic_notification" />
        <meta-data
            android:name="com.google.firebase.messaging.default_notification_color"
            android:resource="@color/primary" />
        <receiver android:name="io.ably.flutter.plugin.push.FirebaseMessagingReceiver"
            tools:node="remove">
        </receiver>
...

In iOS/AppDelegate.swift

...
override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: AblyData) {
       AblyInstanceStore.sharedInstance().didRegisterForRemoteNotifications(withDeviceToken: deviceToken)
    }

    override func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
       AblyInstanceStore.sharedInstance().didFailToRegisterForRemoteNotificationsWithError_error = error;
       NSLog("application:didFailToRegisterForRemoteNotificationsWithError was called with error: %@", error.localizedDescription)
    }
    ...

┆Issue is synchronized with this Jira Task by Unito

@tharro tharro changed the title Crash app when open notification App crashes when opening notification Nov 19, 2024
@tharro tharro changed the title App crashes when opening notification App crash when opening notification Nov 19, 2024
@lawrence-forooghian
Copy link
Collaborator

Hi @tharro, thanks for reporting this. Would you be able to share an example project with some instructions on how to reproduce the issue?

@erdemtas-kollekt
Copy link

erdemtas-kollekt commented Jan 13, 2025

Hey @lawrence-forooghian,

I’m experiencing the same issue. I don’t use the Ably push notification service (it’s disabled), and I have the FCM service used elsewhere in my application. I’m not sure what’s causing this problem, but I can share part of my crash log if that helps.

Thread 0 Crashed:
0   libsystem_c.dylib             	0x000000018f0a5240 __sfvwrite + 4 (fvwrite.c:54)
1   libsystem_c.dylib             	0x000000018f0a50e0 __vfprintf + 11316 (vfprintf.c:1450)
2   libsystem_c.dylib             	0x000000018f0a2048 _vsnprintf + 224 (vsnprintf.c:81)
3   libsystem_c.dylib             	0x000000018f0a1f5c snprintf_l + 32 (snprintf.c:67)
4   CoreFoundation                	0x000000018733d23c __CFStringAppendFormatCore + 10436 (CFString.c:0)
5   CoreFoundation                	0x000000018733a518 _CFStringCreateWithFormatAndArgumentsReturningMetadata + 184 (CFString.c:2009)
6   CoreFoundation                	0x000000018733a454 _CFStringCreateWithFormatAndArgumentsAux2 + 44 (CFString.c:2001)
7   Foundation                    	0x0000000185f6c2fc +[NSString stringWithFormat:] + 68 (NSString.m:276)
8   ably_flutter                  	0x0000000102ef3b00 -[AblyFlutterWriter writeValue:] + 104 (AblyFlutterWriter.m:89)
9   Flutter                       	0x000000010410f8b0 -[FlutterStandardMethodCodec encodeMethodCall:] + 208 (FlutterStandardCodec.mm:85)
10  Flutter                       	0x0000000104109950 -[FlutterMethodChannel invokeMethod:arguments:result:] + 108 (FlutterChannels.mm:288)
11  ably_flutter                  	0x0000000102f01ebc specialized PushNotificationEventHandlers.userNotificationCenter(_:didReceive:withCompletionHandler:) + 244 (PushNotificationEventHandlers.swift:34)
12  ably_flutter                  	0x0000000102f016f0 specialized PushNotificationEventHandlers.userNotificationCenter(_:didReceive:withCompletionHandler:) + 20 (/<compiler-generated>:0)
13  ably_flutter                  	0x0000000102f016f0 @objc PushNotificationEventHandlers.userNotificationCenter(_:didReceive:withCompletionHandler:) + 100
14  Runner                        	0x0000000102572598 -[FLTFirebaseMessagingPlugin userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:] + 392 (FLTFirebaseMessagingPlugin.m:369)
15  Flutter                       	0x0000000103b63070 -[FlutterPluginAppLifeCycleDelegate userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:] + 260 (FlutterPluginAppLifeCycleDelegate.mm:310)
16  Flutter                       	0x0000000103b4ef00 -[FlutterAppDelegate userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:] + 180 (FlutterAppDelegate.mm:127)
17  ably_flutter                  	0x0000000102f01f70 thunk for @escaping @callee_guaranteed (@unowned UNUserNotificationCenter, @unowned UNNotificationResponse, @unowned @escaping @callee_unowned @convention(block) () -> ()) -> () + 24 (/<compiler-generated>:0)
18  ably_flutter                  	0x0000000102f01f70 specialized PushNotificationEventHandlers.userNotificationCenter(_:didReceive:withCompletionHandler:) + 424 (PushNotificationEventHandlers.swift:41)
19  ably_flutter                  	0x0000000102f016f0 specialized PushNotificationEventHandlers.userNotificationCenter(_:didReceive:withCompletionHandler:) + 20 (/<compiler-generated>:0)
20  ably_flutter                  	0x0000000102f016f0 @objc PushNotificationEventHandlers.userNotificationCenter(_:didReceive:withCompletionHandler:) + 100
21  Runner                        	0x0000000102572598 -[FLTFirebaseMessagingPlugin userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:] + 392 (FLTFirebaseMessagingPlugin.m:369)
22  Flutter                       	0x0000000103b63070 -[FlutterPluginAppLifeCycleDelegate userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:] + 260 (FlutterPluginAppLifeCycleDelegate.mm:310)
23  Flutter                       	0x0000000103b4ef00 -[FlutterAppDelegate userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:] + 180 (FlutterAppDelegate.mm:127)
24  ably_flutter                  	0x0000000102f01f70 thunk for @escaping @callee_guaranteed (@unowned UNUserNotificationCenter, @unowned UNNotificationResponse, @unowned @escaping @callee_unowned @convention(block) () -> ()) -> () + 24 (/```


@lawrence-forooghian
Copy link
Collaborator

Hi @erdemtas-kollekt, thanks for letting us know. Are you able to reproduce the issue?

@erdemtas-kollekt
Copy link

Hi @lawrence-forooghian, the issue consistently occurs after I tap a notification sent to my app via FCM. So yes I can reproduce the issue. However, it is not related to Ably in any way. I am ready to provide any necessary information to help resolve this issue.

@maratal maratal linked a pull request Jan 26, 2025 that will close this issue
@jhgroenjes
Copy link

Can anyone provide a status or fix/closure to this issue? I've had a customer report "an app crash" related to push notifications which started after they added our ably_flutter-based SDK to their App. We use ably_flutter 1.2.36, but we don't do anything with or reference anything in our SDK to do with ably's Push Notifications support. Curious if your push notifications code could be causing a host-app crash as this issue above is describing?

@maratal
Copy link
Collaborator

maratal commented Jan 29, 2025

@jhgroenjes This is now under investigation. Do they use FCM for push notifications? If yes, what version? I tried an example app in this repo with Firebase SDK (15.2.1) and Cloud Messaging and haven't experienced any crashes yet.

UPD: tried with firebase_messaging: ^14.6.0 (version installed 14.7.10) with the same result - no crash.

@maratal
Copy link
Collaborator

maratal commented Jan 29, 2025

@erdemtas-kollekt Couldn't you tell what versions of iOS, Firebase and Flutter is being used in your project? And after what action you've started to experience this issue?

@jhgroenjes
Copy link

I've asked for those details from the customer. They develop the Host app, we provided the SDK that uses ably_flutter. They reported Push Notifications issues (host app crashes) after installing our SDK. They discovered this ably_flutter issue log and said it's exactly what they're experiencing. KrowdKinect only uses websockets functionality from ably_flutter, but I believe you all have Push Notifications support within that plugin. Is there anyway its presence or the process of installing your plugin could impact the pre-existing PN handling within the host app? I'll confirm versions you asked for with the customer and report back.

@maratal
Copy link
Collaborator

maratal commented Jan 30, 2025

Yes, ably_flutter intercepts user's push delegate and process pushes internally. Here is an attached to this issue PR that allows user to bypass this behavior, but we keen to find out the exact reason of the crash, so any help is appreciated. Meanwhile you can try this PR's branch for your library.

@jhgroenjes
Copy link

Wait. So you're saying that an unused, unactivated and even unknown feature in your websockets SDK is actively intercepting the delegate for push notifications? Is there a reason this obtrusive behavior is Ably's default on a websockets-only use of the SDK? Is this true only of your flutter SDK or all other SDK platforms as well? We'll review the workaround you referenced, but do you intend a release that reverses this default behavior? (Assuming I understood your comments correctly).

@erdemtas-kollekt
Copy link

Hey @maratal,

I recently started using Ably, and this issue occurred after the initial setup. If you're wondering when it happens—the app receives notifications without any problems through FCM (not related to Ably), but tapping on a notification causes a crash. The issue occurs on both Android and iOS.

In our app (Flutter version: 3.24.5, Ably version: 1.2.23, firebase_core: 3.1.0, firebase_messaging: 15.0.1)

@maratal
Copy link
Collaborator

maratal commented Jan 30, 2025

@jhgroenjes It's a default behavior for Ably Flutter. I wasn't the one who implemented this, but my guess would be that no one expected that users will use push notifications somewhere else. Firebase does something similar - your need to explicitly opt-out their interception of user's delegate (in both cases libraries still call users methods).

@jhgroenjes
Copy link

Understood. I'll review the PR to implement a fix in our SDK. I'll also post details here once known from the customer as to their flutter / FCM versions or other experiences to help you with identifying root cause

@jhgroenjes
Copy link

jhgroenjes commented Jan 30, 2025

@maratal Can you add clarification to #560 as to how to implement your intended fix in a flutter Plugin project? I only want ably_flutter to be used at the Dart layer of my Plugin project to receive websockets messages. Nothing else. I'm led to believe by issue #557 and PR 560 that I still must somehow "disable" push notifications support in your ably_flutter SDK so that it doesn't interfere with the Host Apps (that already have push notifications working at the Host App layer) when they install my SDK. My SDK is now using the commit hash listed in the PR, but it would appear you're ENABLING push notifications support by default in that PR. ?? Hence why I'm posting here for clarity on what configuration changes may still be needed to get ably_flutter "out of the way" when Host Apps install our SDK (which uses ably_flutter only for websockets). The Host App developer shouldn't need to make any changes. Host Apps won't have any knowledge our SDK uses ably_flutter. The fix I need from you must be applied either in your ably_flutter SDK itself, or that, plus some other configuration change I must make to turn off your default behavior of interfering with Push Notifications at the Host App layer. Thanks!

@maratal
Copy link
Collaborator

maratal commented Jan 30, 2025

it would appear you're ENABLING push notifications support by default in that PR

Correct, currently authors of the app should add AblyFlutterHandlePushNotifications = NO into their app's Info.plist
But I understand your point, will think how to disable it on a framework level. I guess default will still be YES though, wdyt @ttypic @umair-ably

@jhgroenjes

@jhgroenjes
Copy link

Flip the logic? Keep ably_flutter quiet and minding its own business, doing absolutely nothing after being installed. Developers then must choose to declaratively Enable features one-by-one as they desire them. I don't desire push notifications, yet your current logic not only forces that on framework developers, it's crashing host apps too as we had no idea it was enabled by default. Just a thought. Thank You!! I have a customer in wait with a crashing app until you find a resolution here please.

@maratal
Copy link
Collaborator

maratal commented Jan 31, 2025

@jhgroenjes I've updated so library doesn't interfere with APNs by default due to your urgency, but keep in mind that this PR is still in a draft state (and until a proper solution will be found).

@jhgroenjes
Copy link

@maratal awesome. you rock. So to confirm, (814ed15...) is the right one? And, there's nothing else to configure other than ensure my SDK Framework imports this commit hash as the ably dependency? Asked differently, I don't need to change my code or apply any additional configurations at all to remove your push notifications features? - just use branch: fix/557-opt-out-push-handler? I understand the next main release will need to be handled differently, perhaps, deeding on how you land on a permanent resolution to this. Again, Thank you.

@maratal
Copy link
Collaborator

maratal commented Jan 31, 2025

I don't need to change my code or apply any additional configurations at all to remove your push notifications features? - just use branch: fix/557-opt-out-push-handler

Correct, commit 814ed15 also correct. Let me know if it fixed user's issue. Thank you for feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

5 participants