2015-10-17 89 views
13

我正在尝试做的事情,它不工作是以下内容:张贴我的choise的图像,并使用内置的Facebook共享器的Facebook的URL,问题是它无法上传两个,它是图片+文字和作品很好或网址+文本和工程很好,但是当我结合他们的文本+图片+网址它从网址获取图片,而不是我上传的图片。有什么建议么?我对iOS9SLComposeViewController post both image and url 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]; 
+0

没有ios9问题。 FB最新api(4.7.x)问题 –

回答

2

因此,目前似乎没有解决方案,我们应该为它找到解决方法,可能会首先将所有图片上传到网址,然后使用fb sdk指向该网址的图片+链接作为一个离线图片似乎并不幸运。

-1

这样做我有Facebook的共享在我的iOS应用程序工作正常时FB没有安装。并且我已经安装了fb以使用最新的api(4.7.x),现在共享并不起作用。我检查了我是否拥有publish_actions权限(我在调用此方法之前执行了此操作,在开放图形设置,操作类型和功能中检查了'expicitly shared'。我正在验证内容(我没有收到错误)并拥有代表,没有它的方法被调用。

-(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."); 
} 
6

的问题是,Facebook已经改变了一些政策,通过这个你不能有存在一个默认的文本或图像。这就是为什么你没有看到文本和照片,下面是安装Facebook应用程序和另一个未安装Facebook应用程序的情景2,下面是Facebook应用程序已经安装在设备上的情况 enter image description here

而这一次是当设备

enter image description here

上没有安装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 。

1

不幸的是,问题依旧,甚至在iOS 10.一个简单的解决方法是简单地丢弃URL,例如:

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

甚至无法添加initialText。它不会出现。 – Ans

0

这不是一个直接的答案OP,但在你只在乎是什么情况显示同时分享一些文字和图片,这里是一个可能的解决方案:

如果你想你的SlComposeView内显示的图像和文字是一样的存在,网站,你会内的信息分享;你根本不需要在iOS端做任何特别的事情。

如果你是谁,也创造了你分享的URL的网页的人,你应该在页面适当的Open Graph META标签,SLComposeView类型Facebook将显示图像和设定于文字您的应用程序中的网页自动运行。

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