Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending App Invites in a React Native app

In the facebook iOS SDK, there is a module called App Invites, allowing to send invites to your app to your friends (https://developers.facebook.com/docs/ios/).

This module does not seem to exist for React Native apps (https://developers.facebook.com/docs/react-native) does anyone know a workaround to make it work?

Many thanks.

like image 291
RaphArbuz Avatar asked Aug 18 '16 18:08

RaphArbuz


1 Answers

I actually found how to do it digging in react-native-fbsdk.

There is a class called AppInviteDialog that you can use like the ShareDialog described here: https://developers.facebook.com/docs/react-native/sharing

const FBSDK = require('react-native-fbsdk');
const {
  AppInviteDialog,
} = FBSDK;


module.exports = React.createClass({
    getInitialState: function() {

        return {
            appInviteContent: {
            applinkUrl: 'https://yourapplink.com',
            }
        }
    },

    shareLink: function() {
        var tmp = this;
        AppInviteDialog.canShow(this.state.appInviteContent).then(
            function(canShow) {
                if (canShow) {
                    return AppInviteDialog.show(tmp.state.appInviteContent);
                }
            }
        ).then(
            function(result) {
                if (result.isCancelled) {
                  alert('Share operation was cancelled');
                } else {
                  alert('Share was successful with postId: ' + result.postId);
                }
            },
            function(error) {
                alert('Share failed with error: ' + error);
            }
        );
    }
    ...
});

Happy discovery ;)

like image 109
RaphArbuz Avatar answered Sep 21 '22 08:09

RaphArbuz