与facebook sdk 4.0 + iOS共享内容

Spi*_*saw 0 share facebook objective-c ios

我使用iOS上的Facebook SDK(objective-c)在Facebook上分享图像.这是我使用的代码:

-(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];  
}
Run Code Online (Sandbox Code Playgroud)

图像是我通过从用户的图库中选择它设置的UIImage.当我尝试按下我的按钮(使用此IBAction)时,应用程序崩溃会发出此错误:

7月1日10:50:23 .local pkd [917]:错误检索pid的权利922 7月1日10:50:23 - [MainViewController sharer:didFailWithError:]:无法识别的选择器发送到实例0x7fd70940efd0 7月1日10:50:23:***由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:' - [MainViewController sharer:didFailWithError:]:无法识别的选择器发送到实例0x7fd70940efd0'

这是以这种方式修复代码后的新错误

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];
        }
Run Code Online (Sandbox Code Playgroud)

:

ul 1 15:55:02 .local Dailypic [1169]:libMobileGestalt MobileGestalt.c:1025:无法检索区域信息Jul 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 Jul 1 15:55:07 local Dailypic [1169]:Error Domain = com.facebook.sdk.share Code = 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在模拟器中运行时没有指定钥匙串访问组,回退到默认设置

最后使用不同的仿真器解决了.

And*_*rea 5

早期版本的FB SDK中存在一个错误,但在这里似乎缺少委托方法的必需实现.

        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];
        }
Run Code Online (Sandbox Code Playgroud)

并实现所需的委托方法

- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results {
    // handle
}
- (void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error{
    // handle
}
- (void)sharerDidCancel:(id<FBSDKSharing>)sharer{
    // handle
}
Run Code Online (Sandbox Code Playgroud)