iOS6에 Facebook 프레임 워크를 앱에 통합하는 방법은 무엇입니까?
-
11-12-2019 - |
문제
나는 앱의 사용자 벽에 물건을 게시 할 수있는 오래된 페이스 북 그래프 API를 사용하고 있습니다.iOS6 Facebook이 OS에 통합 되었기 때문에.물건을 게시하기 위해 어떻게 사용할 수 있습니까?트위터 프레임 워크와 같은 방식으로 사용하고 싶습니다.
TWTweetComposeViewController *tweetViewController = [[TWTweetComposeViewController alloc] init];
[tweetViewController setInitialText:@"bla bla bla"];
[self dismissModalViewControllerAnimated:YES];
[self presentModalViewController:tweetViewController animated:YES];
. 해결책
iOS 6부터는 Twitter, Facebook 및 Weibo와 같은 지원되는 모든 서비스 유형에 대해 SlcomposeViewController를 사용할 수 있습니다. 참고 : social.framework 을 추가하는 것을 잊지 마십시오.
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *fb = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[fb setInitialText:@"bla bla bla"];
[self presentModalViewController:fb animated:YES];
}
. 다른 팁
게시물이 "내 앱 이름을 통해"로 가려면 Slrequest를 사용할 수 있습니다.
-(IBAction)postMessage:(id)sender
{
// Create the URL to the end point
NSURL *postURL = [NSURL URLWithString:@"https://graph.facebook.com/me/feed"];
NSString *link = [[NSString alloc] init];
NSString *message = [[NSString alloc] init];
NSString *picture = [[NSString alloc] init];
NSString *name = [[NSString alloc] init];
NSString *caption = [[NSString alloc] init];
NSString *description = [[NSString alloc] init];
link = @"http://developer.apple.com/library/ios/#documentation/Social/Reference/Social_Framework/_index.html%23//apple_ref/doc/uid/TP40012233";
message = @"Testing Social Framework";
picture = @"http://www.stuarticus.com/wp-content/uploads/2012/08/SDKsmall.png";
name = @"Social Framework";
caption = @"Reference Documentation";
description = @"The Social framework lets you integrate your app with supported social networking services. On iOS and OS X, this framework provides a template for creating HTTP requests. On iOS only, the Social framework provides a generalized interface for posting requests on behalf of the user.";
NSDictionary *postDict = @{
@"link": link,
@"message" : message,
@"picture" : picture,
@"name" : name,
@"caption" : caption,
@"description" : description
};
SLRequest *postToMyWall = [SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodPOST URL:postURL parameters:postDict];
FacebookAccountManager* sharedManager = [FacebookAccountManager sharedAccount];
[postToMyWall setAccount:sharedManager.facebookAccount];
[postToMyWall performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
{
if (error) {
// If there is an error we populate the error string with error
_errorString = [NSString stringWithFormat:@"%@", [error localizedDescription]];
// We then perform the UI update on the main thread. All UI updates must be completed on the main thread.
[self performSelectorOnMainThread:@selector(updateErrorString) withObject:nil waitUntilDone:NO];
}
else
{
NSLog(@"Post successful");
NSString *dataString = [[NSString alloc] initWithData:responseData encoding:NSStringEncodingConversionAllowLossy];
NSLog(@"Response Data: %@", dataString);
}
}];
// Tidy Up
link = nil;
message = nil;
picture = nil;
name = nil;
caption = nil;
description = nil;
postDict = nil;
postToMyWall = nil;
postURL = nil;
}
.
제휴하지 않습니다 StackOverflow