简体   繁体   English

iOS Facebook SDK 4 FBSDKShareDialog

[英]iOS Facebook SDK 4 FBSDKShareDialog

I have some trouble when I try to implement FBSDKShareDialog to perform facebook sharing via my app. 当我尝试实现FBSDKShareDialog通过我的应用程序执行Facebook共享时,遇到了一些麻烦。 If official fb app is installed it shows blank dialog (where user allows to type some text etc). 如果安装了官方fb应用程序,则会显示空白对话框(用户可以在其中键入一些文字等)。 If user doesn't have fb app it shows correct info but FBSDKSharingDelegate methods doesn't work. 如果用户没有fb应用,它将显示正确的信息,但FBSDKSharingDelegate方法不起作用。 (It doesn't work even when user has fb application) (即使用户具有FB应用程序也无法使用)

- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results
{
    NSLog(@"complete");
}
- (void)sharerDidCancel:(id<FBSDKSharing>)sharer
{
    NSLog(@"did cancel");
}

- (void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error
{
    NSLog(@"%@", error);
}

It's never called even when I cancel or share via FB application. 即使我通过FB应用程序取消或共享它也从未被调用。 My code is: 我的代码是:

FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
    content.contentTitle = _place.title;
    content.imageURL = [NSURL URLWithString:_place.logoUrl];
    content.contentDescription = _place.info;
[FBSDKShareDialog showFromViewController:_viewController withContent:content delegate:self];

I have a delegate inside @interface declaration. 我在@interface声明中有一个委托。

@interface FacebookHandler () < FBSDKSharingDelegate >

@end

My app delegate has 我的应用程序代表有

#import <FBSDKCoreKit/FBSDKCoreKit.h>

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
return [[FBSDKApplicationDelegate sharedInstance] application:application
                                    didFinishLaunchingWithOptions:launchOptions];
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    [FBSDKAppEvents activateApp];
}

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation {
    return [[FBSDKApplicationDelegate sharedInstance] application:application
                                                          openURL:url
                                                sourceApplication:sourceApplication
                                                       annotation:annotation];
}

Where I was wrong? 我哪里错了? And is it good idea to post some image and title via FBSDKShareLinkContent . 通过FBSDKShareLinkContent发布一些图像和标题是个好主意。 Thanks in advance. 提前致谢。

您是从主线程调用[FBSDKShareAPI shareWithContent:content delegate:self]吗?

I've already fixed this issue. 我已经解决了这个问题。 The problem was that I've delegate to file inherited from NSObject, which can't be a delegate 问题是我已经委托了从NSObject继承的文件,该对象不能是委托

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM