使用Facebook SDK 3.1支持iOS 5和iOS 6 [英] Supporting both iOS 5 and iOS 6 with the Facebook SDK 3.1

查看:94
本文介绍了使用Facebook SDK 3.1支持iOS 5和iOS 6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,目前支持使用旧的Facebook SDK for iOS通过提要对话框发布到Facebook。

I have an app that currently supports posting to Facebook through the feed dialog using the old Facebook SDK for iOS.

更新到适用于iOS的Facebook SDK 3.1后,似乎我可以:

After updating to the Facebook SDK 3.1 for iOS, it seems that I can either:


  1. 使用旧式API( Facebook.h ,实例化 Facebook ,调用对话框:...

  2. 使用新样式API( FacebookSDK.h ,使用共享 FBSession ,原生对话框)

  1. use the old style API (Facebook.h, instantiate a Facebook, call dialog:...)
  2. or use the new style API (FacebookSDK.h, use shared FBSession, native dialogs)

不同的头文件冲突并且看起来完全不兼容。

The different header files collide and seem completely incompatible.

可以我这两个都做?如果是这样,那么如何?

Can I do both? If so, then how?

推荐答案

只需包含Facebook.h即可。要首先执行此操作,请将DeprecatedHeaders文件夹复制到Frameworks项目中。 DeprecatedHeaders位于〜/ Documents / FacebookSDK / FacebookSDK.frameworks / Versions / A /下。复制时不要将项目复制到项目中,因此将它们复制为参考。

Just include Facebook.h instead. To do this first, Copy the DeprecatedHeaders folder into your Frameworks project. The DeprecatedHeaders are found under ~/Documents/FacebookSDK/FacebookSDK.frameworks/Versions/A/. When you copy it over do not copy the items into your project, so they stay copied as a reference.

接下来,在您的代码中:

Next, in your code where you have:

#import <FacebookSDK/FacebookSDK.h>

替换为:

#import "Facebook.h"

您可能会收到错误,哪个案例关闭并重新打开项目。

You may get an error, in which case close and reopen the project.

接下来,您希望声明一个Facebook对象并设置会话或在会话打开或关闭时清除它。

Next you want to declare a Facebook object and set the session or clear it whenever your Session is open or closed.

以示例为例: https://github.com/fbsamples/ios-3.1-howtos/tree/master/ShareNativeDialogsHowTo https://developers.facebook.com/docs/howtos/share-native-dialogs-ios-sdk/

您可以对该示例进行以下更改以回退到Feed对话框,而不是回退到具有共享UI的视图控制器。在ViewController.m中,您将在包含Facebook标题后进行这些更改:

You could make the following changes to that sample to fallback to the feed dialog instead of falling back to a view controller with a share UI. In ViewController.m you would make these changes after including the Facebook header:

....
@property (unsafe_unretained, nonatomic) IBOutlet UIButton *publishButton;
@property (nonatomic, retain) Facebook *facebook;

....
@synthesize authButton;
@synthesize facebook = _facebook;

....
- (void)sessionStateChanged:(NSNotification*)notification {
    if (FBSession.activeSession.isOpen) {
        self.publishButton.hidden = NO;
        [self.authButton setTitle:@"Logout" forState:UIControlStateNormal];
        if (nil == self.facebook) {
            self.facebook = [[Facebook alloc]
                             initWithAppId:FBSession.activeSession.appID
                             andDelegate:nil];
            // Store the Facebook session information
            self.facebook.accessToken = FBSession.activeSession.accessToken;
            self.facebook.expirationDate = FBSession.activeSession.expirationDate;
        }
    } else {
        self.publishButton.hidden = YES;
        [self.authButton setTitle:@"Login" forState:UIControlStateNormal];
        self.facebook = nil;
    }
}

- (void) publishUsingFeedDialog {
    // Put together the dialog parameters
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   @"Facebook SDK for iOS", @"name",
                                   @"Build great social apps and get more installs.", @"caption",
                                   @"The Facebook SDK for iOS makes it easier and faster to develop Facebook integrated iOS apps.", @"description",
                                   @"https://developers.facebook.com/ios", @"link",
                                   @"https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png", @"picture",
                                   nil];

    // Invoke the dialog
    [self.facebook dialog:@"feed" andParams:params andDelegate:nil];
}


- (IBAction)publishButtonAction:(id)sender {
    BOOL displayedNativeDialog =
    [FBNativeDialogs
     presentShareDialogModallyFrom:self
     initialText:@""
    ....

    if (!displayedNativeDialog) {
        /*ShareViewController *viewController =
        [[ShareViewController alloc] initWithNibName:@"ShareViewController"
                                              bundle:nil];
        [self presentViewController:viewController
                           animated:YES
                         completion:nil];*/
        [self publishUsingFeedDialog];
    }
}

这篇关于使用Facebook SDK 3.1支持iOS 5和iOS 6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