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

iOS notification crashes when its opened #94

Open
pablop94 opened this issue Apr 19, 2021 · 5 comments
Open

iOS notification crashes when its opened #94

pablop94 opened this issue Apr 19, 2021 · 5 comments

Comments

@pablop94
Copy link

Hi, how are you?

I'm experiencing a weird issue in iOS build. When the user receives a notification an taps on it, the app is opened and crashes.
I'm not able to reproduce the issue in the simulator, notifications are working as expected.

Expected Behaviour

The app is opened

Actual Behaviour

The app crashes.

Platform and Version (eg. Android 5.0 or iOS 9.2.1)

iPhone12,8

cordova info Printout

Ionic:

Ionic CLI : 6.12.2 (/usr/local/lib/node_modules/@ionic/cli)
Ionic Framework : @ionic/angular 5.6.4
@angular-devkit/build-angular : 0.901.15
@angular-devkit/schematics : 9.1.15
@angular/cli : 9.1.15
@ionic/angular-toolkit : 2.3.3

Cordova:

Cordova CLI : 10.0.0
Cordova Platforms : 5.0.4, android 9.1.0, browser, ios 6.1.1
Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 5.0.0, (and 10 other plugins)

Utility:

cordova-res (update available: 0.15.3) : 0.15.1
native-run : 1.3.0

System:

ios-deploy : 1.10.0
ios-sim : 8.0.2
NodeJS : v12.13.0 (/usr/local/bin/node)
npm : 6.12.0
OS : macOS Catalina
Xcode : Xcode 12.4 Build version 12D4e

Logs taken while reproducing problem

I see this crashlog in TestFlight, attached.
crashlog.txt

Let me know if you have any doubts

@cyptus
Copy link

cyptus commented Jan 26, 2022

same issue here with

Application Specific Information:
BUG IN CLIENT OF LIBDISPATCH: Unbalanced call to dispatch_group_leave()

starting with iOS 14.
could you solve this @pablop94 ?

Thread 0 name:
Thread 0 Crashed:
0   libdispatch.dylib             	0x00000001aa9807d8 dispatch_group_leave.cold.1 + 36 (semaphore.c:0)
1   libdispatch.dylib             	0x00000001aa94dc00 dispatch_group_leave + 140 (semaphore.c:0)
2   libdispatch.dylib             	0x00000001aa94b24c _dispatch_call_block_and_release + 32 (init.c:1454)
3   libdispatch.dylib             	0x00000001aa94cdb0 _dispatch_client_callout + 20 (object.m:559)
4   libdispatch.dylib             	0x00000001aa95a7ac _dispatch_main_queue_callback_4CF + 836 (inline_internal.h:2548)
5   CoreFoundation                	0x00000001aacd411c __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16 (CFRunLoop.c:1790)
6   CoreFoundation                	0x00000001aacce120 __CFRunLoopRun + 2508 (CFRunLoop.c:3118)
7   CoreFoundation                	0x00000001aaccd21c CFRunLoopRunSpecific + 600 (CFRunLoop.c:3242)
8   GraphicsServices              	0x00000001c27d1784 GSEventRunModal + 164 (GSEvent.c:2259)
9   UIKitCore                     	0x00000001ad70bfe0 -[UIApplication _run] + 1072 (UIApplication.m:3253)
10  UIKitCore                     	0x00000001ad711854 UIApplicationMain + 168 (UIApplication.m:4707)
11  Test PSA en Acción           	0x00000001005a49c0 main + 56 (main.m:32)
12  libdyld.dylib                 	0x00000001aa98d6b0 start + 4

@cyptus
Copy link

cyptus commented Jan 26, 2022

the code fails here after user clicks onto the push notification in iOS notification center:

completionHandler(result);

image

log:

Push Plugin key: content-available
Push Plugin key: alert
Push Plugin key: category
Push Plugin key: sound
Push Plugin register success: {length = 32, bytes = ... }
Push Plugin finish called
Push Plugin stopBackgroundTask called
Push Plugin handlerObj
Push Plugin: stopBackgroundTask (remaining t: ...)

it seems like this handler is called multiple times, which leads into this error on the second time.

@erisu could you have a look into this?

@jhlee8804
Copy link

@cyptus Don't set the "content-available" field to fcm payload unless you absolutely need background notifications.
It seems to be called handler multiple times.

When set the "content-available" field:
https://github.com/havesource/cordova-plugin-push/blob/master/src/ios/AppDelegate%2Bnotification.m#L99
https://github.com/havesource/cordova-plugin-push/blob/master/src/ios/AppDelegate%2Bnotification.m#L103

Call PushNotification.finish()
https://github.com/havesource/cordova-plugin-push/blob/master/src/ios/PushPlugin.m#L583
https://github.com/havesource/cordova-plugin-push/blob/master/src/ios/PushPlugin.m#L604

@igorsantos07
Copy link

Same issue here, causing serious disturbance on our app since background notifications are mandatory. Sad to see such an important plugin abandoned (instead of being part of the core of Cordova).

igorsantos07 added a commit to igorsantos07/cordova-plugin-push that referenced this issue Jul 16, 2023
This is DEFINITELY not a solution, but the last time I coded obj-c was in school, 11 years ago. I'm definitely not willing to understand in which scenarios the completionHandler is called more than once. I hacked this solution with a rough idea and ChatGPT's guidance on how to do almost anything in this weird language.

WORKAROUND DISCLAIMER (if it isn't clear enough from the code comment): if you repeat the same notification body, it will probably have the same notId (it had in my test cases), and thus it will fail to call the completion handler, causing a warning. However, I guess that's better than a full application crash lol Not sure if that could cause a memory leak or stuff like that... also, not sure if this arbitrarily long NSMutableDictionary could grow terribly large and cause issues; I hope your app doesn't get too many notifications in its lifetime.
@igorsantos07
Copy link

igorsantos07 commented Jul 16, 2023

I hacked a dirty workaround for the issue: it counts how many times the completion handler was called, avoiding calling it multiple times. I'm not opening a PR because this is not a solution, and it potentially have two drawbacks:

  1. if you repeat the same notification body, it will probably have the same notId (it had in my test cases), and thus it will fail to call the completion handler, causing a warning. However, I guess that's better than a full application crash lol
  2. not sure if that could cause a memory leak or stuff like that... also, not sure if this arbitrarily long NSMutableDictionary could grow terribly large and cause issues; I hope your app doesn't get too many notifications in its lifetime

How to use it: I have no clue how to do it cleanly nowadays. My cordova plugin add randomly fails at me, and my best resort was to entirely re-clone our repo, manually change the plugin's version at package.json to github:igorsantos07/cordova-plugin-push#patch-1, then cordova add platform ios and run the application 🤷‍♂️
I also had some trouble with the compilation because, with the multiple reinstallation tries of the main plugin/fork, it included a new config key IOS_FIREBASE_MESSAGING_VERSION pointing to 6.32.2, which broke compilation.... But further tries moved that to 8.1.1 (no clue why/how), which seems to work (we didn't have this key before and it worked great, go wonder).

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

No branches or pull requests

4 participants