【问题标题】:Sending App Invites in a React Native app在 React Native 应用程序中发送应用程序邀请
【发布时间】:2016-08-18 18:39:45
【问题描述】:
【问题讨论】:
标签:
facebook
react-native
【解决方案1】:
我实际上发现了如何在 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);
}
);
}
...
});
快乐的发现 ;)
【解决方案2】:
在我的情况下,我将使用共享对话框在 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);
}
);
}