我正在嘗試將Facebook SDK實現到我的應用程序中,但遇到了顯示寫入牆/供稿彈出窗口的問題。我可以從我的應用程序成功登錄Facebook。首先,我需要訪問原生Facebook應用程序,一旦我授權它,它會將我帶回默認應用程序,而不會發生任何事情。該對話框沒有出現,我看到的只是我創建的空白視圖。這是我的代碼,如果有人知道爲什麼這不起作用,我將不勝感激。Popup Facebook feed iOS
感謝
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];
}
你是否嘗試設置斷點以確保你的[facebook對話框:andParams:andDelegate:]被調用? –
我會首先在fbDidLogIn中使用NSLog語句(假設您在代碼中的某處發送某種請求),請求:didLoad:查看登錄是否成功以及是否實際接收數據。如果你實際登錄並獲取數據,那麼你的問題就是你如何將這些數據放在視圖中。但是根據我們在這裏所知,沒有辦法知道這一點。 – geraldWilliam
@Inturbidus該應用程序永遠不會進入fbDidLogin。我不知道爲什麼。有什麼建議麼?謝謝 –