react-native-onesignal icon indicating copy to clipboard operation
react-native-onesignal copied to clipboard

[Looking for Feedback] OneSignal React Native SDK 5.0.0-beta1 Released!

Open kesheshyan opened this issue 1 year ago • 17 comments

In this major version beta release for the OneSignal SDK, we are making a significant shift from a device-centered model to a user-centered model. A user-centered model allows for more powerful omni-channel integrations within the OneSignal platform.

For more information please see the migration guide.

🚧 Beta release. It is not recommended to use in production. 🚧

Please post any feedback related to the beta here!

kesheshyan avatar Mar 27 '23 17:03 kesheshyan

Hey there, I'm just trying to get everything installed according to the existing documentation on the site and I think I'm probably missing something. I'm getting the famous 'OneSignal/OneSignal.h' file not found - and none of the other solutions seem to be working for me, so I'm wondering if it has to do with the new 5.0.0 versions of libraries and such.

I've used OneSignal in the past on a few other apps and it's been great, but I am interested in using the new API as noted in the migration guide. It seems to be much clearer and more straightforward than all the 'player' verbiage and constantly sending tags and such.

I would love any and all help I could get to be able to finish the setup step. I have followed this guide (https://documentation.onesignal.com/docs/react-native-sdk-setup) to a T and have been playing with header search paths for the service extension as well as I have this in my podfile:

target 'OneSignalNotificationServiceExtension' do
  pod 'OneSignalXCFramework', '5.0.0-beta-01'
end

as opposed to the '>= 3.0', '< 4.0' line that the docs state.

Other than that, I'm pretty lost and would love to get rolling. Thanks for any help!

jakehasler avatar Mar 28 '23 20:03 jakehasler

Hello @jakehasler ! Thank you for your interest to our product! I would recommend checking out the example app we have in this repository. Let us know if it works for you. If you get the same error could you please provide your package.json file?

kesheshyan avatar Mar 28 '23 22:03 kesheshyan

Hi @kesheshyan,

I can't seem to run 5.0.0-beta-01 on my Android. It fails to initialize, even after follow both the migration guide and the example app. Also the migration guide seems to be out of sync with the example app. Migration guide says OneSignal.init whereas the example app has OneSignal.initialize. When I try to initialize my Android app just crashes on launch in debug without reporting any errors even on Logcat.

To initialize I do nothing fancy, I just run the OneSignal.initialize code in my App.tsx, and the app instantly crashes on launch.

P.S. I am trying to integrate OneSignal with @notifee/react-native and to build the Android app (I was getting the duplicate classes error otherwise), I had to patch the build.gradle file with the following changes:

-    api 'com.onesignal:OneSignal:5.0.0-beta2'
+    api ('com.onesignal:OneSignal:5.0.0-beta2') {
+        exclude group: 'androidx.work', module: 'work-runtime-ktx'
+    }

AfrazHussain avatar Mar 30 '23 01:03 AfrazHussain

Hi @jakehasler, were you able to get everything working?

Hi @AfrazHussain, thanks for pointing out the OneSignal.init discrepancy. It should be OneSignal.initialize("YOUR_APP_ID"). We will update the migration guide linked in this GitHub repository.

Can you share the error you get when the app crashes for Android?

Were you able to run on iOS? Or you have not tried that yet?

nan-li avatar Apr 05 '23 22:04 nan-li

Hey, I'd like to try this out but wanted to check whether you expect it to be compatible with the "onesignal-expo-plugin" already?

Update: I tried it and get the following error. Using Expo SDK 49 and onesignal-expo-plugin v1.3.2:

[!] CocoaPods could not find compatible versions for pod "OneSignalXCFramework":

  In Podfile:

    OneSignalXCFramework (< 4.0, >= 3.0)

    react-native-onesignal (from `../../../node_modules/react-native-onesignal`) was resolved to 5.0.0-beta-02, which depends on

      OneSignalXCFramework (= 5.0.0-beta-06)

Specs satisfying the `OneSignalXCFramework (< 4.0, >= 3.0), OneSignalXCFramework (= 5.0.0-beta-06)` dependency were found, but they required a higher minimum deployment target.

bndkt avatar Jul 25 '23 02:07 bndkt

Hello I managed to install 5.0.0-beta-02 and it works fine on iOS

the only issue regarding iOS - it was failing during the build because of error No such module OneSignal

I recreated OneSignalNotificationServiceExtension target with Objective-C, pasted code from the existing guide to NotificationService.m and replaced #import <OneSignal/OneSignal.h> with #import <OneSignalFramework/OneSignalFramework.h> and it started working fine

However, I haven't got success with Android, it builds fine, but when I call OneSignal.initialize, the app crashes on startup: below are some errors from logcat:

Exception in native call
java.lang.IllegalArgumentException: Expected receiver of type com.amazon.device.iap.internal.d, but got kotlin.Unit
        at java.lang.reflect.Field.get(Native Method)
        at com.onesignal.core.internal.purchases.impl.TrackAmazonPurchase.start(TrackAmazonPurchase.kt:83)
        at com.onesignal.core.internal.startup.StartupService.start(StartupService.kt:16)
        at com.onesignal.internal.OneSignalImp.initWithContext(OneSignalImp.kt:246)
        at com.onesignal.OneSignal.initWithContext(OneSignal.kt:126)
        at com.geektime.rnonesignalandroid.RNOneSignal.initialize(RNOneSignal.java:231)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
        at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:188)
        at com.facebook.jni.NativeRunnable.run(Native Method)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
        at android.os.Looper.loop(Looper.java:223)
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:228)

Note: We use RevenueCat in our app, but we don't use Amazon, so this is a weird error...

Android, 33 SDK, 5.0.0 released version.

