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

OneSignal Background Notification Issue in iOS #1435

Open
shamique opened this issue Sep 28, 2022 · 8 comments
Open

OneSignal Background Notification Issue in iOS #1435

shamique opened this issue Sep 28, 2022 · 8 comments
Labels

Comments

@shamique
Copy link

I followed this guide to setup the OneSignal background notification in My react native App: https://documentation.onesignal.com/docs/rn-android-native-module-setup-for-notification-service-extension#ios-notification-service-extension-module

Background notification is working as expected when I installed the App directly to My device through Xcode. But when I archive the build and install it from TestFlight, background notification doesn't work. Unless emitNotificationEvent event I added is not get triggered, even though the push notification is received.

When I trace the issue with Archived Build in Xcode (Using device console), noticed that _instance is null in NotificationExtensionModule.m. Anyone experienced similar issue or any idea what could be the reason ?

Note

  • Xcode Version: 13.4
  • Receiving the push notification in both instance (from test flight or direct install)
  • To put a new version in TestFlight, used to increase the build number with same version number.
  • Tried cleaning the build folder, re-installing the pods, nothing worked still

Adding the code snippet for further understanding of My issue:

AppDelegate.h

#import <Foundation/Foundation.h>
#import <React/RCTBridgeDelegate.h>
#import <UIKit/UIKit.h>
#import <UserNotifications/UserNotifications.h>


@interface AppDelegate : UIResponder <UIApplicationDelegate,RCTBridgeDelegate,UNUserNotificationCenterDelegate>

@property (nonatomic, strong) UIWindow *window;

@end

AppDelegate.m

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
  //access NotificationServiceExtensionModule emitNotificationEvent method
  [NotificationServiceExtensionModule.sharedInstance emitNotificationEvent:userInfo ];
  completionHandler(UIBackgroundFetchResultNoData);
}

NotificationServiceExtensionModule.h

#import <foundation/Foundation.h>

// NotificationServiceExtensionModule.h
#import <React/RCTBridgeModule.h>
#import <React/RCTEventEmitter.h>

@interface NotificationServiceExtensionModule : RCTEventEmitter <RCTBridgeModule>

+ (NotificationServiceExtensionModule*) sharedInstance;
- (void)emitNotificationEvent:(NSDictionary *)userInfo;


@end

NotificationServiceExtensionModule.m

#import <Foundation/Foundation.h>

// NotificationServiceExtensionModule.m
#import "NotificationServiceExtensionModule.h"

@implementation NotificationServiceExtensionModule

static NotificationServiceExtensionModule* _instance = nil;


+(NotificationServiceExtensionModule*) sharedInstance {
//    @synchronized( _instance ) {
//        if( !_instance ) {
//            _instance = [[NotificationServiceExtensionModule alloc] init];
//        }
//    }
    
    return _instance; // this returns null when installed from TestFlight. 
}

// To export a module named NotificationServiceExtensionModule
RCT_EXPORT_MODULE();

- (NSArray<NSString *> *)supportedEvents
{
  NSLog(@"Supported EVENTS__________________________");
  _instance = self;
  return @[@"NotificationEvent"];
}

- (void)emitNotificationEvent:(NSDictionary *)userInfo
{
  NSString *eventName = userInfo[@"custom"][@"a"];
  [self sendEventWithName:@"NotificationEvent" body:@{@"notificationPayload": eventName}];
}

@end
@jennantilla
Copy link
Contributor

Hi @shamique

Thanks for your patience!

How are you sending these notifications?

If you are sending the notification with content_available and no body, then you might need to double check that your production version also has the Background Modes/Remote Notifications capability added:
https://documentation.onesignal.com/docs/react-native-sdk-setup#step-4-install-for-ios-using-cocoapods-for-ios-apps

Let us know if that helps!

@angusmcleod
Copy link

angusmcleod commented Jun 16, 2023

I am experiencing exactly the same issue as the OP, and my native code is identical to that posted in the OP.

The iOS Notification Service Extension Module sends notification events to the javascript in a build installed directly from xcode, but does not when a beta build is released via TestFlight. Here's some more detail

  • I've set up Sentry logging on the javascript side of things which is never fired in a TestFlight beta but is always fired in a xcode build installed on a real device.

  • Notifications are received successfully to the device for a TestFlight beta build (i.e. they appear) whether the device is in the background or foreground, even though no event makes it to the javascript.

  • Whether or not a notification has the content_available flag, a body, or whether the app is in the foreground or background makes no difference. The javascript in a TestFlight beta build never receives the event in any permutation of these.

  • I'm using two different Schemes between the development and production versions. Other than an unrelated pre-action build script, the schemes are identical.

  • My minimum deployment target is the same across my main project, the OneSignalNotificationServiceExtension and cocoapods: iOS 13.

  • The version of OneSignalXCFramework in my Podfile.lock is 3.12.4. It doesn't seem to want to update to 3.12.5 (removing the lock file, cleaning pods etc results in the same version being installed).

  • @jennantilla As far as I can tell all versions of my project (i.e. Debug and Release) in xcode have the Background Modes/Remote Notifications capability. I've gone through the SDK instructions a few times and can't see that I've got anything wrong (or at least not that I know of).

I'm using fastlane to deploy the beta build. This is the relevant logic in my fastfile.

lane :prepare do
    produce(
      app_identifier: "com.project.Project.OneSignalNotificationServiceExtension",
      app_name: "OneSignalNotificationServiceExtension",
      skip_itc: true
    )
    match(
      app_identifier: ["com.project.Project","com.project.Project.OneSignalNotificationServiceExtension"],
      type: "development",
    )
    match(
      app_identifier: ["com.project.Project","com.project.Project.OneSignalNotificationServiceExtension"],
      type: "appstore",
    )
end

desc "Push a new beta build to TestFlight"
lane :beta do
    app_store_connect_api_key(
      key_id: [key],
      issuer_id: [issuer],
      key_content: [secret],
      duration: 1200,
      in_house: false
    )
    prepare
    increment_build_number(xcodeproj: "Project.xcodeproj")
    build_app(
      workspace: "Project.xcworkspace",
      scheme: "Project (Production)",
      clean: true
    )
    upload_to_testflight
end

@angusmcleod
Copy link

@shamique Did you ever resolve this issue? @jennantilla Sorry to ping you again, but any other ideas?

@Shamique99x
Copy link

Hi @angusmcleod. No I couldn't resolve this issue. Instead, I downgraded the OneSignal library back to v3.4.2 since it's support background notification by default.

@angusmcleod
Copy link

@kesheshyan Is downgrading the only way here?

@bwoodlt
Copy link

bwoodlt commented Oct 27, 2023

Any update on this?

@eduardojigub
Copy link

eduardojigub commented Apr 30, 2024

Guys, @angusmcleod @shamique, any updates here?
I have exactly the same problem
I've been debugging for days and can't figure out anything else.
My application works 100% perfect in debug mode, but in release it receives the push but doesn't do the actions I need to be done

@shamique
Copy link
Author

shamique commented May 6, 2024

Hi @eduardojigub, I couldn't resolve the issue. My last resort was to downgrade the One Signal version to v3.4.2, in which it supports background notification.

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

No branches or pull requests

6 participants