在React Native应用程序中发送应用程序邀请

时间:2016-08-18 18:39:45

标签: facebook react-native

在Facebook iOS SDK中,有一个名为App Invites的模块,允许向您的朋友发送邀请(https://developers.facebook.com/docs/ios/)。

React Native应用程序(https://developers.facebook.com/docs/react-native)似乎不存在此模块。是否有人知道解决方法以使其正常工作?

非常感谢。

2 个答案:

答案 0 :(得分:15)

我实际上已经找到了如何在react-native-fbsdk中进行挖掘。

有一个名为AppInviteDialog的类,您可以像这里描述的ShareDialog一样使用它: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);
            }
        );
    }
    ...
});

快乐的发现;)

答案 1 :(得分:0)

在这种情况下,我将使用“共享对话框”在Facebook上共享...

import { ShareDialog } from 'react-native-fbsdk';

shareLinkWithShareDialog() {
  var tmp = this;
  ShareDialog.canShow(this.state.shareLinkContent).then(
    function(canShow) {
      if (canShow) {
        return ShareDialog.show(shareLinkContent = {
         contentType: 'link',
          contentUrl: "https://facebook.com",
  contentDescription: 'Facebook sharing is easy!',
});
      }
    }
  ).then(
    function(result) {
      if (result.isCancelled) {
        alert('cancelled');
      } else {
        alert('successful with postId: '
          + result.postId);
      }
    },
    function(error) {
      alert('Exception : ' + error.message);
    }
  );
}