【问题标题】:SLComposeViewController post both image and url ios9SLComposeViewController 发布图像和 url ios9
【发布时间】:2016-01-16 11:00:22
【问题描述】:

我正在尝试做但它不起作用的是以下内容:使用内置的 facebook 共享器将我选择的图像和 url 发布到 facebook,问题是上传两者都不起作用,它要么是图片+文字,效果很好,要么是网址+文字,效果很好,但是当我将它们结合起来文字+图片+网址时,它会从网址获取图片,而不是我上传的图片。有什么建议?我在 iOS9 上这样做

    UIImage *tableViewScreenshot = [tblFeed screenshotOfCellAtIndexPath:idx];

    SLComposeViewController *fbSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
    [fbSheet setInitialText:@"I need your vote"];
    [fbSheet addURL:[NSURL URLWithString:str]];
    [fbSheet addImage:tableViewScreenshot];

【问题讨论】:

  • 不存在ios9问题。 FB最新api(4.7.x)问题

标签: ios facebook uiimage share slcomposeviewcontroller


【解决方案1】:

问题在于 Facebook 更改了一些政策,因此您不能将文本或图像作为默认设置。这就是为什么您看不到文字和照片的原因。这里有两种情况,一种安装了 Facebook 应用程序,另一种没有安装 Facebook 应用程序。以下是 Facebook 应用程序已安装在设备上的情况。

这是设备上未安装 Facebook 应用时的情况

这是我的代码:

 SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

[controller addURL:[NSURL URLWithString:@"https://www.google.com"]];
[controller addImage:[UIImage imageNamed:@"icon_circle"]];
[controller setInitialText:@"Bhavuk you're great!"];

[self presentViewController:controller animated:YES completion:nil];

所以如果你想分享一切,最好使用FB SDK。

【讨论】:

    【解决方案2】:

    所以目前似乎没有解决方案,我们应该找到解决方法,也许首先将所有图片上传到一个 url,然后使用 fb sdk 指向来自该 url 的图片 + 链接为不幸的是,离线图片似乎不起作用。

    【讨论】:

      【解决方案3】:

      不幸的是,即使在 iOS 10 上问题仍然存在。一个简单的解决方法是简单地删除 URL,例如:

      SLComposeViewController *fbSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
      [fbSheet setInitialText:@"I need your vote"];
      [fbSheet addImage:tableViewScreenshot]; 
      

      【讨论】:

      • 你甚至不能添加initialText。它不会出现。
      【解决方案4】:

      这不是对 OP 的直接回答,但如果您只关心在共享内容时显示文本和图像,这是一个可能的解决方案:

      如果您希望在 SlComposeView 中显示的图像和文本与您要共享的网站中存在的信息相同;你根本不需要在 iOS 端做任何特别的事情。

      如果您还创建了您共享 URL 的网页,如果您在页面上有适当的 Open Graph META 标签,Facebook 类型的 SLComposeView 将显示图像和文本这些是在您的应用内的网页上自动设置的。

      有关 Facebook Open Graph Markup 的一些信息;见https://developers.facebook.com/docs/sharing/webmasters/#markup

      【讨论】:

        【解决方案5】:

        当未安装 fb 时,我的 ios 应用程序中的 facebook 共享工作正常。我已经安装了 fb 以使用最新的 api (4.7.x),现在共享根本不起作用。我检查我是否具有 publish_actions 权限(在调用此方法之前我已在打开的图形设置、操作类型、功能中进行了“明确共享”检查。我正在验证内容(我没有收到错误)并且有委托,它的任何方法都不会被调用。

        -(void)shareWithFacebook:(NSString *)message
        {
            if ([[FBSDKAccessToken currentAccessToken] hasGranted:@"publish_actions"])
            {
                NIDINFO(@"Facebook sharing has publish_actions permission");
            }
            else
            {
                FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
                [loginManager logInWithPublishPermissions:@[@"publish_actions"]
                    handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
                    {
                        NIDERROR(@"Facebook sharing getting publish_actions permission failed: %@", error);
                    }
                ];   
            }
        
            NSMutableDictionary *properties = [NSMutableDictionary dictionaryWithDictionary: @{
                                                                                           @"og:type": @"article",
                                                                                           @"og:title": @"Bloc",
                                                                                           @"og:description": message,
                                                                                           @"og:url": @"http://getonbloc.com/download"
                                                                                               }];
        
        
        
        
            FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties];
        
                // Create the action
            FBSDKShareOpenGraphAction *action = [FBSDKShareOpenGraphAction actionWithType:@"mynamespace:Share" object:object key:@"article"];
            [action setString:@"true" forKey:@"fb:explicitly_shared"];
        
                // Create the content
            FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init];
            content.action = action;
            content.previewPropertyName = @"article";
        
                    // Share the content
            FBSDKShareAPI *shareAPI = [[FBSDKShareAPI alloc] init];
            shareAPI.shareContent = content;
            shareAPI.delegate = self;
        
            NSError *error;
            if([shareAPI validateWithError:&error] == NO)
            {
                NIDERROR(@"Facebook sharing content failed: %@", error);
            }
        
            [shareAPI share];
        }
        
         #pragma mark - FBSDKSharingDelegate
        
        - (void) sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results
        {
            NIDINFO(@"Facebook sharing completed: %@", results);
        }
        
        - (void) sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error
        {
            NIDERROR(@"Facebook sharing failed: %@", error);
        }
        
        - (void) sharerDidCancel:(id<FBSDKSharing>)sharer
        {
            NIDINFO(@"Facebook sharing cancelled.");
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2014-11-14
          • 2012-10-03
          • 1970-01-01
          • 1970-01-01
          • 2013-11-27
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多