ios - Social.framework 不适用于 Xcode 6.3.2

标签 ios objective-c xcode facebook twitter

作为新手,我想尝试使用 objective-c 的 Facebook 和 Twitter Post

所以我添加了 2 个按钮,添加了操作,还添加了社交框架。当我运行代码并单击 Tweet 或 Facebook 按钮时,没有任何反应,我是否遗漏了一些东西。我正在模拟器上测试它,这有什么区别吗?

这是我的头文件 SocialSharingViewController.h

#import <UIKit/UIKit.h>

@interface SocialSharingViewController : UIViewController

- (IBAction)postToTwitter:(id)sender;
- (IBAction)postToFacebook:(id)sender;

@end

这是我的 .m 文件 SocialSharingViewController.m

#import "SocialSharingViewController.h"
#import <Social/Social.h>

@interface SocialSharingViewController ()

@end

@implementation SocialSharingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (IBAction)postToTwitter:(id)sender {
    if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
    {
        SLComposeViewController *tweetSheet = [SLComposeViewController
                                               composeViewControllerForServiceType:SLServiceTypeTwitter];
        [tweetSheet setInitialText:@"Great fun to learn iOS programming"];
        [self presentViewController:tweetSheet animated:YES completion:nil];
    }
}

- (IBAction)postToFacebook:(id)sender {
    NSLog(@"clicked facebook button");
    if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
        SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

        [controller setInitialText:@"First post from my iPhone app"];
        [self presentViewController:controller animated:YES completion:Nil];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end

最佳答案

我想到了一些事情:

  • 您是否将 .xib 中的按钮连接到代码中的 IBAction 方法?
  • -isAvailableForServiceType: 是否合法地返回 NO,阻止它们显示?

关于ios - Social.framework 不适用于 Xcode 6.3.2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32032359/

相关文章:

ios - SHA-256 散列与 key swift

ios - 如何将图像处理为如下所示的黑白图像?

ios - 传递数据 VC 委托(delegate) iOS

xcode - 音乐即将在iPhone应用程序中播放时出错

iPhone 崩溃日志 - 是什么原因?

ios - 当我在我的一个文件夹中创建一个新的 viewController 时,该 Controller 包含在一个名为 : ctive-C 的文件夹中

ios - 具有开发供应的 .ipa 和具有临时分发供应配置文件的 .ipa 之间有什么区别?

ios - 创建对象的 NSMutableArray

objective-c - 如何从 NSString 中提取/拆分数字和字符串

ios - 面部识别 iOS