如何使用 ACAccountStore 类在 Objective-C 中的 iOS 6 上发布到 Facebook [英] How to Post to Facebook on iOS 6 in Objective-C using ACAccountStore class

查看:23
本文介绍了如何使用 ACAccountStore 类在 Objective-C 中的 iOS 6 上发布到 Facebook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何使用 Xcode 4.5 上的新框架在 iOS 6 上向 Facebook 发布状态消息.谢谢!:)

I want to know how to post a status message to Facebook on iOS 6 using the new frameworks on Xcode 4.5. Thanks! :)

推荐答案

发消息比较简单.这几乎就像 Twitter 框架一样.

Posting a message is rather simple. It's almost like with the Twitter Framework.

首先您必须导入框架:社交和帐户

First you have to import the Frameworks: Social and Accounts

#import <Social/Social.h>
#import <Accounts/Accounts.h>

在您的 .h 文件中:

In your .h file:

SLComposeViewController *mySLComposerSheet;

此代码必须包含在您的 .m 文件中的操作中:

This code has to be included inside your action in your .m file:

    if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) //check if Facebook Account is linked
    {
      mySLComposerSheet = [[SLComposeViewController alloc] init]; //initiate the Social Controller
        mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook]; //Tell him with what social platform to use it, e.g. facebook or twitter
                [mySLComposerSheet setInitialText:[NSString stringWithFormat:@"Test",mySLComposerSheet.serviceType]]; //the message you want to post
       [mySLComposerSheet addImage:yourimage]; //an image you could post
        //for more instance methods, go here: https://developer.apple.com/documentation/social/slcomposeviewcontroller#//apple_ref/doc/uid/TP40012205
        [self presentViewController:mySLComposerSheet animated:YES completion:nil];
    }
    [mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
        NSString *output;
        switch (result) {
            case SLComposeViewControllerResultCancelled:
                output = @"Action Cancelled";
                break;
            case SLComposeViewControllerResultDone:
                output = @"Post Successful";
                break;
            default:
                break;
        } //check if everything worked properly. Give out a message on the state.
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Facebook" message:output delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
        [alert show];
    }];

这篇关于如何使用 ACAccountStore 类在 Objective-C 中的 iOS 6 上发布到 Facebook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