我正在尝试将 Facebook sdk 实现到我的应用程序中,但在显示写入墙/提要弹出窗口时遇到问题。我可以从我的应用程序成功登录 Facebook。首先它把我带到本机 Facebook 应用程序,一旦我授权它,它就把我带回我的默认应用程序,没有任何反应。该对话框没有出现,我看到的只是我创建的空视图。这是我的代码,如果有人知道为什么这不起作用,我将不胜感激。
谢谢
fbViewController.h
#import <UIKit/UIKit.h>
#import "FBConnect.h"
@interface fbViewController : UIViewController <UIApplicationDelegate,FBSessionDelegate,FBDialogDelegate>
{
Facebook *facebook;
}
@property (nonatomic, retain) Facebook *facebook;
@end
fbViewController.m
#import "fbViewController.h"
#define kAppId @"xxxxxxx"
- (void)viewDidLoad
{
[super viewDidLoad];
facebook = [[Facebook alloc] initWithAppId:@"xxxxxxxxxxx" 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];
}
}
- (void)fbDidLogin {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
[defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
[defaults synchronize];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
kAppId, @"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];
}
myAppDelegate.m
// Pre iOS 4.2 support
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [facebook handleOpenUrl:url];
}
// For iOS 4.2+ support
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [facebook handleOpenURL:url];
}