我按照https://github.com/facebook/react-native-fbsdk上编写的指南安装并使用react-native-fbsdk模块。当我运行应用程序实施react-native-fbsdkshare
'Error: undefined is not an object (evaluating \'FBSDKShareDialogInterface.show\')
而且3个警告显示:然而,当我点击“分享”按钮,它引发以下错误
“警告:‘RCTFBSDKShareButton’不存在天然成分” “警告:‘RCTFBSDKSendButton’本地组件不存在” “警告:本机组件,用于‘RCTFBSDKLikeControl’不存在”
这是我使用的代码:
VAR˚F BSDKShare = require('react-native-fbsdkshare');
变种{ FBSDKShareDialog, FBSDKShareDialogInterface, FBSDKShareLinkContent, FBSDKShareShareButton } = FBSDKShare;
shareOnFacebook() {
var linkContent = new FBSDKShareLinkContent('https://facebook.com', 'Wow, check out this great site!', 'Facebook.com', null);
// Share the link using the native share dialog.
FBSDKShareDialog.show(linkContent, (error, result) => {
if (!error) {
if (result.isCancelled) {
alert('Share cancelled.');
} else {
alert('Thanks for sharing!');
}
} else {
alert('Error sharing.');
}
});
<TouchableHighlight style={[itemStyles.itemButtonShare,itemStyles.itemButtonShareFacebook]} onPress={() => this.shareOnFacebook(item)}><Text>Share On Facebook</Text></TouchableHighlight>
(我FBSDKCoreKit.framework,FBSDKLoginKit.framework和FBSDKShareKit.framework已经安装和框架的搜索路径设置。) 任何人都可以用这个错误帮助吗? 感谢
----- EDITED -------
好最后我决定创建一个本地方法,并从侧面反应调用它。如果有人面对这一问题,这是替代的解决方案:
创建2个文件,FacebookShareManager.h和FacebookShareManager.m:
FacebookShareManager.h的含量应为:
#import "RCTBridgeModule.h"
@interface FacebookShareManager : NSObject <RCTBridgeModule>
@end
和内容在FacebookShareManager.m的:
#import "FacebookShareManager.h"
#import "FBSDKCoreKit/FBSDKCoreKit.h"
#import "FBSDKShareKit/FBSDKShareKit.h"
@implementation FacebookShareManager
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(showDialog: (NSDictionary *)params callback:(RCTResponseSenderBlock)callback) {
dispatch_async(dispatch_get_main_queue(), ^{
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
NSURL * shareUrl = [NSURL URLWithString:params[@"contentUrl"]];
NSURL * shareImageUrl = [NSURL URLWithString:params[@"contentImageUrl"]];
NSString * shareTitle = [NSString stringWithString:params[@"contentTitle"]];
NSString * shareDescription = [NSString stringWithString:params[@"contentDescription"]];
content.contentURL = shareUrl;
content.imageURL = shareImageUrl;
content.contentTitle = shareTitle;
content.contentDescription = shareDescription;
[FBSDKShareDialog showFromViewController:nil
withContent:content
delegate:nil];
});
};
@end
现在我们需要从我们的反应,本地组件调用此方法:
首先包括经理您的反应本地组件类文件的顶部:
var FacebookShareManager = require('NativeModules').FacebookShareManager;
现在里面你的组件类添加这个方法:
shareOnFacebook(item) {
var params = {"contentUrl": item.url,"contentImageUrl": item.pictureUrl,"contentTitle": item.title,"contentDescription":item.description};
FacebookShareManager.showDialog(params, (info)=> {
// do something you need...
});
}
您是否已经在XCode中清理并重建应用程序,并且在安装该组件后重新启动了React Native Packager进程? – jevakallio
是的,我已经多次重新启动打包程序。重建项目多次。没有什么变化@jevakallio – meteorite
不幸的是,我不得不从反应方创建一个本地方法来调用: – meteorite