gpt4 book ai didi

xcode - 如何在 iOS 6 中使用 ACAccountStore 类在 Objective-C 中发布到 Facebook

转载 作者:行者123 更新时间:2023-11-30 05:14:31 26 4
gpt4 key购买 nike

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

最佳答案

发布消息非常简单。这几乎就像 Twitter 框架一样。

首先你必须导入框架:社交和账户

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

在你的 .h 文件中:

SLComposeViewController *mySLComposerSheet;

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

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

关于xcode - 如何在 iOS 6 中使用 ACAccountStore 类在 Objective-C 中发布到 Facebook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12505458/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com