gpt4 book ai didi

ios - 未调用 FBSDKShareDialog 委托(delegate)

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:25:47 25 4
gpt4 key购买 nike

我在iOS平台上使用最新的Facebook SDK。我使用FBSDKShareDialog分享图片到Facebook,代码可以分享图片到Facebook。但是我想得到分享结果委托(delegate)。

- (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 {

}

我还在 AppDelegate.m 中添加了建议代码

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
return YES;
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
[FBSDKAppEvents activateApp];
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
[[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation];
}

但是从来没有调用过FBSDKSharingDelegate方法。

最佳答案

您正在正确设置 fromViewController 但该 Controller 应该是委托(delegate)而不是对象。下面是正在运行的代码并且正在调用委托(delegate)

- (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");
}

关于ios - 未调用 FBSDKShareDialog 委托(delegate),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32195141/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com