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

RN 0.43 - OneSignal RN 3.2.1 - iOS - Cold start doesn't trigger 'opened' event #509

Closed
kinnarshah08 opened this issue May 15, 2018 · 10 comments

Comments

@kinnarshah08
Copy link

kinnarshah08 commented May 15, 2018

Description:

Hello,

Sharing a problem that I have been facing for a while now. Notification behaviour is different for cold start and a background app in iOS.

Things work as planned if the app is in background or if the debug mode is on. For release mode in iOS, the app opens up but the notification doesn't fire up.

Sharing snippets of index.ios.js and Main.js

index.ios.js

...
var Main = require('./SRC/Main');
var Share = require('./SRC/Share');

AppRegistry.registerComponent('PlexusMD', () => Main ); // Main activity
AppRegistry.registerComponent('PlexusMDShare', () => Share);
...

Main.js

var Main = React.createClass({
   ...
   OneSignal.init(ONE_SIGNAL_APP_ID);
   OneSignal.addEventListener('received', (param) => { Notification.onReceived(param)});
   OneSignal.addEventListener('opened', (param) => { Notification.onOpened(param)}); // NOT TRIGGERED ON COLD START
   OneSignal.addEventListener('registered', (param) => { Notification.onRegistered(param)});
   OneSignal.addEventListener('ids', (param) => { Notification.onIds(param)});
   ...
})

Environment
RN 0.43
OneSignal RN 3.2.1
iOS
NO Redux

Additional Info
I followed other seemingly related issues and moved the listeners to:

  1. index.ios.js
  2. Outside createClass

Both led to app crashing on launch.

I also tried to tap into PushNotificationIOS.getInitialNotification() - No data received.

Any help around this is very much appreciated.

@Nightsd01
Copy link
Contributor

Nightsd01 commented May 15, 2018

@kinnarshah08 it’s very difficult to troubleshoot a crash without the actual error message/stacktrace, can you please post it?

Also, are you sure you’re using 3.1.2 or 3.2.1?

@hhunaid
Copy link

hhunaid commented May 15, 2018

I don't know about 3.1.2 but its definitely the case with 3.2.1.

@Nightsd01
Copy link
Contributor

@hhunaid This bug would definitely occur if you comment out the first null init call. I would suggest un-commenting this first init call so the cold start opened handler fires correctly.

The registration issues you're facing would be a separate problem - commenting out the first init call is not a good solution. We'll want to troubleshoot more - I'll ask you for more details in the other git issue

@kinnarshah08 kinnarshah08 changed the title RN 0.43 - OneSignal RN 3.1.2 - iOS - Cold start doesn't trigger 'opened' event RN 0.43 - OneSignal RN 3.2.1 - iOS - Cold start doesn't trigger 'opened' event May 16, 2018
@kinnarshah08
Copy link
Author

Hi @Nightsd01 ,

My bad - it was 3.2.1. Thanks for pointing it out - Have updated the bug report.

I cannot attach a stack trace or message as this fails without raising an exception - the event handler itself never gets called on the initial notification.

A weird behavior (which I jokingly call the quantum particle behavior) is that the system works as soon as you try to "observe" it by debugging in any way:

  • Debug mode - works, notification opens
  • Debug mode with hot-reload - works, notification opens
  • Release mode with xcode debugging - works, notification opens
  • Release mode with debugging off - Doesn't work!

In a nutshell, whenever you try observing the notification in any way, it starts working - my hypothesis is that the app waits for the bundle to load when in debug mode but I can be wrong.

I am also adding a snippet of didFinishLaunchingWithOptions from AppDelegate.m, if that would help:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{ 
  NSURL *jsCodeLocation;

  jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];

  RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                              moduleName:@"PlexusMD"
                                              initialProperties:nil
                                              launchOptions:launchOptions];
  rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  
  // FB SDK
  [[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];

  // Razorpay SDK
  dlopen("Razorpay.framework/Razorpay", RTLD_LAZY | RTLD_GLOBAL);
  
  // RN Video SDK
  [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:nil];
  
  [self.window makeKeyAndVisible];

  // Persist Loading View till the bundle loads - tackles the white flash
  UIView* launchScreenView = [[[NSBundle mainBundle] loadNibNamed:@"LaunchScreen" owner:self options:nil] objectAtIndex:0];
  launchScreenView.frame = self.window.bounds; rootView.loadingView = launchScreenView;

  return YES;
}

Also, with reference to your comment directed at @hhunaid, do we need a null init call before we pass on the key? Would it be something like:
OneSignal.init(null);
outside the main component? Will try this, but I am a bit stumped.

I really appreciate you guys helping out on this.

@Nightsd01
Copy link
Contributor

@kinnarshah08 the SDK automatically calls init, long before the React-Native runtime is loaded (before it knows your app ID). There’s no need for you to call it again. Thanks for all of the info, it’s quite helpful

@Nightsd01
Copy link
Contributor

Nightsd01 commented May 16, 2018

@kinnarshah08 Would you be able to use something like Crashlytics so we can get a stack trace from Schrodinger's bug?

Most iOS apps are configured to enable certain compiler optimizations when in release mode. This optimizations cause the compilation progress to take longer, so it's usually only enabled for Release builds.

The fact that it still works even in release mode when debugging is enabled indicates it's probably a timing issue/race condition. A stack trace would be extremely helpful in this case, so please use something like Crashlytics so we can debug it

@Nightsd01
Copy link
Contributor

Hi @kinnarshah08

We suspect this issue is being caused by a race condition that we fixed today (#512 ). We expect to have a new update within the next few hours to fix this and other related issues

@Nightsd01
Copy link
Contributor

The new update (3.2.3) has been released and should fix this issue. @kinnarshah08 Please feel free to let me know if you see this issue (or other issues) again and I'll be happy to investigate.

@kinnarshah08
Copy link
Author

Hi @Nightsd01,

I can confirm that this update resolves the issue.
Thank you very much for the super-prompt support. :)
Cheers! 🍻

  • Kinnar

@udarts
Copy link

udarts commented Nov 29, 2018

Hi Guys, I am still having an issue where the onOpened function is not triggered when the app is closed, when the app closes again and reopened for the second time, it is triggered.

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