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

[Bug]: Using 2 push SDKs crashed at [OneSignalNotificationsUNUserNotificationCenter onesignalRequestAuthorizationWithOptions:completionHandler:] #1404

Open
1 task done
weiqingtangx opened this issue Apr 12, 2024 · 2 comments

Comments

@weiqingtangx
Copy link

weiqingtangx commented Apr 12, 2024

What happened?

pod 'OneSignal/OneSignal', '5.1.3'

OneSignal crashed at [OneSignalNotificationsUNUserNotificationCenter onesignalRequestAuthorizationWithOptions:completionHandler:] when I registered two Push SDKs.

Integration Code

- (void)registOneSignalNotifcation:(NSDictionary *)launchOptions {
    // Remove this method to stop OneSignal Debugging
      [OneSignal.Debug setLogLevel:ONE_S_LL_VERBOSE];
      
      // OneSignal initialization
      [OneSignal initialize:oneSignalKey withLaunchOptions:launchOptions];

      // requestPermission will show the native iOS notification permission prompt.
      // We recommend removing the following code and instead using an In-App Message to prompt for notification permission
      [OneSignal.Notifications requestPermission:^(BOOL accepted) {
        NSLog(@"User accepted notifications: %d", accepted);
      } fallbackToSettings:true];
    
    [OneSignal.Notifications addClickListener:self];
    
    [self cleanBadgeNumber];
}

Steps to reproduce?

1. Integrate JPUSH SDK in AppDelegate
2. Integrate OneSignal SDK in AppDelegate
3. Crashed at OneSignalNotifications`__109-[OneSignalNotificationsUNUserNotificationCenter onesignalRequestAuthorizationWithOptions:completionHandler:]_block_invoke + 136

The reason for the crash is probably related to the below source code of OneSignal, I tried registering OneSignal first, but it still caused a crash of OneSignal. No crash of JPush SDK.

The reason we have 2 Push SDKs together is that we want to migrate from JPUSH to OneSignal SDK, we take the JPUSH SDK as a downgrade option for a while, then remove the JPUSH SDK.

OneSignalNotificationsUNUserNotificationCenter

+ (void)swizzleSelectors {
    injectSelector(
        [UNUserNotificationCenter class],
        @selector(setDelegate:),
        [OneSignalNotificationsUNUserNotificationCenter class],
        @selector(setOneSignalUNDelegate:)
   );
    
    // Overrides to work around 10.2.1 bug where getNotificationSettingsWithCompletionHandler: reports as declined if called before
    //  requestAuthorizationWithOptions:'s completionHandler fires when the user accepts notifications.
    injectSelector(
        [UNUserNotificationCenter class],
        @selector(requestAuthorizationWithOptions:completionHandler:),
        [OneSignalNotificationsUNUserNotificationCenter class],
        @selector(onesignalRequestAuthorizationWithOptions:completionHandler:)
    );
    injectSelector(
        [UNUserNotificationCenter class],
        @selector(getNotificationSettingsWithCompletionHandler:),
        [OneSignalNotificationsUNUserNotificationCenter class],
        @selector(onesignalGetNotificationSettingsWithCompletionHandler:)
   );
}


### What did you expect to happen?

No crash.

### OneSignal iOS SDK version

Release 5.1.3

### iOS version

15

### Specific iOS version

```Markdown
iOS 17.4.1

Relevant log output

* thread #4, queue = 'com.apple.usernotifications.UNUserNotificationServiceConnection.call-out', stop reason = EXC_BAD_ACCESS (code=1, address=0x10)
  * frame #0: 0x0000000109e00a58 OneSignalNotifications`__109-[OneSignalNotificationsUNUserNotificationCenter onesignalRequestAuthorizationWithOptions:completionHandler:]_block_invoke + 136
    frame #1: 0x000000010a5e4b98 libdispatch.dylib`_dispatch_call_block_and_release + 32
    frame #2: 0x000000010a5e67bc libdispatch.dylib`_dispatch_client_callout + 20
    frame #3: 0x000000010a5ee66c libdispatch.dylib`_dispatch_lane_serial_drain + 832
    frame #4: 0x000000010a5ef43c libdispatch.dylib`_dispatch_lane_invoke + 460
    frame #5: 0x000000010a5fc404 libdispatch.dylib`_dispatch_root_queue_drain_deferred_wlh + 328
    frame #6: 0x000000010a5fba38 libdispatch.dylib`_dispatch_workloop_worker_thread + 444
    frame #7: 0x00000001f33acf20 libsystem_pthread.dylib`_pthread_wqthread + 288

Code of Conduct

  • I agree to follow this project's Code of Conduct
@emawby
Copy link
Contributor

emawby commented Apr 12, 2024

@weiqingtangx Thank you for reaching out we will investigate the conflict. It looks like the JPush SDK is not open source (please correct me if I am wrong), but we will do our best to see how the SDKs are conflicting. Just to double check is the app not crashing if you remove either SDK?

@weiqingtangx
Copy link
Author

weiqingtangx commented Apr 12, 2024

@emawby Thank you for your reply. I investigated their official GitHub, it sounds like there is no source code of JPush iOS SDK. Our app is fine if we remove either SDK.

@nan-li nan-li changed the title [Bug]: Crashed at [OneSignalNotificationsUNUserNotificationCenter onesignalRequestAuthorizationWithOptions:completionHandler:] [Bug]: Using 2 push SDKs crashed at [OneSignalNotificationsUNUserNotificationCenter onesignalRequestAuthorizationWithOptions:completionHandler:] Apr 16, 2024
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

2 participants