【问题标题】:Sharing content with facebook sdk 4.0 + iOS使用 facebook sdk 4.0 + iOS 分享内容
【发布时间】:2015-09-18 08:12:45
【问题描述】:

我使用 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];  
}

其中 image 是我通过从用户的图库中选择它来设置的 UIImage。当我尝试按下我的按钮(使用此 IBAction)时,应用程序崩溃并出现此错误:

7 月 1 日 10:50:23 .local pkd[917]:检索 pid 922 的权利时出错 7 月 1 日 10:50:23 -[MainViewController 共享器:didFailWithError:]:无法识别的选择器发送到实例 0x7fd70940efd0 7 月 1 日 10:50:23:*** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[MainViewController sharer:didFailWithError:]: unrecognized selector sent to instance 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];
        }

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]:错误域 = com.facebook.sdk.share 代码 = 2“操作无法完成。(com.facebook.sdk.share 错误 2。)”用户信息 = 0x7ffc8a59bcd0 {com.facebook.sdk:FBSDKErrorArgumentValueKey=, com.facebook.sdk:FBSDKErrorDeveloperMessageKey=Feed 分享对话框支持 FBSDKShareLinkContent., com.facebook.sdk:FBSDKErrorArgumentNameKey=shareContent} 7 月 1 日 15:55:10 本地安全 [499]:SecTaskCopyAccessGroups 在模拟器中运行时未指定钥匙串访问组,回退到默认设置

终于用不同的模拟器解决了。

【问题讨论】:

  • sharer:didFailWithError: 的委托方法 FBSDKShareDialog 未实现。

标签: ios objective-c facebook share


【解决方案1】:

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];
        }

并实现所需的委托方法

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

【讨论】:

  • 内容结果为未声明的标识符,对于 :path 是否正确添加 _image?
  • 好的,现在代码看起来不错,但是当我尝试运行它时,我无法获得我的对话框,如果我“强制”[shareDialog show];应用崩溃
  • 那么,是否应该安装 Facebook 应用才能上传照片/视频资产?
  • 嗨@Andrea,有没有办法使用 iOS 应用在 Facebook 上发布 GIF?
  • @RajatDeepSingh 不太清楚,但即使 FB 不支持 gif,iOS 也支持,您可以将其转换为 JPG 或 PNG。如果您在谈论动画 GIF,它们不受 FB 框架支持,要发布它们,您必须将它们上传到特定的服务,例如 TumbIR 并将它们的链接发布到 FB
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-06-13
  • 2015-06-11
  • 1970-01-01
  • 2015-07-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多