簡體   English   中英

使用SLComposeViewController在Facebook中共享圖像

[英]Share Image in Facebook using SLComposeViewController

我正在我的應用程序中實現Facebook共享。 必須共享帶有說明的圖像,但是,一旦點擊或單擊該圖像,應將其導航到Web門戶。

但是,可以使用feed對話框來實現,但是我想使用社交框架來做到這一點。 這可能嗎 ?

使用SLComposeViewController,您無法為用戶預填充Facebook帖子。 該方法存在於社交框架中,但幾年前Facebook禁止應用程序執行此操作,因此即使您使用:

BOOL initialTextSet = [fbController setInitialText:@"Check out this article."];

該方法將返回YES,但實際上不會填充該文本。

如果您想對發布的內容進行更多控制,則必須將Facebook SDK添加到您的項目中。 我實際上是在較早版本的應用程序中采用了這種方法,但是維護起來很麻煩。 最后,我只使用了Apple本機框架。 它比FB SDK更容易使用,並且具有前瞻性。 無需懷疑您的下一個iOS版本構建是否突然失去了Facebook共享,因為SDK需要更新(而且經常需要更新)。

似乎無法進行這種定制。 但是,要從本機框架中實現所需的功能,網頁網址應包含元數據,如以下文章中所述。

如何使用og meta標簽進行Facebook分享

用這個

SLComposeViewController * fbController=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];


if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
        SLComposeViewControllerCompletionHandler __block completionHandler=^(SLComposeViewControllerResult result){

        [fbController dismissViewControllerAnimated:YES completion:nil];

        switch(result){
        case SLComposeViewControllerResultCancelled:
        default:
        {
            NSLog(@"Cancelled.");

        }
            break;
        case SLComposeViewControllerResultDone:
        {
            NSLog(@"Posted.");
        }
            break;
    }};

    [fbController addImage:[UIImage imageNamed:@"1.jpg"]];
    [fbController setInitialText:@"Check out this article."];
    [fbController addURL:[NSURL URLWithString:@"URLString"]];
    [fbController setCompletionHandler:completionHandler];
    [self presentViewController:fbController animated:YES completion:nil];
}
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {

 SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

 SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
 if (result == SLComposeViewControllerResultCancelled)
 {
 DebugLog(@"Cancelled");
 }
 else
 {
 [UIUtils alertView:NSLocalizedString(@"FB POST SUCCEEDED", nil) withTitle:NSLocalizedString(@"SUCCESS", nil)];
 }

 [controller dismissViewControllerAnimated:YES completion:Nil];
 };
 controller.completionHandler =myBlock;

 //Adding the Text to the facebook post value from iOS
 [controller setInitialText:NSLocalizedString(@"SHARE TWITTER", nil)];

 //Adding the URL to the facebook post value from iOS
 //        [controller addURL:[NSURL URLWithString:@"http://www.mobile.safilsunny.com"]];

 //Adding the Image to the facebook post value from iOS
 [controller addImage:self.crushCardImage];

 [self.view.window.rootViewController presentViewController:controller animated:YES completion:Nil];
 }
 else
 {
 [UIUtils alertView:NSLocalizedString(@"NO FB", nil) withTitle:NSLocalizedString(@"FAILURE", nil)];
 }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM