【问题标题】:Social.framework doesn't work for Xcode 6.3.2Social.framework 不适用于 Xcode 6.3.2
【发布时间】:2015-11-09 00:37:19
【问题描述】:

作为一个新手,我想尝试使用 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

【问题讨论】:

  • 你是在 iPhone 还是模拟器上测试?
  • @YunusErenGüzel 我正在模拟器上测试它
  • 如果您确定isAvailable 方法可以访问,您应该在实际手机上进行测试。

标签: ios objective-c xcode facebook twitter


【解决方案1】:

想到几件事:

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

【讨论】:

  • 1) 是的,按钮在情节提要中连接。 (2) 如何检查 -isAvailableForServiceType: 是否合法返回 NO ?
  • 设置断点,看看你的if语句是否被输入。该方法可能在模拟器或其他东西中不可用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-15
  • 2014-06-22
  • 2017-01-22
相关资源
最近更新 更多