[英]iOS Facebook login doesn't work
我有一個適用於iOS5及更高版本的應用,試圖在其中設置Facebook登錄名。 手機中集成了Facebook帳戶后,一切正常。 如果不是,則不起作用。 即使安裝了Facebook應用程序也是如此。
安裝該應用程序后,它將打開該應用程序,詢問我是否有權訪問適當的用戶數據,並返回我的應用程序,但沒有結果。 未安裝時相同。 Safari打開,要求我授權,返回,什么也沒有。
我遵循了Facebook登錄教程中提到的所有步驟。 這只是我面臨的一個問題嗎?
編輯:這是所需的代碼:
我像這樣打開一個會話:
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {
NSArray *permissions = [[NSArray alloc] initWithObjects:
@"email",
nil];
return [FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
[self sessionStateChanged:session
state:state
error:error];
}];
}
當它返回時,我猜必須調用此方法。 但是不是:
- (void)sessionStateChanged:(FBSession *)session
state:(FBSessionState) state
error:(NSError *)error
{
switch (state) {
case FBSessionStateOpen:
if (!error) {
// We have a valid session
NSLog(@"session opened");
FBRequest *me = [FBRequest requestForMe];
__block NSString *username = nil;
[me startWithCompletionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
NSDictionary<FBGraphUser> *my = (NSDictionary<FBGraphUser> *) result;
// NSLog(@"User session found: %@", my.username);
username = my.username;
}];
// /fb_access/:access_token
}
break;
case FBSessionStateClosed:
if (!error) {
// We have a valid session
NSLog(@"User session closed");
}
case FBSessionStateClosedLoginFailed:
NSLog(@"login failed, %@", error);
[FBSession.activeSession closeAndClearTokenInformation];
break;
default:
break;
}
[[NSNotificationCenter defaultCenter]
postNotificationName:FBSessionStateChangedNotification
object:session];
if (error) {
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:@"Error"
message:error.localizedDescription
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
}
有任何想法嗎?
在您的plist中添加以下鍵值對。
將以下方法添加到您的appdelgate中
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{ // attempt to extract a token from the url return
[FBSession.activeSession handleOpenURL:url];
}
iUser和Kalpesh的答案都是正確的。 將兩者結合起來對我有用。 請參考它們。 :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.