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

received, opened never fired on IOS. #209

Closed
ddereszewski opened this issue Mar 2, 2017 · 13 comments
Closed

received, opened never fired on IOS. #209

ddereszewski opened this issue Mar 2, 2017 · 13 comments

Comments

@ddereszewski
Copy link

version: 3.0.3

I'm able to receive a notification but the functions received or opened are never fired or at least console log doesn't show the infromation.

I checked this when the app was enabled as well as working in a background.

What is more, if I click on the notification it doesn't change the value in OneSignal (Clicked).

class RootContainer extends Component {
  componentDidMount () {
    // if redux persist is not active fire startup action
    if (!ReduxPersist.active) {
      this.props.startup()
    }
  }


  componentWillMount() {
    OneSignal.addEventListener('received', this._onReceived.bind(this));
    OneSignal.addEventListener('opened', this._onOpened.bind(this));
    OneSignal.addEventListener('registered', this._onRegistered.bind(this));
    OneSignal.addEventListener('ids', this._onIds.bind(this));
  }

  componentWillUnmount() {
    //OneSignal.removeEventListener('received', this._onReceived.bind(this));
    //OneSignal.removeEventListener('opened', this._onOpened.bind(this));
    OneSignal.removeEventListener('registered', this._onRegistered.bind(this));
    OneSignal.removeEventListener('ids', this._onIds.bind(this));
  }

  _onIds ({pushToken, userId}){
    this.props.pushTokenIdsAvailable(pushToken, userId)
  }
  _onReceived(notification) {
    console.log("Notification received: ", notification);
  }

  _onOpened(openResult) {
    console.log('Message: ', openResult.notification.payload.body);
    console.log('Data: ', openResult.notification.payload.additionalData);
    console.log('isActive: ', openResult.notification.isAppInFocus);
    console.log('openResult: ', openResult);
  }

  _onRegistered(notifData) {
    console.log("Device had been registered for push notifications!", notifData);
  }



  render () {
    return (
          <NavigationRouter  />
    )
  }
}

const mapStateToDispatch = dispatch => ({
  startup: () => dispatch(StartupActions.startup()),
  pushTokenIdsAvailable: (pushToken, userId) => dispatch(ConfigActions.pushTokenAvailable(pushToken, userId))
})

export default connect(null, mapStateToDispatch)(RootContainer)

My AppDelegate.m

#import "AppDelegate.h"

#import "RCTBundleURLProvider.h"
#import "RCTRootView.h"
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>
#import <OneSignal/OneSignal.h>

@implementation AppDelegate

@synthesize oneSignal = _oneSignal;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  NSURL *jsCodeLocation;
  
  self.oneSignal = [[RCTOneSignal alloc] initWithLaunchOptions:launchOptions
                                                         appId:@"ecae5810-fcc6-4c40-8568-adb3947d5b0c"
                    settings:@{kOSSettingsKeyInFocusDisplayOption : @(OSNotificationDisplayTypeNotification), kOSSettingsKeyAutoPrompt : @YES}];
  
  jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];

  RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                      moduleName:@"TennisApp"
                                               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;
  [self.window makeKeyAndVisible];
  //return YES;
  return [[FBSDKApplicationDelegate sharedInstance] application:application
                                  didFinishLaunchingWithOptions:launchOptions];
}

// Facebook SDK
- (void)applicationDidBecomeActive:(UIApplication *)application {
  [FBSDKAppEvents activateApp];
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
  return [[FBSDKApplicationDelegate sharedInstance] application:application
                                                        openURL:url
                                              sourceApplication:sourceApplication
                                                     annotation:annotation];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification {
  [RCTOneSignal didReceiveRemoteNotification:notification];
}

@end
@mateoinnventto
Copy link

I' ve the same problem, someone know how to solve it?

@zawarudo
Copy link

zawarudo commented Apr 5, 2017

Having the same issue, cannot track down the issue.

Received will fire if the app is in focus, but in the background it will not.

Edit: I have other things receiving remote data in the background just fine.

@LEEY19
Copy link

LEEY19 commented May 8, 2017

@zawarudo zawarudo, have you got any updates on this issue? I faced the exact same issue as you, where onreceived will fire when app is in focus, but not when its on background.

@avishayil
Copy link
Contributor

Hi guys, could any one of you share a repo with the issue reproduced? I'll try to take a look on this.

@zawarudo
Copy link

zawarudo commented May 9, 2017

@LEEY19 Unsolved, moved away from onesignal to compensate.

@LEEY19
Copy link

LEEY19 commented May 9, 2017

@avishayil we literally just followed the example on this github readme. everything works as expected except that onreceive is not fired when app is on background on iOS

@avishayil
Copy link
Contributor

@LEEY19 I'll have a look on this.

@LEEY19
Copy link

LEEY19 commented May 9, 2017

@avishayil @zawarudo guys, after setting content_available to true when sending notification through REST API, onreceive is fired. Thanks for the help :)

@zawarudo
Copy link

zawarudo commented May 9, 2017

@LEEY19 Glad you sorted it out, if I remember correctly I did have this set to no avail.

@LEEY19
Copy link

LEEY19 commented May 10, 2017

@avishayil Ok this is really weird. setting content_available to true did fire onreceive on iOS for debug build. But when it comes to release build, the issue happens again. Also, is it a limitation of the library, that when the app is originally closed (neither foreground nor background), tapping the notif on the notif drawer does not trigger onopened?

@LEEY19
Copy link

LEEY19 commented May 11, 2017

@avishayil i think this onreceive not firing issue on iOS has something to do with this
https://developer.apple.com/reference/uikit/uiapplicationdelegate/1623013-application?language=objc

can you look into this ? Our current declaration is this:

  • (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification {
    [RCTOneSignal didReceiveRemoteNotification:notification];
    }

but seems like the 'fetchCompletionHandler:' needs to be added

@LEEY19
Copy link

LEEY19 commented May 11, 2017

@avishayil Further testing reveals this finding:
When iOS release build has the scheme running on xcode, everything works fine. But when the scheme is stopped and the app is run again, onreceive does not fire when app is on background.

However, Android release build works fine.

@hcyildirim
Copy link

@LEEY19 Hi, did you solve the problem? I'm having the same problem.

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

6 participants