IOS - Facebook SDK fbDidLogin未调用 - 初始化视图控制器。 [英] IOS - Facebook SDK fbDidLogin not called -- initialize view controllers.
问题描述
- (BOOL)应用程序:(UIApplication *)应用程序handleOpenURL:(NSURL *)url {
return [[controller facebook] handleOpenURL:url];
}
from fbDidLogin未调用
问题是我不确定如何分配init视图控制器。这是我的.h应用程序委托:
#import< UIKit / UIKit.h>
#importFBConnect.h
@interface fb2AppDelegate:UIResponder< UIApplicationDelegate,FBSessionDelegate> {
Facebook * facebook;
UIViewController * fb2ViewController;
}
@property(强,非原子)UIWindow *窗口;
@property(强,非原子)Facebook * facebook;
@property(nonatomic,strong)UIViewController * fb2ViewController;
@end
和.m:
#importfb2AppDelegate.h
@implementation fb2AppDelegate
@synthesize window = _window;
@synthesize Facebook;
@synthesize fb2ViewController;
- (BOOL)应用程序:(UIApplication *)应用程序didFinishLaunchingWithOptions :( NSDictionary *)launchOptions
{
self.fb2ViewController = [[UIViewController alloc] init];
facebook = [[Facebook alloc] initWithAppId:@key_hereandDelegate:self];
NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
if([defaults objectForKey:@FBAccessTokenKey]
&&&&default; ]。
facebook.expirationDate = [defaults objectForKey:@FBExpirationDateKey];
}
if(![facebook isSessionValid]){
[facebook authorize:nil];
}
返回YES;
}
- (BOOL)应用程序:(UIApplication *)应用程序handleOpenURL:(NSURL *)url {
return [[fb2ViewController facebook] handleOpenURL:url] ;
}
- (void)fbDidLogin {
NSLog(@fbdidlogin);
NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[facebook accessToken] forKey:@FBAccessTokenKey];
[defaults setObject:[facebook expirationDate] forKey:@FBExpirationDateKey];
[默认同步];
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@key_here,@app_id,
@http://developers.facebook.com/docs/reference/对话框/,@link,
@http://fbrell.com/f8.jpg,@picture,
@Facebook Dialogs,@name,
@参考文档,@caption,
@使用对话框与用户交互,@description,
nil];
[facebook dialog:@feedandParams:params andDelegate:self];
}
对于视图控制器...我没有把任何代码放进去。
我收到的错误是:
没有可见的@interface为'UIViewController'声明选择器' Facebook'
我做错了什么?
thx!
好的,你需要做:
[facebook handleOpenURL:url]。
您正在使用 facebook
作为选择器而不是一个对象。
另外..你需要设置 facebook.sessionDelegate = self
,以便代理方法 fbDidLogin
可以调用。
希望这有帮助!
I followed the Facebook SDK tutorial from Facebook step by step. I have everything working besides fbDidLogin getting called... the authorization process works fine. I've been told to do:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [[controller facebook] handleOpenURL:url];
}
the problem is is that I'm not exactly sure how to alloc init my view controller. Here is my .h for app delegate:
#import <UIKit/UIKit.h>
#import "FBConnect.h"
@interface fb2AppDelegate : UIResponder <UIApplicationDelegate, FBSessionDelegate> {
Facebook *facebook;
UIViewController *fb2ViewController;
}
@property (strong, nonatomic) UIWindow *window;
@property (strong,nonatomic) Facebook *facebook;
@property (nonatomic, strong) UIViewController *fb2ViewController;
@end
and the .m :
#import "fb2AppDelegate.h"
@implementation fb2AppDelegate
@synthesize window = _window;
@synthesize facebook;
@synthesize fb2ViewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.fb2ViewController = [[UIViewController alloc] init];
facebook = [[Facebook alloc] initWithAppId:@"key_here" andDelegate:self];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:@"FBAccessTokenKey"]
&& [defaults objectForKey:@"FBExpirationDateKey"]) {
facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
}
if (![facebook isSessionValid]) {
[facebook authorize:nil];
}
return YES;
}
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [[fb2ViewController facebook] handleOpenURL:url];
}
- (void)fbDidLogin {
NSLog(@"fbdidlogin");
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
[defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
[defaults synchronize];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"key_here", @"app_id",
@"http://developers.facebook.com/docs/reference/dialogs/", @"link",
@"http://fbrell.com/f8.jpg", @"picture",
@"Facebook Dialogs", @"name",
@"Reference Documentation", @"caption",
@"Using Dialogs to interact with users.", @"description",
nil];
[facebook dialog:@"feed" andParams:params andDelegate:self];
}
as for the view controllers... I haven't put any code in them.
the error that I am receiving is:
no visible @interface for 'UIViewController' declares the selector 'Facebook'
what am i doing wrong?
thx!
Okay, You need to do:
[facebook handleOpenURL:url].
You are currently using facebook
as a selector instead of an object.
Also.. you need to set facebook.sessionDelegate = self
, so that the delegate method fbDidLogin
can get called.
Hope this helps!
这篇关于IOS - Facebook SDK fbDidLogin未调用 - 初始化视图控制器。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!