Cordova Push Plugin Crashes Once Notification is Received iOS


#1

Whenever the iOS app (but not Android) receives a push notification, the app crashes.

To recreate the problem:

  1. Add the ios platform to ionic.
  2. Add the cordova push notification plugin.
  3. Build ios and run on device.
  4. Register device for push notifications. (Registration is successful.)
  5. Send push notification to device, with absolutely any payload. (See payload in the logs)
  6. Ionic logs the notification as being received.
  7. After notification is handled (and specifically, after the execution of method didReceiveRemoteNotification in the AppDelegate+notification.m file), the app crashes. Step debugging does not help as after that method I step through assembly code.

More details:

Initialization

(lldb) command source -s 1 '/tmp/fruitstrap-lldb-prep-cmds-9d544ad7a9d6516d40fbc0f4d2f04d7a7464fb27’
success
2015-08-11 15:34:08.660 MyApp[2299:634883] DiskCookieStorage changing policy from 2 to 0, cookie file: file:///private/var/mobile/Containers/Data/Application/9AC37FBA-AC07-411D-88A1-C82AD977B3B3/Library/Cookies/Cookies.binarycookies
(lldb) 2015-08-11 15:34:09.372 MyApp[2299:634883] Apache Cordova native platform version 3.8.0 is starting.
(lldb) 2015-08-11 15:34:09.373 MyApp[2299:634883] Multi-tasking -> Device: YES, App: YES
(lldb) 2015-08-11 15:34:09.388 MyApp[2299:634883] Unlimited access to network resources
(lldb) 2015-08-11 15:34:09.607 MyApp[2299:634883] [CDVTimer][keyboard] 0.727057ms
(lldb) 2015-08-11 15:34:09.954 MyApp[2299:634883] [CDVTimer][splashscreen] 346.632004ms
(lldb) 2015-08-11 15:34:10.002 MyApp[2299:634883] [CDVTimer][file] 47.894001ms
2015-08-11 15:34:10.002 MyApp[2299:634883] [CDVTimer][TotalPluginStartup] 396.166980ms
(lldb) 2015-08-11 15:34:10.247 MyApp[2299:634883] active
(lldb) 2015-08-11 15:34:10.527 MyApp[2299:634883] Resetting plugins due to page load.
(lldb) 2015-08-11 15:34:11.347 MyApp[2299:634883] Finished load of: file:///private/var/mobile/Containers/Bundle/Application/D1C08963-0379-4CFB-B367-063BDD1F46DA/MyApp.app/www/index.html#/landing
(lldb) 2015-08-11 15:34:11.563 MyApp[2299:634883] THREAD WARNING: [‘PushPlugin’] took ‘12.333008’ ms. Plugin should use a background thread.
(lldb) 2015-08-11 15:34:11.571 MyApp[2299:634883] enabledRemoteNotificationTypes is not supported in iOS 8.0 and later.
(lldb) 2015-08-11 15:34:11.659 MyApp[2299:634883] Register success 602… (deivce token)

Send my empty notification

