的Facebook SDK登錄問題我想Facebook的SDK集成到我的應用程序,它在我的模擬器完美的作品。當我安裝它在我的iPhone,並嘗試運行它,它讓我看到一個警告,其中指出,「MYAPP需要訪問您的個人資料,好友列表等」,當我選擇允許它什麼也沒有發生 - 它需要這些權限。iPhone上
我已經安裝在我的iPhone上的Facebook應用程序,試圖註銷並回過很多次,但沒有使用。
但是,當我去設置和刪除Facebook的細節,它完美的作品:
我該如何解決這個問題?
的Facebook SDK登錄問題我想Facebook的SDK集成到我的應用程序,它在我的模擬器完美的作品。當我安裝它在我的iPhone,並嘗試運行它,它讓我看到一個警告,其中指出,「MYAPP需要訪問您的個人資料,好友列表等」,當我選擇允許它什麼也沒有發生 - 它需要這些權限。iPhone上
我已經安裝在我的iPhone上的Facebook應用程序,試圖註銷並回過很多次,但沒有使用。
但是,當我去設置和刪除Facebook的細節,它完美的作品:
我該如何解決這個問題?
我用下面的方式及其對我工作:
-(void)openFacebookAuthentication
{
NSArray *permission = [NSArray arrayWithObjects:kFBEmailPermission,kFBUserPhotosPermission, nil];
FBSession *session = [[FBSession alloc] initWithPermissions:permission];
[FBSession setActiveSession: [[FBSession alloc] initWithPermissions:permission] ];
[[FBSession activeSession] openWithBehavior:FBSessionLoginBehaviorForcingWebView completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
switch (status) {
case FBSessionStateOpen:
[self getMyData];
break;
case FBSessionStateClosedLoginFailed: {
// prefer to keep decls near to their use
// unpack the error code and reason in order to compute cancel bool
NSString *errorCode = [[error userInfo] objectForKey:FBErrorLoginFailedOriginalErrorCode];
NSString *errorReason = [[error userInfo] objectForKey:FBErrorLoginFailedReason];
BOOL userDidCancel = !errorCode && (!errorReason || [errorReason isEqualToString:FBErrorLoginFailedReasonInlineCancelledValue]);
if(error.code == 2 && ![errorReason isEqualToString:@"com.facebook.sdk:UserLoginCancelled"]) {
UIAlertView *errorMessage = [[UIAlertView alloc] initWithTitle:kFBAlertTitle
message:kFBAuthenticationErrorMessage
delegate:nil
cancelButtonTitle:kOk
otherButtonTitles:nil];
[errorMessage performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:YES];
errorMessage = nil;
}
}
break;
// presently extension, log-out and invalidation are being implemented in the Facebook class
default:
break; // so we do nothing in response to those state transitions
}
}];
permission = nil;
}
KSR:你的代碼在哪裏? –
好的,我知道了什麼錯誤。讓我知道,無論你做的是正確的,但你想要的結果將需要別的東西。
試試這個 -
首先實現所有的應用程序委託Facebook的SDK委託方法。現在
- (IBAction)loginWithFacebookButtonTapped:(id)sender
{
IntubeAppDelegate *delegat = (IntubeAppDelegate*)[[UIApplication sharedApplication] delegate];
[delegat doLoginAndSwitch];
}
,在你的appDelegate -
-(void) doLoginAndSwitch
{
[self openSessionWithAllowLoginUI:YES];
}
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI
{
NSArray *permissions = [NSArray arrayWithObjects:@"email", nil];
return [FBSession openActiveSessionWithPublishPermissions:permissions
defaultAudience:FBSessionDefaultAudienceFriends
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
[self sessionStateChanged:session
state:state
error:error];
}];
}
-(BOOL)openSessionWithAllowPublishStreamPermission:(BOOL)allowLoginUI
{
NSArray *permissions = [NSArray arrayWithObjects:@"publish_actions",@"publish_stream", nil];
[[FBSession activeSession] requestNewPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceEveryone completionHandler:^(FBSession *session, NSError *error){
}];
return YES;
}
- (void)sessionStateChanged:(FBSession *)session
state:(FBSessionState)state
error:(NSError *)error
{
switch (state) {
case FBSessionStateOpen:
if(!error)
{
// NSLog(@"FBSessionStateOpen :- logged in");
[self openSessionWithAllowPublishStreamPermission:YES];
// Your code
}
}
}
而且切換回您的應用程序 -
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
return [FBSession.activeSession handleOpenURL:url];
}
我希望你會得到你現在的願望。 :)
發佈您的代碼。 – keen
符合您bundal Id和對AppKey? –