【问题标题】:Facebook Share Dialog in iOSiOS 中的 Facebook 分享对话框
【发布时间】:2013-05-31 00:52:39
【问题描述】:

我正在尝试在示例应用程序中实现来自 Facebook 的 native Share dialog

这样做似乎有一些问题。

到目前为止我做过的事情:

  1. 包含最新的 Facebook SDK
  2. 包括 AdSupport、Social、Account、Security 和 libsqlite3.dylib。
  3. 添加了来自 Facebook 的示例代码。
  4. 还向其他链接器标志添加了 -lsqlite3.0 -ObjC
  5. 将应用 ID 添加到 plist 中
  6. 将 FBUserSettingsViewResources 包和 FacebookSDKResources.bundle 添加到项目中

但我似乎无法分享网址。共享对话框甚至没有出现。

我的代码如下所示:

Viewcontroller.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
{
    IBOutlet UIButton *buttonShare;
}
- (IBAction)shareButtonClicked:(id)sender;
@end

ViewController.m

#import "ViewController.h"
#import <FacebookSDK/FacebookSDK.h>

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



- (IBAction)shareButtonClicked:(id)sender
{
    FBShareDialogParams *params = [[FBShareDialogParams alloc] init];
    params.link = [NSURL URLWithString:@"https://developers.facebook.com/ios"];
    params.picture = [NSURL URLWithString:@"https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"];
    params.name = @"Facebook SDK for iOS";
    params.caption = @"Build great apps";
    [FBDialogs presentShareDialogWithParams:params clientState:nil handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
        if(error) {
            NSLog(@"Error: %@", error.description);
        } else {
            NSLog(@"Success!");
        }
    }];
}
@end

无法分享网址。在这方面需要一些指导。

【问题讨论】:

  • 您使用的是哪个版本的 Facebook 应用?
  • @MingLi 你是怎么检查的?
  • 在您的手机设置中,向下滚动到 Facebook,它应该会在那里显示详细信息中的版本(请注意,由于 iOS6 集成和 Facebook 应用程序,您可能有 2 个 Facebook 按钮)。

标签: ios facebook ios6 share


【解决方案1】:
- (IBAction)btn_facebook:(id)sender {
    [self performSelector:@selector(fb_func) withObject:nil afterDelay:0.0];
}

-(void)fb_func
{
    // if the session is closed, then we open it here, and establish a handler for state changes

    [FBSession openActiveSessionWithReadPermissions:nil allowLoginUI:YES completionHandler:^(FBSession *session,FBSessionState state, NSError *error)
     {
         if (error)
         {
             UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
             [alertView show];
         }
         else if(session.isOpen)
         {
             NSString *str_link = @"";
             NSLog(@"%@",str_link);

             NSDictionary *params = @{
                                      @"name" :@"name",
                                      @"caption" : @"Description",
                                      @"description" :@"test",
                                      @"picture" : PostimageToPintresrAndFacebook,
                                      @"link" : @"url",
                                      };

             // Invoke the dialog
             [FBWebDialogs presentFeedDialogModallyWithSession:nil
                                                    parameters:params
                                                       handler:
              ^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
                  if (error) {
                      NSLog(@"Error publishing story.");
                  } else {
                      if (result == FBWebDialogResultDialogNotCompleted) {
                          NSLog(@"User canceled story publishing.");
                      } else {
                          NSLog(@"Story published.");
                      }
                  }}];
         }
     }];
    return;

}

