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

Instructions for react-native. #90

Open
balzack opened this issue Jun 9, 2023 · 7 comments
Open

Instructions for react-native. #90

balzack opened this issue Jun 9, 2023 · 7 comments

Comments

@balzack
Copy link

balzack commented Jun 9, 2023

I struggled for a few days integrating UnfiedPush into my mobile app, mostly because I am not too familiar with native android development. Silly things like making the receiver class public or the intent immutable tripped me up, but also waiting for the javascript layer to be initiated was required.

I would be happy to document the steps I followed if you would be interested in adding it to your site. Here is my app for reference: https://github.com/balzack/databag/tree/unified

Mostly, I love your project and hope it continues to grow!

@p1gp1g
Copy link
Member

p1gp1g commented Jun 9, 2023

Do you think we can use your work to make a library ? It will probably be quite similar to flutter-connector :)

Else documentation is welcome !

@balzack
Copy link
Author

balzack commented Jun 9, 2023

In my app, I take the payload and use it as the title, as I didn't need the description. For a formal react-native plugin you would probably want to have a format defined, ex: { "title": <title>, "description": }

If you are asking me to write the plugin, I probably can in time, but am new to the native layer and would have some learning to do on how plugins work. If you are asking to take the code yourself and make the plugin, then feel free. All my code is open and free.

@p1gp1g
Copy link
Member

p1gp1g commented Jun 10, 2023

The right way to do is to pass the message to the react side, like you're doing with onNewEndpoint. I haven't done any react but if you want to work on the react lib, I'll be happy to help (it is easier once there is a structure :) )

@balzack
Copy link
Author

balzack commented Jun 11, 2023

I'll give it a go. No promises as I'll need to do some learning first, but it's a good excuse for me to learn the domain.

I'm not sure it will work to load the whole javascript engine to process a notification when the app is not running; the react-native firebase plugin doesn't. It is best to stay consistent with the other connectors, so I will try your approach first.

Hopefully my work can help your project grow. Cheers.

@balzack
Copy link
Author

balzack commented Jun 12, 2023

I started working the plugin. In my app, my usage model was to use UnifiedPush if a distributor was found, otherwise to try and use Firebase. I guess this is similar to your embedded FCM distributor, but I didn't want to host a rewrite proxy.

As a result of my the way I use UnifiedPush, I didn't want the 'no distributor' dialog to popup. Unfortunately the 'UnifiedPush.registerApp' was not working for me, and I had to use 'UnifiedPush.registerAppWithDialog'. To avoid the popup, I added the work around code:

this.getSharedPreferences("unifiedpush.connector", Context.MODE_PRIVATE).edit().putBoolean("unifiedpush.no_distrib_dialog", true).apply();

In short, is the 'registerApp' expected to be working, and I am likely doing something wrong? It would be best if the plugin didn't include any workarounds.

@p1gp1g
Copy link
Member

p1gp1g commented Jun 13, 2023

I started working the plugin. In my app, my usage model was to use UnifiedPush if a distributor was found, otherwise to try and use Firebase. I guess this is similar to your embedded FCM distributor, but I didn't want to host a rewrite proxy.

Usually, we let the user choose what they prefer, it can be achieved with the google firebase-messaging lib or the embedded FCM distib.

As a result of my the way I use UnifiedPush, I didn't want the 'no distributor' dialog to popup. Unfortunately the 'UnifiedPush.registerApp' was not working for me, and I had to use 'UnifiedPush.registerAppWithDialog'. To avoid the popup, I added the work around code:

this.getSharedPreferences("unifiedpush.connector", Context.MODE_PRIVATE).edit().putBoolean("unifiedpush.no_distrib_dialog", true).apply();

In short, is the 'registerApp' expected to be working, and I am likely doing something wrong? It would be best if the plugin didn't include any workarounds.

Indeed, something may be wrong. What can be done to avoid the pop up when starting is checking if getDistributors is empty before calling registerAppWithDialog. This function (registerAppWithDialog) can be called once clicked on the UI button used to change distributor.

Nevertheless, all of this logic is on the application side. The library should just interfaces react with the android side :)

@balzack
Copy link
Author

balzack commented Jun 14, 2023

I finished a first pass of the plugin library, but I don't think it will be all that useful for you. I wasn't able to call into the JS from the backgrounded app. I left it as a replacement for the way I was using UnifiedPush and tested with my app.

I'll spend more time looking into why I can't call into the JS engine from a backgrounded app, but I'm not sure I'll be able to find a solution. I am happy to make any changes you suggest, or let you take over the repo.

repo: https://github.com/balzack/react-native-unifiedpush-connector
npm: https://www.npmjs.com/package/react-native-unifiedpush-connector

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

2 participants