问题描述
我使用iOS(objective-c)上的Facebook SDK来在Facebook上共享图像.这是我使用的代码:
I use the Facebook SDK on iOS (objective-c) to share an image on Facebook. Here's the code that I use:
-(IBAction)facebookShare:(UIButton *)sender {
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
photo.image = self.image;
photo.userGenerated = YES;
FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init];
content.photos = @[photo];
[FBSDKShareDialog showFromViewController:self withContent:content delegate:self];
}
其中image是我通过从用户的库中选择它设置的UIImage.当我尝试按下按钮(使用此IBAction)时,应用程序崩溃,并显示以下错误:
Where image is an UIImage that I set by picking it from the user's gallery. When I try to press my button (with this IBAction) the app crashes giving this error:
7月1日10:50:23 .local pkd [917]:检索pid 922的权利时出错7月1日10:50:23-[MainViewController共享器:didFailWithError:]:无法识别的选择器已发送到实例0x7fd70940efd07月1日10:50:23:***由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[MainViewController sharer:didFailWithError:]:无法识别的选择器已发送至实例0x7fd70940efd0'
Jul 1 10:50:23 .local pkd[917]: error retrieving entitlements for pid 922Jul 1 10:50:23 -[MainViewController sharer:didFailWithError:]: unrecognized selector sent to instance 0x7fd70940efd0Jul 1 10:50:23: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MainViewController sharer:didFailWithError:]: unrecognized selector sent to instance 0x7fd70940efd0'
以这种方式修复代码后,这是新的错误
here's the new error after fixing the code in this way
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
photo.image = //YOUR IMAGE photo.userGenerated = YES;
FBSDKSharePhotoContent * photoContent = [[FBSDKSharePhotoContent alloc] init];
photoContent.photos = @[photo];
FBSDKShareDialog *shareDialog = [[FBSDKShareDialog alloc] init];
shareDialog.shareContent = photoContent;
shareDialog.delegate = (id)self;
shareDialog.fromViewController = self;
NSError * error = nil;
BOOL validation = [shareDialog validateWithError:&error];
if (validation) {
[shareDialog show];
}
:
ul 1 15:55:02 .local Dailypic [1169]:libMobileGestalt MobileGestalt.c:1025:无法检索区域信息7月1日15:55:06 com.apple.CoreSimulator.SimDevice.D482DFDD-3051-4759-B70D-94EC93BFF5D0.launchd_sim [471](com.apple.imfoundation.IMRemoteURLConnectionAgent):_DirtyJetsamMemoryLimit密钥在此平台上不可用.7月1日15:55:07 o.local pkd [498]:检索pid 1169的权利时出错7月1日15:55:07本地Dailypic [1169]:错误Domain = com.facebook.sdk.share代码= 2操作无法完成.(com.facebook.sdk.share错误2.)" UserInfo = 0x7ffc8a59bcd0 {com.facebook.sdk:FBSDKErrorArgumentValueKey =,com.facebook.sdk:FBSDKErrorDeveloperMessageKey = Feed共享对话框支持FBSDKShareLinkContent.,com.facebook.sdk:FBSDKErrorArgumentNameKey = shareContent}7月1日15:55:10本地安全性[499]:SecTaskCopyAccessGroups在模拟器中运行时未指定钥匙串访问组,并恢复为默认设置
ul 1 15:55:02 .local Dailypic[1169]: libMobileGestalt MobileGestalt.c:1025: Could not retrieve region infoJul 1 15:55:06 com.apple.CoreSimulator.SimDevice.D482DFDD-3051-4759-B70D-94EC93BFF5D0.launchd_sim[471] (com.apple.imfoundation.IMRemoteURLConnectionAgent): The _DirtyJetsamMemoryLimit key is not available on this platform.Jul 1 15:55:07 o.local pkd[498]: error retrieving entitlements for pid 1169Jul 1 15:55:07 local Dailypic[1169]: Error Domain=com.facebook.sdk.share Code=2 "The operation couldn’t be completed. (com.facebook.sdk.share error 2.)" UserInfo=0x7ffc8a59bcd0 {com.facebook.sdk:FBSDKErrorArgumentValueKey=, com.facebook.sdk:FBSDKErrorDeveloperMessageKey=Feed share dialogs support FBSDKShareLinkContent., com.facebook.sdk:FBSDKErrorArgumentNameKey=shareContent}Jul 1 15:55:10 local securityd[499]: SecTaskCopyAccessGroups No keychain access group specified whilst running in simulator, falling back to default set
最后使用其他仿真器解决了
Finally solved using a different Emulator.
推荐答案
在FB SDK的早期版本中存在一个错误,但是在这里看来您缺少必需的委托方法实现.
There was a bug in the earlier version of FB SDK, but here it seems that you are missing a required implementation of a delegate methods.
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
photo.image = //YOUR IMAGE photo.userGenerated = YES;
FBSDKSharePhotoContent * photoContent = [[FBSDKSharePhotoContent alloc] init];
photoContent.photos = @[photo];
FBSDKShareDialog *shareDialog = [[FBSDKShareDialog alloc] init];
shareDialog.shareContent = photoContent;
shareDialog.delegate = (id)self;
shareDialog.fromViewController = self;
NSError * error = nil;
BOOL validation = [shareDialog validateWithError:&error];
if (validation) {
[shareDialog show];
}
并实现所需的委托方法
- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results {
// handle
}
- (void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error{
// handle
}
- (void)sharerDidCancel:(id<FBSDKSharing>)sharer{
// handle
}
这篇关于与Facebook SDK 4.0 + iOS共享内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!