将Facebook SDK与旧版Xcode集成以支持iOS 5和iOS 6 [英] Integrating Facebook SDK for older versions of Xcode to Support both iOS 5 and iOS 6
问题描述
我仍在使用XCode 4.3.2和iOS 5.1基础SDK。我想要实现的是集成Facebook API for iOS 5.0+设备。只是基本功能,例如代表发布和获取基本用户信息。
I am still using XCode 4.3.2 and iOS 5.1 base SDK. What I want to achieve is to integrate Facebook API for iOS 5.0+ devices. Just basic features such as posting on behalf and getting basic user information.
我假设Facebook SDK在iOS 5上运行,将在iOS 6上运行,但我我不确定。
I am assuming that which ever Facebook SDK works on iOS 5, will work on iOS 6, but I am not sure about that.
作为Facebook整合的新手,任何人都可以对这个问题有所了解。 (因为我正在开发项目,所以不能升级XCode和iOS SDK)
As a rookie on Facebook Integration, can anybody shed some light on this issue. ( Since I am working on the project, upgrading the XCode and the iOS SDK is not an option)
- 我应该寻找哪个iOS SDK成?
- 我可以同时支持iOS 5和
6,基本SDK 5.1和XCode 4.3吗? - 是否有支持这两个iOS版本的API?
- Facebook集成的任何必须品?
- Which iOS SDK should I be looking into?
- Can I support both iOS 5 and 6, with base SDK 5.1 and XCode 4.3?
- Is there an API supporting both iOS versions?
- Any musts for Facebook Integration?
推荐答案
首先,您阅读了Facebook开发者发表的这篇文章
First of all you read this article published from Facebook developers
http://developers.facebook.com/docs/getting-started/facebook- sdk-for-ios /
在第1步中它也适用于xcode 4.3
in step 1 it will also work for xcode 4.3
你仔细阅读了所有的步骤n
you carefully read all steps one by one n implement
在第6步中你编写代码如下Facebook Btn Pressed
In step6 you write code as follow on where Facebook Btn Pressed
- (IBAction)facebookBtnPressed:(id)sender
{
// if it is available to us, we will post using the native dialog
BOOL displayedNativeDialog = [FBNativeDialogs presentShareDialogModallyFrom:self
initialText:[NSString stringWithFormat:@"Here U write code which u want to post on facebook"]
image:[UIImage imageNamed:@"1.jpg"]
url:[NSURL URLWithString:@""]
handler:nil];
if (!displayedNativeDialog)
{
NSString *shareStr = [NSString stringWithFormat:@"Here U write code which u want to post on facebook"];
NSMutableDictionary* params = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
shareStr,@"description",
@"sharelink", @"link",
@"ImageName", @"picture",
nil];
[self performPublishAction:^{
[FBRequestConnection startWithGraphPath:@"me/feed" parameters:params HTTPMethod:@"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (error)
{
NSLog(@"error in post");
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Success" message:@"Post Successfully" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
}
}];
}];
}
//}
//===set delagate in Viewcontroller.h of mySLComposerSheet
[mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
NSString *output;
switch (result) {
case SLComposeViewControllerResultCancelled:
output = @"Action Cancelled";
break;
case SLComposeViewControllerResultDone:
output = @"Post Successfully";
break;
default:
break;
} //check if everything worked properly. Give out a message on the state.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Facebook" message:output delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
}];
}
- (void) performPublishAction:(void (^)(void)) action {
if ([[FBSession activeSession]isOpen]) {
/*
* if the current session has no publish permission we need to reauthorize
*/
if ([[[FBSession activeSession]permissions]indexOfObject:@"publish_actions"] == NSNotFound) {
[[FBSession activeSession] reauthorizeWithPublishPermissions:[NSArray arrayWithObject:@"publish_actions"]
defaultAudience:FBSessionDefaultAudienceOnlyMe
completionHandler:^(FBSession *session, NSError *error) {
action();
}];
}else{
action();
}
}else{
/*
* open a new session with publish permission
*/
[FBSession openActiveSessionWithPublishPermissions:[NSArray arrayWithObject:@"publish_actions"]
defaultAudience:FBSessionDefaultAudienceOnlyMe
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
if (!error && status == FBSessionStateOpen) {
action();
}else{
NSLog(@"error");
}
}];
}
}
这篇关于将Facebook SDK与旧版Xcode集成以支持iOS 5和iOS 6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!