我为iOS平台使用了最新的Facebook,我使用FBSDKShareDialog与Facebook共享图像,代码可以将图像共享到Facebook.But,我想获得共享结果委托。
- (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方法从未被调用过。
发布于 2015-08-28 05:24:36
您正在正确地设置fromViewController,但是控制器应该是委托,而不是object.Below是正在工作的代码,并且委托正在被调用。
- (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");
}发布于 2016-11-02 04:19:16
在我的情况下,这是因为我的视图控制器已经解散了,所以不可能调用我的委托函数。所以请检查一下您的视图控制器是否被解职了。希望会有所帮助。
https://stackoverflow.com/questions/32195141
复制相似问题