Facebook iOS SDK 3.0 - 会话未打开 [英] Facebook iOS SDK 3.0 - session not open
问题描述
我正在使用最新的Facebook iOS SDK 3.0
I am using the latest Facebook iOS SDK 3.0
我需要在登录过程中的帮助:
I need a help in in the login process:
首先,我在 AppDelegate.h
中声明此属性:
First I declare this property in AppDelegate.h
:
@property (nonatomic, strong) FBSession *session;
在ViewController类中,我得到这个在代码中使用它:
and in ViewController class I get this to use it in the code as this:
AppDelegate *delegate = [[UIApplication sharedApplication]delegate];
[delegate.session someproperty];
我还在ViewController中从 viewDidLoad
I also have this method in ViewController that get called from viewDidLoad
:
-(void)login
{
AppDelegate *delegate = [[UIApplication sharedApplication]delegate];
[delegate.session accessToken];
NSLog(@"%d",delegate.session.isOpen);
if (!delegate.session.isOpen)
{
delegate.session = [[FBSession alloc] init];
if (delegate.session.state == FBSessionStateCreatedTokenLoaded)
{
[delegate.session openWithCompletionHandler:^(FBSession *session,
FBSessionState status,
NSError *error)
{
NSLog(@"%d", delegate.session.isOpen); // First Line //////////////////
}];
}
NSLog(@"%@", delegate.session.description); // Second Line //////////////////
}
}
在Facebook应用获得授权之后,第一个 NSLog
打印为零,第二个 NSLog
表示会话
状态是 FBSessionStateCreated
不是 FBSessionStateOpen
?
After the facebook app get authorized the firs NSLog
print zero, and the second NSLog
indicate that the session
state is FBSessionStateCreated
not FBSessionStateOpen
?
这是第二个 NSLog
的输出:
2012-08-16 18:37:24.327 Facebook3[2418:f803] <FBSession: 0x6890ff0, state: FBSessionStateCreated, loginHandler: 0x0, appID: 193716877424306, urlSchemeSuffix: , tokenCachingStrategy:<FBSessionTokenCachingStrategy: 0x6890f20>, expirationDate: (null), refreshDate: (null), attemptedRefreshDate: 0001-12-30 00:00:00 +0000, permissions:()>
我在这里缺少什么。
注意:在 https://developers.facebook.com 的应用设置中,我将应用配置为:
1-配置为iOS SSO:启用
2- iOS本地深度链接:启用
3- iOS软件包ID:com.mycompany.appname
Note : in the app setting at https://developers.facebook.com I configure the app as this: 1- Configured for iOS SSO: Enabled 2- iOS Native Deep Linking: Enabled 3- iOS Bundle ID : com.mycompany.appname
推荐答案
我为我的项目使用了这个框架。它工作正常
这是我的相关代码
i used this framework for my project. it works properly. this is my related code
-(IBAction)logIn:(id)sender;
{
AppDelegate *appdelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
if (!FBSession.activeSession.isOpen) {
[appdelegate sessionOpener];
}
else {
[self loginHelp];
}
我的sessionOpener函数是;
and my sessionOpener function is;
-(void) sessionOpener
{
[FBSession sessionOpenWithPermissions:nil
completionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
// session might now be open.
if (!error) {
[self.viewController loginHelp];
}
}];
NSLog(@"%d", FBSession.activeSession.isOpen);
NSLog(@"%@", FBSession.activeSession.description );
}
它适用于我。可能对您有帮助。
it works for me. may be helpful to you.
,我的控制台打印为:
1
2012-08-16 22:24:55.899 TaraftarlikOyunu[838:c07] <FBSession: 0xd2512c0, state: FBSessionStateOpen, loginHandler: 0xd250240, appID: 433294056715040, urlSchemeSuffix: , tokenCachingStrategy:<FBSessionTokenCachingStrategy: 0xd24fda0>, expirationDate: 2012-10-15 19:02:34 +0000, refreshDate: 2012-08-16 19:05:03 +0000, attemptedRefreshDate: 0001-12-30 00:00:00 +0000, permissions:(
)>
这篇关于Facebook iOS SDK 3.0 - 会话未打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!