필요 프레임워크
Twitter.framework, social.framework, Accounts.framework, AdSupport.framework(이건.. 왜 필요한거지.)
개발환경
OS X : 10.9.4 메버릭스
Xcode : 5.1.1
iOS SDK : 7.1
ARC
트위 터
#import <twitter/twitter.h>
후에
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) { ACAccountStore *accountStore = [[ACAccountStore alloc] init]; ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; [accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) { if (granted) { NSArray *accountArray = [accountStore accountsWithAccountType:accountType]; if (accountArray.count > 0) { NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/1/statuses/update.json"]; NSDictionary *params = [NSDictionary dictionaryWithObject:@"SLRequest post test." forKey:@"status"]; SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodPOST URL:url parameters:params]; [request setAccount:[accountArray objectAtIndex:0]]; [request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { NSLog(@"responseData=%@", [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]); }]; } } }]; }
끝
다음 페이스북
페이스북은 앱을 만들어야한다.
페북 개발자 버전으로 앱을 만든후
#import <Accounts/Accounts.h> #import <Social/Social.h>
추가후
ACAccountStore *accountStore = [[ACAccountStore alloc] init]; ACAccountType *accountTypeFacebook = [accountStore accountTypeWithAccountTypeIdentifier: ACAccountTypeIdentifierFacebook]; NSDictionary *options = @{ACFacebookAppIdKey: @"You Facebook App Key", ACFacebookPermissionsKey: @[@"publish_actions"], ACFacebookAudienceKey: ACFacebookAudienceFriends }; [accountStore requestAccessToAccountsWithType:accountTypeFacebook options:options completion:^(BOOL granted, NSError *error) { if(granted) { NSArray *accounts = [accountStore accountsWithAccountType:accountTypeFacebook]; _facebookAccount = [accounts lastObject]; NSDictionary *parameters = @{@"access_token":_facebookAccount.credential.oauthToken, @"message": @"My first iOS 7 Facebook posting"}; NSURL *feedURL = [NSURLURLWithString:@"https://graph.facebook.com/me/feed"]; SLRequest *feedRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodPOST URL:feedURL parameters:parameters]; [feedRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { NSLog(@"Request failed, %@", [urlResponse description]); }]; } else { NSLog(@"Access Denied"); NSLog(@"[%@]",[error localizedDescription]); } }];
그럼 끝
'IT > iOS' 카테고리의 다른 글
CAKeyframeAnimation 대하여 (0) | 2017.02.02 |
---|---|
iOS10 Widget Height값 조정하기 (0) | 2016.12.26 |
[iOS] AutoLayout기반 StoryBoard에서 기준점 없는 4인치 3.5인치 대응하기 (0) | 2014.08.05 |
[iOS] Google YouTube API 이용하기 (설치, 적용, 테스트) (1) | 2014.04.25 |
오픈소스 관리 CocoaPods - 설치하기, 관리하기, update하기 (0) | 2014.04.21 |