FBSessionDelegate方法不触发 [英] FBSessionDelegate methods not firing

查看:187
本文介绍了FBSessionDelegate方法不触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图实现最新的Facebook Connect SDK,我有一些麻烦。由于某种原因,代理回调 FBSessionDelegate 协议未被触发。我按照git Facebook页面上的说明,试图模仿Facebook示例应用程序,但没有运气。我在这里疯了,所以我要发布我的代码,也许有人会看到我错过的愚蠢的东西。

  #import< Foundation / Foundation.h> 
#importFBConnect.h

@interface FacebookWrapper:UIViewController< FBSessionDelegate,FBRequestDelegate,FBDialogDelegate> {
Facebook * _facebook;
NSArray * _permissions;
}

@property(readonly)Facebook * facebook;

- (void)login;

@end

#importFacebookWrapper.h

static NSString * kAppId = @1234455667778;

@implementation FacebookWrapper

@synthesize Facebook = _facebook;

- (id)init {
if(self = [super init]){
_permissions = [[NSArray arrayWithObjects:@read_stream,@offline_access,nil ]留]
_facebook = [[Facebook alloc] initWithAppId:kAppId];

}
return self;
}

- (void)dealloc {
[_facebook release];
[_permissions release];
[super dealloc];
}

- (void)login {
[_facebook authorize:_permissions delegate:self];
}

- (void)fbDidLogin {
NSLog(@登录);
}

- (void)fbDidNotLogin:(BOOL)已取消{
NSLog(@无法登录);
}

- (void)fbDidLogout {
NSLog(@Logged Out);
}

并从另一个类调用这个,

  FacebookWrapper * fw = [[FacebookWrapper alloc] init]; 
[fw login];

我在手机上看到的行为是预期的。 Facebook应用程序启动在init和权限被请求。然后,手机将我的应用程序带回到前台,但是 c $ c> FBSessionDelegate 的代表从未被触发。我使用我的应用程序ID在Facebook示例应用程序中尝试过这个,它工作正常。我不知道有什么区别。

解决方案

我想出了这个问题。在App Delegate中,您需要覆盖handleOpenURL。

   - (BOOL)应用程序:(UIApplication *)应用程序handleOpenURL:(NSURL *)url {
return [[ facebookWrapper facebook] handleOpenURL:url];
}

如果您正在创建一个包装类,因为我需要一个它在应用程序委托中的实例,因此您可以在Facebook类中调用hanleOpenURL方法。还要注意,在我的FacebookWrapper类中,我的Facebook实例有一个public readonly属性,所以我可以调用handlOpenURL。



通过这样做,你的应用程序将知道在哪里继续从Facebook应用程序获取权限返回。


I'm attempting to implement the latest Facebook Connect SDK and I'm having some troubles. For some reason the delegate callbacks for FBSessionDelegate protocol are not being fired. I've followed the instructions on the git Facebook page and tried to mimic the Facebook sample app but no luck. I'm going crazy here so I'm gonna post my code and maybe somebody will see something silly that I've missed.

#import <Foundation/Foundation.h>
#import "FBConnect.h"

@interface FacebookWrapper : UIViewController <FBSessionDelegate, FBRequestDelegate, FBDialogDelegate>{
 Facebook* _facebook;
 NSArray* _permissions;
}

@property(readonly) Facebook *facebook;

- (void)login;

@end

#import "FacebookWrapper.h"

static NSString* kAppId = @"1234455667778";

@implementation FacebookWrapper

@synthesize facebook = _facebook;

- (id)init {
 if (self = [super init]) {
  _permissions =  [[NSArray arrayWithObjects: @"read_stream", @"offline_access",nil] retain];
  _facebook = [[Facebook alloc] initWithAppId:kAppId];

 }
 return self;
}

- (void)dealloc {
 [_facebook release];
 [_permissions release];
 [super dealloc];
}

- (void)login {
 [_facebook authorize:_permissions delegate:self];
}

- (void)fbDidLogin {
 NSLog(@"Did Log In");
}

- (void)fbDidNotLogin:(BOOL)cancelled {
 NSLog(@"Failed to log in");
}

- (void)fbDidLogout {
 NSLog(@"Logged Out");
}

And to call this from another class,

FacebookWrapper *fw = [[FacebookWrapper alloc] init];
[fw login];

The behavior that I'm seeing on the phone is as expected. The Facebook app launches on init and permissions are requested. The phone then brings my app back to the foreground but the delegates for FBSessionDelegate are never fired. I've tried this in the Facebook sample app using my app ID and it worked fine. I have no idea what the difference is.

解决方案

I figured out the problem. In the App Delegate you need to override handleOpenURL.

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
    return [[facebookWrapper facebook] handleOpenURL:url];
}

If you're creating a wrapper class as I am you'll need an instance of it in the app delegate so you can call the hanleOpenURL method in the Facebook class. Also notice that there is a public readonly property for my Facebook instance in my FacebookWrapper class so I can call handlOpenURL.

By doing this your app will know where to continue when it returns from getting permissions inside of the Facebook app.

这篇关于FBSessionDelegate方法不触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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