iOS下 Sharesdk 2.10.4 适配facebook分享

本文详细介绍了如何在iOS应用中集成并使用Facebook SDK进行分享操作,包括申请AppKey、配置回调函数、初始化SDK、发送单一分享等内容,并指导了如何编辑URL Scheme确保分享功能正常运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

还是参考快速集成指南:

http://wiki.sharesdk.cn/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E6%8C%87%E5%8D%97/


你需要facebook一个app key, 这个对应的app内的bundle必须包含应用的bundle, 否则分享失败


其次, facebook需要分享回调, 我一开始看文档里面的sharesdk接口 看到wx字样就以为只针对微信的, 后来工作人员和我聊说是全部的整体需要的回调接口


初始化:

[ShareSDK registerApp:@"sharesdk id"];
[ShareSDK connectFacebookWithAppKey:@"app id" appSecret:@"app secret"];

回调函数, 写死就行了:

-(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{
	return [ShareSDK handleOpenURL:url wxDelegate:self];
}
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{
	return [ShareSDK handleOpenURL:url sourceApplication:sourceApplication annotation:annotation wxDelegate:self];
}

如果没有这个回调函数, 会在授权后无法发送出去分享, 只会在分享窗口和facebook app之间来回切换而已


通用的发送单一分享方法:

id<ISSContent> shareContent= [ShareSDK content:content
											  defaultContent:@""
														  image:[ShareSDK jpegImageWithImage:[UIImage imageNamed:SHARE_IMAGE_NAME] quality:0.8]//[ShareSDK imageWithPath:imagePath]
														  title:[ShareSDK getClientNameWithType:shareType]
															 url:nil
												  description:nil
													 mediaType:SSPublishContentMediaTypeText];
	id<ISSAuthOptions> shareAuthOptions=[ShareSDK authOptionsWithAutoAuth:YES
																			  allowCallback:YES
																			  authViewStyle:SSAuthViewStyleFullScreenPopup
																				viewDelegate:nil
																 authManagerViewDelegate:AppDelegateHD.agviewDelegate];

[ShareSDK showShareViewWithType:shareType
								 container:[ShareSDK container]
									content:shareContent
							statusBarTips:YES
							  authOptions:shareAuthOptions
							 shareOptions:[ShareSDK defaultShareOptionsWithTitle:[ShareSDK getClientNameWithType:shareType]
																			 oneKeyShareList:nil//[NSArray defaultOneKeyShareList]
																			  qqButtonHidden:YES
																	 wxSessionButtonHidden:YES
																	wxTimelineButtonHidden:YES
																	  showKeyboardOnAppear:NO
																		  shareViewDelegate:AppDelegateHD.agviewDelegate
																		friendsViewDelegate:AppDelegateHD.agviewDelegate
																	 picViewerViewDelegate:nil]
							 result:^(ShareType type, SSResponseState state, id<ISSPlatformShareInfo> statusInfo, id<ICMErrorInfo> error, BOOL end) {
								 if (state == SSResponseStateSuccess)
								 {
									 NSLog(@"发表成功");
								 }
								 else if (state == SSPublishContentStateFail)
								 {
									 NSLog(@"发布失败!error code == %d, error code == %@", [error errorCode], [error errorDescription]);
								 }
									 }];

最后需要编辑URL Scheme, 将facebook id加上"fb"前缀就ok, 在info面板最下面的URL Type中设置


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值