OneSignal.initialize('appId');
console.log(OneSignal.Notifications.hasPermission()); // false
await new Promise(resolve => setTimeout(resolve, 500));
console.log(OneSignal.Notifications.hasPermission()); // suddenly true

Calling OneSignal.Notifications.requestPermission(true) will hang up the thread if previously was declined.

Maclay74 avatar Aug 26 '23 19:08 Maclay74

the only issue regarding iOS - it was failing during the build because of error No such module OneSignal

this is because the library silently changed the XCFramework name from OneSignal to OneSignalExtension.

The import at the top of the NotificationService.swift file needs to be changed from:

import OneSignal

to

import OneSignalExtension

skam22 avatar Aug 29 '23 20:08 skam22

Android, 33 SDK, 5.0.0 released version.

OneSignal.initialize('appId');
console.log(OneSignal.Notifications.hasPermission()); // false
await new Promise(resolve => setTimeout(resolve, 500));
console.log(OneSignal.Notifications.hasPermission()); // suddenly true

Calling OneSignal.Notifications.requestPermission(true) will hang up the thread if previously was declined.

I've experienced that as well but not anymore (it seems... :sigh:).

On my side. Similar / related issue (?!):

OneSignal.Notifications.hasPermission()

Returns false at app launch after just enabling it ! App clearly HAS permission (just requested it & confirmed in Phone Settings, just reloaded the app - reboot right).

And then if I try to requestPermission again (because hasPermission is false duh) and it hangs like @Maclay74 described.

Basically I cannot rely on hasPermission...

Strange (hint?): onChangePermission listener fires true after requesting permission (all good), but then fires false right after !

eightyfive avatar Sep 05 '23 10:09 eightyfive

I am seeing the same thing as @eightyfive where the hasPermission gives false on app load, but making an edit and saving forces expo to reload the app and it is then true. This is also incorrect for OneSignal.User.PushSubscription which I tried calling immediately after login.

Is the solution for now to just add in a timeout? This makes me feel there is a race condition happening but the types do not indicate there is a promise returned for any of these methods.

ChromeQ avatar Sep 18 '23 05:09 ChromeQ

Hello I managed to install 5.0.0-beta-02 and it works fine on iOS

the only issue regarding iOS - it was failing during the build because of error No such module OneSignal

I recreated OneSignalNotificationServiceExtension target with Objective-C, pasted code from the existing guide to NotificationService.m and replaced #import <OneSignal/OneSignal.h> with #import <OneSignalFramework/OneSignalFramework.h> and it started working fine

However, I haven't got success with Android, it builds fine, but when I call OneSignal.initialize, the app crashes on startup: below are some errors from logcat:

Exception in native call
java.lang.IllegalArgumentException: Expected receiver of type com.amazon.device.iap.internal.d, but got kotlin.Unit
        at java.lang.reflect.Field.get(Native Method)
        at com.onesignal.core.internal.purchases.impl.TrackAmazonPurchase.start(TrackAmazonPurchase.kt:83)
        at com.onesignal.core.internal.startup.StartupService.start(StartupService.kt:16)
        at com.onesignal.internal.OneSignalImp.initWithContext(OneSignalImp.kt:246)
        at com.onesignal.OneSignal.initWithContext(OneSignal.kt:126)
        at com.geektime.rnonesignalandroid.RNOneSignal.initialize(RNOneSignal.java:231)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
        at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:188)
        at com.facebook.jni.NativeRunnable.run(Native Method)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
        at android.os.Looper.loop(Looper.java:223)
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:228)

Note: We use RevenueCat in our app, but we don't use Amazon, so this is a weird error...

having the same issue on v5.0.1, were you able to solve it?

skam22 avatar Sep 29 '23 18:09 skam22

having the same issue on v5.0.1, were you able to solve it?

nope... we with the team decided to stay on v4.*, we needed to release our app ASAP, so we could not wait until v5 became stable... But probably we'll get back to this at some point

same here, we're going to stay on v4 until v5 is production ready.

skam22 avatar Oct 02 '23 19:10 skam22

My solution which seems to work is adding a timeout, try the following code and let me know if it also works for you:

// Set the `permissionGranted` on first load based on device permission
    useEffect(() => {
      const setInitialPermission = async () => {
        const granted = OneSignal.Notifications.hasPermission();
        console.log('INITIAL PERM', granted);

        setPermissionGranted(granted ?? null);
      };

      // FIXME: Hack to get correct value from `hasPermission()`
      // @see https://github.com/OneSignal/react-native-onesignal/issues/1506#issuecomment-1706332448
      setTimeout(setInitialPermission, 0);
    }, []);

I am using this to set some local state which should be in sync with the permission: const [permissionGranted, setPermissionGranted] = useState<boolean | null>(null);

If you are also trying to do that you may also need to listen to permission change event: OneSignal.Notifications.addEventListener('permissionChange', (granted: boolean) => console.log('Permission Changed:', granted);)

ChromeQ avatar Oct 03 '23 22:10 ChromeQ

Any update on this?

We have implemented v5 but waiting for this to push to production.

When we use requestPermission(true) it never resolves the promise

snikoletopoulos avatar Oct 25 '23 11:10 snikoletopoulos

I think that's been fixed in the just-released 5.0.3: https://github.com/OneSignal/react-native-onesignal/releases/tag/5.0.3

liamjones avatar Nov 10 '23 17:11 liamjones

the only issue regarding iOS - it was failing during the build because of error No such module OneSignal

this is because the library silently changed the XCFramework name from OneSignal to OneSignalExtension.

The import at the top of the NotificationService.swift file needs to be changed from:

import OneSignal

to

import OneSignalExtension

This should be part of the Migration Guide.. Otherwise people need to go through installing guide and might fail to see the change in the code.

luispedro18 avatar Jan 18 '24 12:01 luispedro18