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