我使用最新的Facebook SDK for iOS平台。我使用FBSDKShareDialog将图像分享到Facebook,代码可以共享图像到Facebook。但我想获得共享结果委托。
setTimeout(hello1, 3000);
我还在AppDelegate.m中添加了建议代码
- (void)sharedImage:(UIImage *) sharedImage
fromViewController:(UIViewController *) fromViewController {
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
photo.image = sharedImage;
photo.userGenerated = YES;
FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init];
content.photos = @[photo];
FBSDKShareDialog *dialog = [[FBSDKShareDialog alloc] init];
dialog.fromViewController = fromViewController;
dialog.shareContent = content;
dialog.delegate = self;
dialog.mode = FBSDKShareDialogModeShareSheet;
[dialog show];
}
#pragma mark - FBSDKSharingDelegate
- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results {
}
- (void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error {
}
- (void)sharerDidCancel:(id<FBSDKSharing>)sharer {
}
但是从未调用过FBSDKSharingDelegate方法。
答案 0 :(得分:6)
您正在正确设置fromViewController
但该控制器应该是委托而不是对象。下面是代码正在运行并且委托被调用
- (IBAction)facebookButtonClick:(UIButton *)sender {
// FacebookShare *facebookShare = [[FacebookShare alloc] init];
// [facebookShare sharedImage:[UIImage imageNamed:@"facebook_share"]
// fromViewController:self];
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
photo.image = [UIImage imageNamed:@"facebook_share"];
photo.userGenerated = YES;
FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init];
content.photos = @[photo];
FBSDKShareDialog *dialog = [[FBSDKShareDialog alloc] init];
dialog.fromViewController = self;
dialog.delegate = self;
dialog.shareContent = content;
dialog.mode = FBSDKShareDialogModeShareSheet;
[dialog show];
}
//FBSDKSharingDelegate
- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results {
NSLog(@"completed");
}
- (void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error {
NSLog(@"fail %@",error.description);
}
- (void)sharerDidCancel:(id<FBSDKSharing>)sharer {
NSLog(@"cancel");
}
答案 1 :(得分:-1)
在我的情况下,那是因为我的视图控制器已经解散,因此无法调用我的委托功能。所以请检查您的视图控制器被解雇的天气。希望会有所帮助。