Onesignal-ios-sdk: iOS 10 completionHandler called twice?

Created on 29 Nov 2016  ·  14Comments  ·  Source: OneSignal/OneSignal-iOS-SDK

I need some help here guys.

My implementation of notifications is very simple:

OneSignal.initWithLaunchOptions(launchOptions, appId: "46b495af-9a8c-4af8-937a-3e57d78a0029", handleNotificationReceived: { result in
      print("Notification received: \(result)")
      guard let typedic = result?.payload.additionalData else {
        print("No additional data found, ignoring notif.")
        return
      }
//...
    }, handleNotificationAction: { result in

      print("Notification opened: \(result)")
     //...
    }, settings: [kOSSettingsKeyInFocusDisplayOption:OSNotificationDisplayType.none.rawValue])

But, when I get the notification in the background and I tap an action button, I get this exception:

* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'this request has been neutered - you can't call -sendResponse: twice nor after encoding it'

I have searched a lot around and the reason seems to be the fact that the fetchCompletion is getting called twice.

More Details:

  • My notification payload is actually contains both contents and content-available, but removing either one didn't help the case.
    Example:
{
  "app_id": "...",
  "included_segments": ["All"],
  "data": {"type":"..."},
  "headings": {"en": "Heading"},
  "subtitle": {"en": "subtitle"},
  "contents": {"en": "body"},
  "buttons": [{"id": "view_button", "text": "details"}]
}
  • I have no other code or 3rd party library concerning push notifications whatsoever.
  • If I enable in-app notification's alert, the action works perfectly fine.

What am I doing wrong?

Most helpful comment

re-open /
We got exactly same issue with @mohpor. But our iOS version is 13.x.x.
We use newest react-native-onesignal with react-native 0.60.6. The native sdk in podspec is 2.11.2.

All 14 comments

@mohpor Thanks for the report. Can you also include the following details.

  • iOS version
  • OneSignal SDK version
  • Full stack trace of the exception.
  • Your application:didReceiveRemoteNotification:fetchCompletionHandler: selector code if you have one in your AppDelegate.

Sure.
iOS: 10.1.1
OneSignal SDK: 2.2.3 (both pod and git head)
Swift Version: 3.0.1
Xcode: Version 8.1 (8B62)
I have no application:didReceiveRemoteNotification:fetchCompletionHandler: selector in my AppDeleagte
Here is the stack trace:

*** Assertion failure in -[UIHandleRemoteNotificationAction sendResponse:withCompletion:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/BaseBoard/BaseBoard-262.2.1/BaseBoard/BSAction.m:438
2016-11-30 09:00:51.606853 Proto1[3202:2399875] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'this request has been neutered - you can't call -sendResponse: twice nor after encoding it'

And

thread #1: tid = 0x249548, 0x0000000183966014 libsystem_kernel.dylib`__pthread_kill + 8, stop reason = signal SIGABRT
    frame #0: 0x0000000183966014 libsystem_kernel.dylib`__pthread_kill + 8
    frame #1: 0x0000000183a2e450 libsystem_pthread.dylib`pthread_kill + 112
    frame #2: 0x00000001838da47c libsystem_c.dylib`__abort + 144
    frame #3: 0x00000001838da3ec libsystem_c.dylib`abort + 152
    frame #4: 0x00000001833a52d4 libc++abi.dylib`abort_message + 132
    frame #5: 0x00000001833c2cc0 libc++abi.dylib`default_terminate_handler() + 304
    frame #6: 0x00000001833d0844 libobjc.A.dylib`_objc_terminate() + 124
    frame #7: 0x00000001833bf66c libc++abi.dylib`std::__terminate(void (*)()) + 16
    frame #8: 0x00000001833bf6dc libc++abi.dylib`std::terminate() + 64
    frame #9: 0x00000001833d07a0 libobjc.A.dylib`objc_terminate + 12
    frame #10: 0x000000010167d230 libdispatch.dylib`_dispatch_client_callout + 36
    frame #11: 0x0000000101689e38 libdispatch.dylib`_dispatch_barrier_sync_f_invoke + 156
    frame #12: 0x00000001864a5ad8 BaseBoard`-[BSAction sendResponse:withCompletion:] + 224
    frame #13: 0x000000018ae387f4 UIKit`-[UIHandleRemoteNotificationAction sendResponse:] + 308
    frame #14: 0x000000018aa8ac7c UIKit`__91-[UIApplication _handleNonLaunchSpecificActions:forScene:withTransitionContext:completion:]_block_invoke_3.2879 + 72
    frame #15: 0x000000010167d25c libdispatch.dylib`_dispatch_call_block_and_release + 24
    frame #16: 0x000000010167d21c libdispatch.dylib`_dispatch_client_callout + 16
    frame #17: 0x0000000101682284 libdispatch.dylib`_dispatch_main_queue_callback_4CF + 1200
    frame #18: 0x0000000184943f2c CoreFoundation`__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
    frame #19: 0x0000000184941b18 CoreFoundation`__CFRunLoopRun + 1660
    frame #20: 0x0000000184870048 CoreFoundation`CFRunLoopRunSpecific + 444
    frame #21: 0x00000001862f6198 GraphicsServices`GSEventRunModal + 180
    frame #22: 0x000000018a85c2fc UIKit`-[UIApplication _run] + 684
    frame #23: 0x000000018a857034 UIKit`UIApplicationMain + 208
  * frame #24: 0x00000001001684ac Proto1`main + 140 at AppDelegate.swift:28
    frame #25: 0x00000001838545b8 libdyld.dylib`start + 4

I'm not sure if this is the FULL stack trace.

Interestingly enough, adding an empty application:didReceiveRemoteNotification:fetchCompletionHandler: to my AppDelegate fixes the problem.

@mohpor We made a number of changes around this that should fix this issue in our 2.3.0 release.
https://github.com/OneSignal/OneSignal-iOS-SDK/releases/tag/2.3.0

Could you report back if this version now fixes this issue for you?

That's great news.
I'm going to test it and report back.

Well, I still need that empty implemented.

Thanks, I am able to reproduce the issue now. Seems only happen when there are action button along with the absents of application:didReceiveRemoteNotification:fetchCompletionHandler:.

I'll be able to create a fix now that I can reproduce the issue.

That'll be great.

@mohpor This is now fixed in commit cc7ae438bfd9cb325b63b4f0ae9771751ed4c68f and will be included in the next release.

re-open /
We got exactly same issue with @mohpor. But our iOS version is 13.x.x.
We use newest react-native-onesignal with react-native 0.60.6. The native sdk in podspec is 2.11.2.

I have same issue like @mohpor . It crash iOS version 12.x.x. and 13.x.x
I using react-native-onesignal 3.6.0 with react-native 0.60.4. Native sdk is 2.12.2

@namdao i got no crash since added and empty handler for notification

// this just a workaround to fix onesignal crash in iOS 13+
// need remove when we have a completed solution from OneSignal
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler {
}

@namdao i got no crash since added and empty handler for notification

// this just a workaround to fix onesignal crash in iOS 13+
// need remove when we have a completed solution from OneSignal
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler {
}

@thuan-nguyen-js , I have reproduce and it crash all both. When user minimize app and click noti. Thanks that code which you send. It fixed.

Was this page helpful?
0 / 5 - 0 ratings