工作作爲一個新手,我想嘗試Facebook和Twitter發佈使用Objective-C的Social.framework不適合的Xcode 6.3.2
所以我加了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我正在模擬器上測試它 – user580950
如果您確定'isAvailable'方法可達,您應該在實際的手機上進行測試。 –