只需包含 Facebook.h。首先,将 DeprecatedHeaders 文件夹复制到您的 Frameworks 项目中。DeprecatedHeaders 位于 ~/Documents/FacebookSDK/FacebookSDK.frameworks/Versions/A/ 下。当您复制它时,不要将这些项目复制到您的项目中,因此它们会保持复制作为参考。
接下来,在您拥有的代码中:
#import <FacebookSDK/FacebookSDK.h>
替换为:
#import "Facebook.h"
您可能会收到错误,在这种情况下关闭并重新打开项目。
接下来,您要声明一个 Facebook 对象并设置会话或在会话打开或关闭时清除它。
以示例为例:https ://github.com/fbsamples/ios-3.1-howtos/tree/master/ShareNativeDialogsHowTo记录在这里,https://developers.facebook.com/docs/howtos/share-本机对话框-ios-sdk/
您可以对该示例进行以下更改以回退到提要对话框,而不是回退到具有共享 UI 的视图控制器。在 ViewController.m 中,您将在包含 Facebook 标头后进行这些更改:
....
@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];
}
}