(lldb) 2015-08-11 15:36:26.038 Swipes[2299:634883] didReceiveNotification
2015-08-11 15:36:26.039 Swipes[2299:634883] Notification received
2015-08-11 15:36:26.040 Swipes[2299:634883] Msg: {foreground:“1”}
(lldb) 2015-08-11 15:36:26.090 Swipes[2299:634883] [{“foreground”:“1”}]
2015-08-11 15:36:26.091 Swipes[2299:634883] {“foreground”:“1”}
(lldb) 2015-08-11 15:36:26.197 Swipes[2299:634883] THREAD WARNING: [‘Notification’] took ‘105.516846’ ms. Plugin should use a background thread.
(lldb) 2015-08-11 15:36:26.222 Swipes[2299:634883] -[__NSDictionaryI length]: unrecognized selector sent to instance 0x17dc92a0
(lldb) 2015-08-11 15:36:26.225 Swipes[2299:634883] *** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[__NSDictionaryI length]: unrecognized selector sent to instance 0x17dc92a0’
*** First throw call stack:
(0x255a3fef 0x33f0d(lldb) c8b 0x255a9409 0x255a7327 0x254d6e78 0x28f59d33 0x28f59e67 0x28d0bf01 0x2625c3b5 0x2625bd83 0x2625bb1f 0x26267aa9 0x28d0d225 0x2625b755 0x28d0d0ad 0x28c1d3df 0x28d0d18b 0x2625b755 0x28d0d0ad 0x28c1d3df 0x28ecc5af 0x28d0d18b 0x2625b755 0x28d0d0ad 0x28c1d3df(lldb) 0x28d0d18b 0x2625b755 0x28d0d0ad 0x28c1d3df 0x28d0d18b 0x2625b755 0x28d0d0ad 0x28c1d3df 0x28d0d18b 0x2625b755 0x28d0d0ad 0x28c1d3df 0x28d0b881 0x2625b755 0x28c30d35 0x29094815 0x28ef803d 0x28c9ba41 0x28c1633f 0x25569fed 0x255676ab 0x25567ab3 0x254b4201 0x254b4013 0x2cf3f201 0x28c80a09 0xa5deb 0x344bfaaf)
(lldb) libc++abi.dylib: (lldb) terminating with uncaught exception of type NSException
(lldb) Process 2299 stopped

  • thread #1: tid = 0x9b003, 0x34589df0 libsystem_kernel.dylib__pthread_kill + 8, queue = 'com.apple.main-thread', stop reason = signal SIGABRT frame #0: 0x34589df0 libsystem_kernel.dylib__pthread_kill + 8
    libsystem_kernel.dylib`__pthread_kill:
    -> 0x34589df0 <+8>: blo 0x34589e08 ; <+32>
    0x34589df4 <+12>: ldr r12, [pc, #0x4] ; <+24>
    0x34589df8 <+16>: ldr r12, [pc, r12]
    0x34589dfc <+20>: b 0x34589e04 ; <+28>
    (lldb)

Send my notification with a body

(lldb) 2015-08-11 15:41:12.267 Swipes[2330:637508] didReceiveNotification
2015-08-11 15:41:12.268 Swipes[2330:637508] Notification received
2015-08-11 15:41:12.270 Swipes[2330:637508] Msg: {"sonhere":"yo",foreground:"1"}
(lldb) 2015-08-11 15:41:12.290 Swipes[2330:637508] [{"sonhere":"yo","foreground":"1"}]
2015-08-11 15:41:12.291 Swipes[2330:637508] {"sonhere":"yo","foreground":"1"}
(lldb) 2015-08-11 15:41:12.383 Swipes[2330:637508] THREAD WARNING: ['Notification'] took '91.395752' ms. Plugin should use a background thread.
(lldb) 2015-08-11 15:41:12.411 Swipes[2330:637508] -[__NSDictionaryI length]: unrecognized selector sent to instance 0x156be200
(lldb) 2015-08-11 15:41:12.414 Swipes[2330:637508] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryI length]: unrecognized selector sent to instance 0x156be200'
*** First throw call stack:
(0x255a3fef 0x33f0d(lldb) c8b 0x255a9409 0x255a7327 0x254d6e78 0x28f59d33 0x28f59e67 0x28d0bf01 0x2625c3b5 0x2625bd83 0x2625bb1f 0x26267aa9 0x28d0d225 0x2625b755 0x28d0d0ad 0x28c1d3df 0x28d0d18b 0x2625b755 0x28d0d0ad 0x28c1d3df 0x28ecc5af 0x28d0d18b 0x2625b755 0x28d0d0ad 0x28c1d3df(lldb)  0x28d0d18b 0x2625b755 0x28d0d0ad 0x28c1d3df 0x28d0d18b 0x2625b755 0x28d0d0ad 0x28c1d3df 0x28d0d18b 0x2625b755 0x28d0d0ad 0x28c1d3df 0x28d0b881 0x2625b755 0x28c30d35 0x29094815 0x28ef803d 0x28c9ba41 0x28c1633f 0x25569fed 0x255676ab 0x25567ab3 0x254b4201 0x(lldb) 254b4013 0x2cf3f201 0x28c80a09 0xa6deb 0x344bfaaf)
(lldb) libc++abi.dylib: (lldb) terminating with uncaught exception of type NSException
(lldb) Process 2330 stopped
* thread #1: tid = 0x9ba44, 0x34589df0 libsystem_kernel.dylib`__pthread_kill + 8, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
    frame #0: 0x34589df0 libsystem_kernel.dylib`__pthread_kill + 8
libsystem_kernel.dylib`__pthread_kill:
->  0x34589df0 <+8>:  blo    0x34589e08                ; <+32>
    0x34589df4 <+12>: ldr    r12, [pc, #0x4]           ; <+24>
    0x34589df8 <+16>: ldr    r12, [pc, r12]
    0x34589dfc <+20>: b      0x34589e04                ; <+28>
(lldb)

I really dug deep in the iOS code here and could not figure out the problem. Anyone else experiencing this?


#2

For me the solution was: remove and add again platform IOS


#3

I’ve tried that many times and I still have the same result.


#4

I do not understand point 7 in your first message in this thread. Are you building a ionic app. If so, how do you handle received messages?


#5

What happens if you send a push notification if the app is in background. I
OS of your device should handle the nessage without the app.


#6

Indeed I’m building an Ionic app. When I send a push notification and the app is in the background, nothing appears.


#7

Did you pushed the proper .p12 keyfikes to ionic.
Did you set productionmode to N?
Did you install the right push plugin?

Did you tried With platform Android?


#8

I’m not using the ionic push notifications, as I found they were too slow for my application. I created my own push notification server based on this code https://github.com/argon/node-apn .

I have tried with Android and everything works perfectly well. I’m not sure how familiar you are with the PushPlugin code, but if I comment out line 221 in PushPlugin.m, my app doesn’t crash. If I replace the variable jsCallBack with an empty string @"", then my app doesn’t crash AND the javascript receives the notification. However, as soon as I start putting in real JSON in there things break. If I hard code a string like @“Hi”, the app doesn’t crash but the javascript doesn’t receive the notification.


#9

I don’t have problems with the plugin, neither with pushnotifications in IOS and Android.
I’m afraid I can’t help you because I don’t know what you are doing. As far as I understanding you are not doing it the Ionic way?


#10

I figured it out. It was bad javascript code in my rootScope onNotificationReceived method that was being executed.


#11

Wow. I 'm glad you finally find out.