如何在以下代码中更改FB对话模式:

时间:2015-12-24 05:26:54

标签: ios facebook

如何在以下代码中更改FB对话模式:

FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
        content.contentTitle = @"Hello:";
        content.contentDescription = @"Hello World";
        content.contentURL = [NSURL URLWithString:@"http://... abc.."];
        content.imageURL = [NSURL URLWithString:@"http://...logo.png"];

[FBSDKShareDialog showFromViewController:self withContent:content delegate:self];

我试过了:

    FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
                content.contentTitle = @"Hello:";
                content.contentDescription = @"Hello World";
                content.contentURL = [NSURL URLWithString:@"http://... abc.."];
                content.imageURL = [NSURL URLWithString:@"http://...logo.png"];
   FBSDKShareDialog *shareDialogue = [[FBSDKShareDialog alloc]init];
  [shareDialogue setMode:FBSDKShareDialogModeWeb];
  [[shareDialogue class] showFromViewController:self withContent:content delegate:self];

这里showFromViewController是一个类方法:

+ (instancetype)showFromViewController:(UIViewController *)viewController
                           withContent:(id<FBSDKSharingContent>)content
                              delegate:(id<FBSDKSharingDelegate>)delegate;

这是FBSDKShareDialog.h

#import <UIKit/UIKit.h>

#import <FBSDKShareKit/FBSDKShareDialogMode.h>
#import <FBSDKShareKit/FBSDKSharing.h>
#import <FBSDKShareKit/FBSDKSharingContent.h>

/*!
 @abstract A dialog for sharing content on Facebook.
 */
@interface FBSDKShareDialog : NSObject <FBSDKSharingDialog>

/*!
 @abstract Convenience method to show an FBSDKShareDialog with a fromViewController, content and a delegate.
 @param viewController A UIViewController to present the dialog from, if appropriate.
 @param content The content to be shared.
 @param delegate The receiver's delegate.
 */
+ (instancetype)showFromViewController:(UIViewController *)viewController
                           withContent:(id<FBSDKSharingContent>)content
                              delegate:(id<FBSDKSharingDelegate>)delegate;

/*!
 @abstract A UIViewController to present the dialog from.
 @discussion If not specified, the top most view controller will be automatically determined as best as possible.
 */
@property (nonatomic, weak) UIViewController *fromViewController;

/*!
 @abstract The mode with which to display the dialog.
 @discussion Defaults to FBSDKShareDialogModeAutomatic, which will automatically choose the best available mode.
 */
@property (nonatomic, assign) FBSDKShareDialogMode mode;

@end

我们在FBSDKShareDialogMode.h中有这些模式:

FBSDKShareDialogModeAutomatic
FBSDKShareDialogModeNative,
FBSDKShareDialogModeShareSheet,
FBSDKShareDialogModeBrowser,
FBSDKShareDialogModeWeb,
FBSDKShareDialogModeFeedBrowser,
FBSDKShareDialogModeFeedWeb

请帮忙。在此先感谢。

1 个答案:

答案 0 :(得分:1)

您可以尝试以下代码:

 FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
 content.contentURL = url;
 content.contentTitle = self.strTitle;
 content.contentDescription = newStr;

 FBSDKShareDialog *dialog = [[FBSDKShareDialog alloc] init];
 dialog.fromViewController = self;
 [dialog setShareContent:content];
 dialog.mode = FBSDKShareDialogModeFeedBrowser;
 [dialog show];