gpt4 book ai didi

iphone - 为旧版本的 Xcode 集成 Facebook SDK 以支持 iOS 5 和 iOS 6

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:15:10 25 4
gpt4 key购买 nike

我仍在使用 XCode 4.3.2 和 iOS 5.1 基础 SDK。我想要实现的是为 iOS 5.0+ 设备集成 Facebook API。只有基本功能,例如代表发帖和获取基本用户信息。

我假设在 iOS 5 上运行的 Facebook SDK 也能在 iOS 6 上运行,但我不确定。

作为 Facebook 集成的新手,任何人都可以阐明这个问题。 (因为我正在做这个项目,升级 XCode 和 iOS SDK 不是一个选项)

  • 我应该研究哪个 iOS SDK?
  • 我可以同时支持 iOS 5 和6、使用基础 SDK 5.1 和 XCode 4.3?
  • 是否有支持这两个 iOS 版本的 API?
  • Facebook 集成的任何必要条件?

最佳答案

首先,您阅读了这篇由 Facebook 开发人员发布的文章

http://developers.facebook.com/docs/getting-started/facebook-sdk-for-ios/

在第 1 步中,它也适用于 xcode 4.3

您仔细阅读所有步骤 n 实现

在第 6 步中,您在按下 Facebook Btn 的位置编写如下代码

 - (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");
}
}];
}
}

关于iphone - 为旧版本的 Xcode 集成 Facebook SDK 以支持 iOS 5 和 iOS 6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15467558/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com