2015-10-17 90 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