React-native-onesignal: RNOneSignal.configure is not a function after updating OneSignal to the latest version

Created on 6 Sep 2019  路  17Comments  路  Source: OneSignal/react-native-onesignal

Description:
I updated React native OneSignal from 3.2.12 version to 3.3.2 version, after that I started getting error during app launch.

(your description here)

Environment

  • react-native: 0.59.8, "react-native-onesignal": "^3.3.2",
  • I updated OneSignal using npm
  • Steps to Reproduce Issue:

    Anything else:

    (crash stacktraces, as well as any other information here)

    Here is my code:

    import OneSignal from 'react-native-onesignal';
    
    initialize() {
            OneSignal.init(config.oneSignalAppId, {kOSSettingsKeyAutoPrompt : false});
            OneSignal.inFocusDisplaying(0);
    
            OneSignal.addEventListener('received', this.onReceived);
            OneSignal.addEventListener('opened', this.onOpened);
            OneSignal.addEventListener('ids', this.onIds);
    
            OneSignal.configure();
        }
    

    Here is the full error stack trace:

    NOneSignal.configure is not a function. (In 'RNOneSignal.configure()', 'RNOneSignal.configure' is undefined)
    - node_modules/react-native-onesignal/index.js:97:12 in addEventListener
    * src/tracking/PushNotificationService.js:24:35 in initialize
    * src/App.js:37:4 in App
    - node_modules/react-proxy/modules/createClassProxy.js:98:23 in
    - node_modules/react-proxy/modules/createClassProxy.js:96:6 in instantiate

    Most helpful comment

    The docs have been updated. Cheers

    All 17 comments

    OneSignal.configure() was depreciated at the previous version.
    It would be called automatically.

    Hm, weird, but on OneSignal React Native SDK setup guide it still says, that we need to use OneSignal.configure();

    Screen Shot 2019-09-07 at 11 05 59

    When I'm removing OneSignal.configure(); I'm still getting an error:

    RNOneSignal.configure is not a function

    WasOneSignal.addEventListener('ids', this.onIds)deprecated a as well?

    Hm, weird, but on OneSignal React Native SDK setup guide it still says, that we need to use OneSignal.configure();

    Screen Shot 2019-09-07 at 11 05 59

    I believe the documentation is outdated. At 3.3.1 version, the configure() method was depreciated and at 3.3.2 version it was removed.

    I am not sure about the ids event. It requires some clarification from one-signal.

    @Luckygirlllll

    Commit Link

    As I know from 3.3.1, configure() method would be called automatically from ids event.
    And I found this commit for 3.3.2 release. They changed configure() method name in native code.

    I am not sure you need to run the pod update and pod install again after updating the onesign version in npm.

    @OscarYuen it seems that in my case error throwsOneSignal.addEventListener('ids', this.onIds);, if I comment it, app works without error, however, I need this listener, because I use it to get device pushToken /

    I removed OneSignal.configure(); from my code and removed configure() from node_modules/react-native-onesignal/index.js and app started work normally after that!

    I will make sure the docs get updated. Thanks for bringin this up. The configure method is indeed deprecated. You don't need to call this anymore to trigger the 'ids' event as this gets triggered automatically

    The docs have been updated. Cheers

    I have same issue. When I upgrade to 3.5.0 and have this:
    RNOneSignal.configure is not a function

    Code:

     OneSignal.init(oneSignalAppId, {
            kOSSettingsKeyAutoPrompt: true,
            kOSSettingsKeyInFocusDisplayOption: 0
        });
    
        OneSignal.addEventListener('received', onReceivedNotification);
        OneSignal.addEventListener('opened', onOpenedNotification);
        OneSignal.addEventListener('ids', onRegisteredIds);
    

    I have just install from npm which steps am i missing?

    @luutruong ,
    You're definitely on an older version of the SDK. Make sure you updated correctly

    @rgomezp How do i check if my version are latest? I see the Pod output.

    Installing OneSignal 2.11.2 (was 2.10.0 and source changed to `https://cdn.cocoapods.org/` from `trunk`)
    

    Is that latest version?

    @rgomezp bump!

    @luutruong ,
    Yes, that's the latest iOS native version. But the issue is not on the native side, but rather on the Javascript side. You need to make sure you're using the latest React Native OneSignal SDK version.
    Also, please include the entire stack trace, to get a better idea of what is going on

    @rgomezp Quite strange. Now it's work fine.

    @luutruong ,
    strange. good to hear though! cheers

    I had to go through I lot of process just to fix this "ids" issue.

    1. when you install the one signal package it is not linked automatically so I had to do it manually via pods:

    pod 'react-native-onesignal', :path => '../node_modules/react-native-onesignal/react-native-onesignal.podspec'

    then pod install

    1. after that I had to locate the OneSignalSDK inside "Pods/OneSignal/iOS_SDK/OneSignalSDK/Framework" folder.

    2. Drag "OneSignal.framework" in to my xcode

    Was this page helpful?
    0 / 5 - 0 ratings