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

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

问题描述

我想知道如何在iOS 6上使用Xcode 4.5上的新框架向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文件中:

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];
    }];

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

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