GithubHelp home page GithubHelp logo

onesignal / react-native-onesignal Goto Github PK

View Code? Open in Web Editor NEW
1.6K 51.0 367.0 135.55 MB

React Native Library for OneSignal Push Notifications Service

License: Other

Java 35.84% Objective-C 24.32% Ruby 1.20% TypeScript 37.78% JavaScript 0.86%
react-native onesignal react-native-onesignal push-notifications android ios push mobile onesignal-instructions onesignal-notifications notifications

react-native-onesignal's Introduction

React Native OneSignal SDK

npm version npm downloads


⚠️ Migration Advisory for current OneSignal customers

Our new user-centric APIs and v5.x.x SDKs offer an improved user and data management experience. However, they may not be at 1:1 feature parity with our previous versions yet.

If you are migrating an existing app, we suggest using iOS and Android’s Phased Rollout capabilities to ensure that there are no unexpected issues or edge cases. Here is the documentation for each:

If you run into any challenges or have concerns, please contact our support team at [email protected]


OneSignal is a free email, sms, push notification, and in-app message service for mobile apps. This SDK makes it easy to integrate your native React-Native iOS and/or Android apps with OneSignal.

Installation

See the Setup Guide for setup instructions.

Change Log

See this repository's release tags for a complete change log of every released version.

Support

Please visit this repository's Github issue tracker for feature requests and bug reports related specifically to the SDK. For account issues and support please contact OneSignal support from the OneSignal.com dashboard.

Demo Project

To make things easier, we have published demo projects in the /examples folder of this repository.

react-native-onesignal's People

Contributors

avishayil avatar bitsal avatar danpe avatar deepmehtait avatar dependabot[bot] avatar emawby avatar eriksape avatar fhboswell avatar forki avatar haikov avatar jeanregisser avatar jeasmine avatar jennantilla avatar jkasten2 avatar jmadler avatar joonmanji avatar kesheshyan avatar lucasfronza avatar maxs15 avatar micksabox avatar mikechoch avatar nan-li avatar nightsd01 avatar rgomezp avatar samermurad avatar sonicdoe avatar torufuruya avatar wdamron avatar williamrijksen avatar wkoutre avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-onesignal's Issues

App crash on Android at launch if no Internet connection is available

Hi,

For all Android devices I have tested, my application crash right at the moment the app start if no Internet connection is available. If we turn on 3G/4G and / or Wi-Fi then everything is working. The situation does not happen on iOS device.

Any suggestion? I have put NetInfo to prevent is idsAvailable() function from running but it still fails. Seem like we need to do something in the native code.

The callback idsAvailable() exists in module RNOneSignal but only one callback may be registered

Hey guys,

I discovered an error that is happening when using registerForPushNotificationsand idsAvailable
I'm getting this RN error:

My code is as simple as that:

OneSignal.registerForPushNotifications();
OneSignal.configure({
  onNotificationOpened: this.onNotification,
  onError: this.onError
 });
OneSignal.idsAvailable((device) => {
  console.log('device = ', device);
});

I found out that the issue is related to the idsAvailable method in RCTOneSignal.m.
The callback registered in [oneSignal IdsAvailable:callback] is called twice (The first time without pushToken and the second time with a pushToken)
The issue is that it'll call the RN callback twice, and RN only authorize the callback to be called once in a method.

I'm trying to find a fix.. I guess we should call the idsAvailable method after the push has been successfully registered (or declined).

@avishayil, any idea how we could fix that ?

Thanks,

build-tools error

Throws "com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/local/opt/android-sdk/build-tools/23.0.1/aapt''

react native 0.21
on android

And readme is really need to should be checked.

How do you set the badge count programmatically?

Since it isn't possible (as far as I know) to get/set the badge count programmatically in OneSignal, I've used this library https://github.com/zo0r/react-native-push-notification#ios-only-methods and this function: PushNotification.setApplicationIconBadgeNumber(number: number) to reset the badge count in my application in addition to using OneSignal.

However, when I make the call to PushNotification.setApplicationIconBadgeNumber(number: number) OneSignal will still increment the badge count continuously, not respecting this badge count.

How to reproduce:

  • turn off OneSignal badge clearing: OneSignal_disable_badge_clearing in Info.plist
  • Send a notification from OneSignal Dashboard
  • Open app, the badge icon is now cleared due to the call to PushNotification.setApplicationIconBadgeNumber(number: number)
  • Send another push notification from OneSignal Dashboard
  • Note the badge count on the app icon was never really set to 0 in OneSignal, it was incremented

Question: How do I reset the badge count so that OneSignal doesn't continuous increment the badge count each time the push comes in.

