由于Facebook SDK每小时都在变化,因此很难获得适用于当前SDK版本的实际教程。一些变化是激进的!
我正在尝试上传照片......但问题是我的FBSessionDelegate方法“fbDidLogin”永远不会被调用。我登录,回到应用程序,但没有任何反应:/
我想我的Session Delegate存在问题:/
这个新SDK的主要变化是关于委托...你在视图中设置委托一次加载而不是设置它[facebook authorize:permissions delegate:self];
我尝试过发现视频(教程):http://developers.facebook.com/blog/post/532/
这是我的.H
#import "Facebook.h"
@interface sampleClass : UIViewController
<FBSessionDelegate, FBRequestDelegate> {
Facebook * facebook;
}
@property (strong, nonatomic) Facebook * facebook;
- (IBAction)uploadPhoto:(id)sender;
这是我的.M
- (void)viewDidLoad {
[super viewDidLoad];
facebook = [[Facebook alloc] initWithAppId:kAppId andDelegate:self];
}
- (IBAction)uploadPhoto:(id)sender {
NSArray* permissions = [[NSArray alloc] initWithObjects:
@"offline_access", @"publish_stream", nil];
[facebook authorize:permissions];
}
#pragma mark - Facebook Session Delegate Methods
- (void)fbDidLogin {
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"mov"];
NSData *videoData = [NSData dataWithContentsOfFile:filePath];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
videoData, @"video.mov",
@"video/quicktime", @"contentType",
@"Video Test Title", @"title",
@"Video Test Description", @"description",
nil];
[facebook requestWithGraphPath:@"me/videos"
andParams:params
andHttpMethod:@"POST"
andDelegate:self];
}
-(void)fbDidNotLogin:(BOOL)cancelled {
NSLog(@"did not login");
}
#pragma mark - Facebook Request Delegate Methods
- (void)request:(FBRequest *)request didLoad:(id)result {
if ([result isKindOfClass:[NSArray class]]) {
result = [result objectAtIndex:0];
}
NSLog(@"Result of API call: %@", result);
}
- (void)request:(FBRequest *)request didFailWithError:(NSError *)error {
NSLog(@"Failed with error: %@", [error localizedDescription]);
}
#pragma mark - Support SSO for Facebook
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [self.facebook handleOpenURL:url];
}
答案 0 :(得分:0)
您需要输入您的应用程序代表。
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
并将'Facebook * facebook'变量放在Application Delegate和View Controller都可以访问的位置。
您可以按照本指南进一步说明
https://developers.facebook.com/docs/mobile/ios/build/#implementsso
答案 1 :(得分:0)
你有没有工作?您是否尝试过使用Hackbook作为示例?它以sdk下载为例。此链接指的是演示应用程序,但它现在称为Hackbook。 http://thinkdiff.net/facebook/how-to-develop-facebook-application-for-iphone/
密歇根州