【讨论】:

    【解决方案2】:

    这对我有用:

    NSString *url = @"myUrl";
    FBLinkShareParams* params = [[FBLinkShareParams alloc]init];
    params.link = [NSURL URLWithString:url];
    
    if([FBDialogs canPresentShareDialogWithParams:params]){
            [FBDialogs presentShareDialogWithLink:  [NSURL URLWithString:url]
            name:   @"Name"
            caption:    @"Caption"
            description:    @"Description"
            picture:    nil
            clientState:    nil
            handler:    nil];
        }
    
        else{
              [...]
        }
    

    【讨论】:

      【解决方案3】:
      - (IBAction)shareButtonClicked:(id)sender
      {
          // if the session is closed, then we open it here, and establish a handler for state changes
      
          [FBSession openActiveSessionWithReadPermissions:nil allowLoginUI:YES completionHandler:^(FBSession *session,FBSessionState state, NSError *error)
           {
               if (error)
               {
                   UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
                   [alertView show];
               }
               else if(session.isOpen)
               {
                   NSString *str_img = [NSString stringWithFormat:@"https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"];
      
                   NSDictionary *params = @{
                                            @"name" :[NSString stringWithFormat:@"Facebook SDK for iOS"],
                                            @"caption" : @"Build great Apps",
                                            @"description" :@"Welcome to iOS world",
                                            @"picture" : str_img,
                                            @"link" : @"",
                                            };
      
                   // Invoke the dialog
                   [FBWebDialogs presentFeedDialogModallyWithSession:nil
                                                          parameters:params
                                                             handler:
                    ^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
                        if (error) {
                            //NSLog(@"Error publishing story.");
                            [self.indicator stopAnimating];
                        } else {
                            if (result == FBWebDialogResultDialogNotCompleted) {
                                //NSLog(@"User canceled story publishing.");
                                [self.indicator stopAnimating];
                            } else {
                                //NSLog(@"Story published.");
                                [self.indicator stopAnimating];
                            }
                        }}];
               }
      
           }];
      
          return;
      }
      

      【讨论】:

        【解决方案4】:

        您的设备上是否安装了 Facebook 应用程序?共享对话框仅在您安装了 Facebook 应用程序时才有效。

        来自共享对话框文档:

        提示 1:如果人们没有安装 Facebook 应用怎么办?

        如果人们没有安装 Facebook 应用,则无法显示“分享”对话框。应用程序可以通过调用[FBDialogs canPresentShareDialogWithParams:nil]; 检测到这一点,并且可以禁用或隐藏共享按钮或退回到 Feed 对话框以在网络上共享。有关示例,请参阅 iOS SDK 中包含的 HelloFacebookSample。

        据我所见,iOS 6 将返回NO+ canPresentShareDialogWithParams:。它只响应+ canPresentOSIntegratedShareDialogWithSession:。但我在这里可能是错的。

        不管怎样,我就是这样做的- 1. 分享链接:

        if ([FBDialogs canPresentShareDialogWithParams:nil]) {
        
            NSURL* url = [NSURL URLWithString:link.url];
            [FBDialogs presentShareDialogWithLink:url
                                      handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
                         if(error) {
                               NSLog(@"Error: %@", error.description);
                         } else {
                               NSLog(@"Success");
                         }
             }];
        }
        

        2.对于 OpenGraph 调用:

        id<FBGraphObject> pictureObject =
            [FBGraphObject openGraphObjectForPostWithType:@"your_namespace:picture"
                                                    title:image.title
                                                    image:image.thumbnailUrl
                                                      url:image.url
                                              description:@""];
        
            id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
            [action setObject:pictureObject forKey:@"picture"];
        
            [FBDialogs presentShareDialogWithOpenGraphAction:action
                                                  actionType:@"your_namespace:action_name"
                                         previewPropertyName:@"picture"
                                                     handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
                                                         if(error) {
                                                             NSLog(@"Error: %@", error.description);
                                                         } else {
                                                             NSLog(@"Success");
                                                         }
                                                     }];
        

        查看其他在 iOS 上分享的方式here

        希望这会有所帮助。

        【讨论】:

        • 是否可以使用 sharedDialog 与上述代码共享?顺便说一句,你使用 FBGraphObject 或 OpenGraph 调用什么?
        • 是的,我可以毫无问题地分享。开放图调用可用于创建故事。例如。您可以发布类似“用户在 your_app 上创建了一个收据”之类的内容。谷歌一下。
        • 用户完成操作后是否会调用presentShareDialogWithLink 处理程序?
        猜你喜欢
        • 2018-11-02
        • 1970-01-01
        • 1970-01-01
        • 2013-11-23
        • 1970-01-01
        • 1970-01-01
        • 2014-05-31
        • 2012-12-03
        • 1970-01-01
        相关资源
        最近更新 更多