我会尽量做到尽可能深入。我跟着在Facebook上开发站点的引导和结束了这段代码:Facebook SSOw登录和发布图片无效。
在我AppDelegate.h:
@interface AppDelegate : UIResponder <UIApplicationDelegate, FBSessionDelegate> {
...
Facebook *facebook;
}
@property (nonatomic, retain) Facebook *facebook;
在我指定了Facebook的appid等
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [facebook handleOpenURL:url];
}
- (void)fbDidLogin {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
[defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
[defaults synchronize];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.menuViewController = [[MenuViewController alloc] init];
UIView *menuView = self.menuViewController.view;
facebook = [[Facebook alloc] initWithAppId:@"172938549507285" 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];
}
...
}
的AppDelegate中实施
和只是柜面我的应用程序是永远不会关闭我已经在实现了相同的方法:
- (void)applicationWillEnterForeground:(UIApplication *)application
{
facebook = [[Facebook alloc] initWithAppId:@"172938549507285" 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];
NSLog(@"Facebook session is not valid");
}
NSLog(@"Application Entering Foreground.. setting segue to login flag");
[defaults setObject:@"yes" forKey:@"shouldgotologin"];
[defaults synchronize];
}
然而,即使在实现所有这些之后,我从来没有得到Facebook登录窗口打开...它只是从来没有出现...它曾经出现过一次...但我现在从来没有看到我的控制台日志中的任何东西....我没有真的知道为什么......我很迷茫。有人能帮我吗?请不要直接到我的Facebook开发站点...这是我刚刚从感谢!
好的谢谢。它是过期的accessToken,所以我扩展了它,它又开始工作了。 – jimbob 2012-08-09 16:00:31