Note: I believe what is happening here is that when the badge count is set to 0 in the client, OneSignal is not made aware of it in the cloud, so it keeps on incrementing the number. What is needed is a way to tell OneSignal the the badge count has been set to 0.

Related: #62

cc @avishayil

Sample project or better documentation

Could you please post a sample project displaying the usage of the onNotificationOpened callback? I am having a hard time making my React project setting it up for that callback. OneSignal is properly set-up only that last part is failing.

Set OneSignal app id programmatically.

Can I set OneSignal app id programmatically from my JS code? In my case I have to differentiate my app id between staging and production environment, and the environment is set in the JS portion of my app.

Notification does not appear on lock screen

Guys, The payload

{
    "app_id": "XXXXXXXXXXXXXXXX",
    "contents": {"en": "English Message","es": "Spanish Message"},
    "buttons": [{"id": "id1", "text": "button1", "icon": "ic_menu_share"}, {"id": "id2", "text": "button2", "icon": "ic_menu_send"}],
    "included_segments": ["All"],
    "android_visibility": 1
}

According to API docs, the notification should appear on lock screen. But this does not happen. I have enabled on the phone notifications on lock screen, and other apps like Facebook, Whatsapp, Gmail appear on the lock screen.

registerForPushNotifications should return a promise

Please enhance registerForPushNotifications so that it will return a promise mimicking: requestPermissions

From the doc it says:

This method returns a promise that will resolve when the user accepts, rejects, or if the permissions were previously rejected. The promise resolves to the current state of the permission.

I'm searching a way to know whether the user has accepted the notification permission or not.

RN crashes

App crashes regularly when developing, here with RN 0.2 and android 6. This happens only after integrating OneSignal RN component. This is pretty vague, any leads to track down this bug ?

Notification on iOS get lose if app is closed or totally suspended?

If i quit the app, or do not run the app for a long period of time, tapping on the incoming notification only runs the app and does not fire the notification handler as you specified in the readme file. I think it's the same problem which you did mentioned, which is the app is running too fast that the notification is not received. I did try to put Alert.alert commands to detect whether notification is received but nothing happen.

Any idea on this guys?

sendTags Docs

I believe the sendTags docs need to be updated.

the following code on Android resulted in an error for me that the OneSignal native module expected a map but instead got 2 strings (e.g. native module only accepts the object format not two string arguments).

// Sending single tag
OneSignal.sendTags("key", "value");

// Sending multiple tags
OneSignal.sendTags({key: "value", key2: "value2"});

errors in generating signed APK.

Hi,

starting from v1.1.6, generating signed APK for android emits the following error:

:app:dexRelease
Unknown source file : UNEXPECTED TOP-LEVEL EXCEPTION:
Unknown source file : com.android.dex.DexException: Multiple dex files define Landroid/support/v7/appcompat/R$anim;
Unknown source file : at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
Unknown source file : at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
Unknown source file : at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
Unknown source file : at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
Unknown source file : at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
Unknown source file : at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502)
Unknown source file : at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
Unknown source file : at com.android.dx.command.dexer.Main.run(Main.java:277)
Unknown source file : at com.android.dx.command.dexer.Main.main(Main.java:245)
Unknown source file : at com.android.dx.command.Main.main(Main.java:106)

:app:dexRelease FAILED

Any Idea?

Thanks.

Notice & Help Request Regarding RN 0.29 Support

In RN 0.29 fb changed the way RN libraries should be included in Android, and listen to application life cycle. I'm working right now on a solution for the migration, but I'd be happy to get some help from Android experts around here.

Version 1.1.9 would include all features and will support RN version < 0.29, while version 1.2.0 and up will support RN 0.29 and up. New features will be supported only on RN 0.29 and up once we'll figure a solution to migrate the library according to the new changes.

symbol(s) not found for architecture arm64

I am getting the following error when trying to build the sample project and any project with the library:

