簡體   English   中英

Facebook 與 iOS6 的集成

[英]Facebook Integration With iOS6

我正在使用以下代碼在 Facebook 上發布一些內容。

- (IBAction)post:(id)sender {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
    mySocialComposer = [[SLComposeViewController alloc]init];
    mySocialComposer = [SLComposeViewController 
    composeViewControllerForServiceType:SLServiceTypeFacebook];
    [mySocialComposer setInitialText:@"Hellooooooo World"];
    [mySocialComposer addImage:[UIImage imageNamed:@"image.jpg"]];

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


[mySocialComposer setCompletionHandler:^(SLComposeViewControllerResult result){

    NSString *outout = [[NSString alloc] init];

    switch (result) {
        case SLComposeViewControllerResultCancelled:
            outout = @"Post Cancled";
            break;
            case SLComposeViewControllerResultDone:
            outout = @"Post Successfull";

        default:
            break;
    }


    UIAlertView *myalertView = [[UIAlertView alloc]initWithTitle:@"FaceBook" 
    message:outout delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
    [myalertView show];

}];
}

}

我正在使用上述方法從 iOS 應用程序在 Facebook 上發布。如果我發布的內容包括圖片和一些文本,則它成功地發布在 Facebook 上。 但是,當我嘗試在沒有圖片的情況下在 Facebook 上發帖時,我只是為了這個目的而注釋掉了以下行。

  [mySocialComposer addImage:[UIImage imageNamed:@"image.jpg"]];

在此過程中,我收到一條錯誤警報,提示無法發送此帖子,因為與 Facebook 的連接丟失。 有什么方法可以在沒有圖片的情況下在 Facebook 上發帖。 提前致謝。

您可以將添加圖像設置為零。 你應該可以發帖了。

if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
    {
        SLComposeViewController* mySocialComposer = [SLComposeViewController
                            composeViewControllerForServiceType:SLServiceTypeFacebook];
        [mySocialComposer setInitialText:@"Hellooooooo World"];
        [mySocialComposer addImage:nil];

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


        [mySocialComposer setCompletionHandler:^(SLComposeViewControllerResult result){

            NSString *outout = [[NSString alloc] init];

            switch (result) {
                case SLComposeViewControllerResultCancelled:
                    outout = @"Post Canceled";
                    break;
                case SLComposeViewControllerResultDone:
                    outout = @"Post Successfull";

                default:
                    break;
            }

根據 Apple 關於SLComposeViewController的官方文檔,您會看到它說

返回值

返回一個布爾值,指示文本是否已成功設置。 討論

如果文本不適合當前可用的字符空間或視圖控制器已經呈現給用戶(因此無法更改),則此方法返回 NO。 字符限制取決於目標服務並由服務提供商記錄。 有關受支持服務的文檔鏈接,請參閱 SLRequest 類參考中的“表 1 社會服務個人文檔站點”。

因此,如果該控制器已經顯示,它將無法工作。 嘗試不同的文本並再次查看。

你能去掉嗎

mySocialComposer = [[SLComposeViewController alloc]init];

你不應該那樣做。

[mySocialComposer setInitialText:@"Hellooooooo World"];
[mySocialComposer addImage:[UIImage imageNamed:@"image.jpg"]];

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

在設置完成處理程序后放置這些代碼行。

還要從那里刪除 UIAlertView 並將其放在完成處理程序中以用於錯誤情況。

暫無
暫無

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

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