Undefined symbols for architecture arm64:
  "_OBJC_CLASS_$_OneSignal", referenced from:
      objc-class-ref in libRCTOneSignal.a(RCTOneSignal.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Any ideas on how to fix this?

Notification Action Buttons Callback

Hi,

When sending a push notification from One Signal, there is the option to include "Action Buttons" to it.

Even if doing so, the notification appears as regular (not with Action Buttons).

What do we need to do so the notification appears with buttons and each button's action is a callback in react native?

Thanks

symbol(s) not found for architecture x86_64

Hey,

I am running into an issue when importing this into a RN project (migrating from Parse!).

Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_OneSignal", referenced from:
      objc-class-ref in libRCTOneSignal.a(RCTOneSignal.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

It looks very similar to #5 although different architecture.

I am pretty unfamiliar with ObjectiveC but happy to help where I can and will issue PR if I can be guided as required. Hopefully someone can help me along!

Thanks
Ollie

iOS can not set, get or delete tags

Is there an opportunity to manage tags on iOS? If no, how can we manage devices to target them further?

In my case I check in app subscription that should allow user no receive notifications. I've stuck on how to target iOS users in this case? On Android i set subscribed tag.

how do I stop OneSignal from resetting the badge count automatically?

I am trying to maintain the badge count on the app icon until the user visits a specific section in my app. This section is in the TabBar and I want to bind the badge in the TabBar to the badge count. This is impossible if OneSignal clears the badge count automatically each time we receive notifications.

ExampleUnitTest.java Causes Rebuild To Fail On Android

Once removing this file my build passed

/Users/bdellarocco/apps/masstuning/node_modules/react-native-onesignal/android/src/test/java/com/geektime/rnonesignalandroid/ExampleUnitTest.java
Error:(3, 17) error: package org.junit does not exist
Error:(5, 24) error: package org.junit does not exist
Error:(11, 6) error: cannot find symbol class Test
Error:(13, 9) error: cannot find symbol method assertEquals(int,int)
:react-native-onesignal:compileDebugUnitTestJavaWithJavac FAILED
Error:Execution failed for task ':react-native-onesignal:compileDebugUnitTestJavaWithJavac'.

Compilation failed; see the compiler error output for details.

Ask permissions later

Hi,

Awesome component, very useful ! :)
I was wondering if we could ask the permissions later ? For now the popup show up at the start of the app and not when I'm calling OneSignal.configure.

Thanks

Multiple dex files define

RN v0.24.1

Dex: Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/auth/api/signin/internal/zzk;
    UNEXPECTED TOP-LEVEL EXCEPTION:
    com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/auth/api/signin/internal/zzk;
        at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:579)
        at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:535)
        at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:517)
        at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:164)
        at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
        at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:504)
        at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
        at com.android.dx.command.dexer.Main.run(Main.java:277)
        at com.android.dx.command.dexer.Main.main(Main.java:245)
        at com.android.dx.command.Main.main(Main.java:106)

android/app/build.gradle

dependencies {
    compile project(':react-native-facebook-account-kit')
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.google.android.gms:play-services-location:8.3.0"
    compile "com.facebook.react:react-native:+"
    compile("com.google.android.gms:play-services-analytics:8.3.0"){
      force = true
    }
    compile project(':react-native-onesignal')
    compile project(':react-native-google-analytics-bridge')
    compile project(":react-native-share")
    compile project(":react-native-vector-icons")
    compile project(':react-native-android-statusbar')
    compile project(":react-native-facebook-login")
    compile project(":react-native-google-signin")
    compile project(":react-native-image-picker")
}

Unable to merge AndroidManifest

Keeps on getting the following error

[com.onesignal:OneSignal:2.4.1] /Users/Tony/Code/app/node_modules/react-native-onesignal/android/build/intermediates/exploded-aar/com.onesignal/OneSignal/2.4.1/AndroidManifest.xml:54:17-69 Error:
    Missing 'name' key attribute on element category at [com.onesignal:OneSignal:2.4.1] AndroidManifest.xml:54:17-69
[com.onesignal:OneSignal:2.4.1] /Users/Tony/Code/app/node_modules/react-native-onesignal/android/build/intermediates/exploded-aar/com.onesignal/OneSignal/2.4.1/AndroidManifest.xml Error:
    Validation failed, exiting


See http://g.co/androidstudio/manifest-merger for more information about the manifest merger.

:react-native-onesignal:processDebugAndroidTestManifest FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-onesignal:processDebugAndroidTestManifest'.
> java.lang.RuntimeException: Manifest merger failed with multiple errors, see logs

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Basically the manifestPlaceholders from my app/build.gradle is not able to override the settings build.gradle inside react-native-one-signal. Therefore manifestApplicationId as well as all the other fields are empty string.

Unsubscribe user on iOS

Is it possible to disable PushNotifications for the user through js (I'd like to add switch in the app)? I see that we have setSubscription method, but seems like it doesn't work on iOS.

iOS and Android idsAvailable return values not consistent

on iOS we return

NSDictionary *value = @{
                                    @"pushToken": pushToken,
                                    @"playerId" : userId
                                    };
            callback(@[value]);

On Android we return

final WritableMap value = Arguments.createMap();
                    value.putString("userId", userId);
                    value.putString("pushToken", registrationId);

                    callback.invoke(value);

We should return either userId or playerId and keep it the same on both platforms for consistency

OneSignal/OneSignal.h file not found

when i build i got this error 'OneSignal/OneSignal.h file not found' in RCTOneSignal.h

can i fix it?

in my fold Headers i can't find OneSignal.h

so i was reinstall and linking onesignal library in xcode

but still i have this error

even i copy onesignal.h file to my Headers folder

but i can't solve this error.

how can i fix it?


i found this issue in closed issued

but i can't add this library in cocoapod.

i successed install cocoapod. but add library failed.

how add it in cocoapod?

This Doesnt Work

i have followed your documentation, and it does not work. i think you should test before posting here.

Show permissions prompt later

Hi and thanks for this amazing toolset.
I'd like to know, is there a way to "delay" the prompt that shows when the app starts and asks the user for permissions to send notifications?
Thanks!

idsAvailable is not called

Today I upgraded from 1.1.5 to 1.1.8 and idsAvailable stopped working event though on OneSignal dashboard the new user is added correctly.

I'm using RN 0.28.

idsAvailable() does not call callback if no pushToken.

The current implementation does not call callback if there's no pushToken in idsAvailable().
But to be consistent w/ original behaviour it seems better to callback w/ null pushToken. On client there's no way to detect what's happening.

What do you think?
Thanks.

com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/internal/zzas;

I got this error after linking the library with the Android project

Unknown source file : UNEXPECTED TOP-LEVEL EXCEPTION:
Unknown source file : com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/internal/zzas;
Unknown source file :   at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
Unknown source file :   at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
Unknown source file :   at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
Unknown source file :   at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
Unknown source file :   at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
Unknown source file :   at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502)
Unknown source file :   at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
Unknown source file :   at com.android.dx.command.dexer.Main.run(Main.java:277)
Unknown source file :   at com.android.dx.command.dexer.Main.main(Main.java:245)
Unknown source file :   at com.android.dx.command.Main.main(Main.java:106)

Remove example AwesomeProject from npm package

Thank you for providing a really easy way to use OneSignal notifications with React Native.

Please would it be possible to exclude the example AwesomeProject from the npm package.

When I use cloud services for continuous integration, I have observed that pod file in the example messes up the build. Also, it would be better, if the npm package only includes whatever is required to integrate and run with own project.

support autoRegister flag

In iOS the RCTOneSignal bridge needs to expose the autoRegister: flag while creating the OneSignal instance as well as expose the registerForPushNotifications method.

I want to control when the notification permission dialog is shown. Without these 2 changes the user sees the request for permission as soon as the app is launched the first time.

Duplicate notification registration

Set bridge can be called multiple times due to reloading bundle during debugging or code push.

- (void)setBridge:(RCTBridge *)receivedBridge {
    _bridge = receivedBridge;

    if (launchDict) {
        NSLog(@"launchDict:%@", launchDict);
        [_bridge.eventDispatcher sendDeviceEventWithName:@"remoteNotificationOpened" body:launchDict];
    }
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(handleRemoteNotificationReceived:)
                                                 name:OSRemoteNotificationReceived
                                               object:nil];
}

We will end up calling handleRemoteNotificationReceived and thus js multiple times for each notification.

Notification open causes Android app to crash and cannot navigate

Hi,

I have use OneSignal for the iOS app and it works perfectly. However, on Android (running on real device and virtual devices), the messages sometimes cause my app to crash. Moreover, it cannot navigate to any page as specified by me while everything works on iOS. Here is the log. Is it the notification which is opened before the render of the main layout leads to the issues?

04-25 20:51:07.419 20467-31513/com.lugagi I/ReactNativeJS: 'NOTIFICATION OPENED on Android Index: ', { message: 'This is a message',
data:
{ notification_type: 'newPostLike',
reference: '261',
toUser: '10203561702321472',
fromUser: '10203561702321472',
passProps: { recipeID: '261' },
pageToNavigate: 'DisplayRecipe',
notification_id: 1812,
referenceName: 'Công thức' },
isActive: false }
04-25 20:51:07.491 20467-20532/com.lugagi D/OpenGLRenderer: Switching from surface 0xec099ac0 (pbuffer) to 0xca5d60c0
04-25 20:51:07.512 20467-20467/com.lugagi W/unknown:React: Unable to dispatch keyboard events in JS as the react instance has not been attached
04-25 20:51:07.592 20467-31513/com.lugagi I/ReactNativeJS: set seen completed
04-25 20:51:07.594 20467-31513/com.lugagi I/ReactNativeJS: { Status: 'success' }
04-25 20:51:07.633 20467-26050/com.lugagi I/ReactNativeJS: set seen completed
04-25 20:51:07.633 20467-26050/com.lugagi I/ReactNativeJS: { Status: 'success' }
04-25 20:51:08.005 20467-2749/com.lugagi I/ReactNativeJS: Running application "Lugagi" with appParams: {"initialProps":{},"rootTag":1}. DEV === false, development-level warning are OFF, performance optimizations are ON

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.