0

我正在尝试将 Facebook SDK 集成到我的应用程序中,它可以在我的模拟器中完美运行。当我将它安装到我的 iPhone 上并尝试运行它时,它会向我显示一条警报,其中指出“myapp 需要访问您的个人资料、好友列表等”,而当我选择允许它时,什么也没有发生 - 它需要这些权限。

我已经在我的 iPhone 上安装了 Facebook 应用程序,多次尝试注销并返回,但没有使用。

但是,当我进入设置并删除 Facebook 详细信息时,它可以完美运行:

在此处输入图像描述

我怎样才能解决这个问题?

4

3 回答 3

0

好的,我知道出了什么问题。让我知道,无论你做什么都是对的,但你想要的结果需要别的东西。

尝试这个 -

首先在您的应用程序委托中实现所有 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];
}

我希望你现在能得到你想要的。:)

于 2013-08-26T08:16:13.173 回答
0

我使用以下方式为我工作:

-(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;
}
于 2013-08-24T07:49:58.460 回答
0

记得将您的应用程序添加到 Facebook 开发人员/应用程序!

如果没有,您将无法与他们的服务器交互...

于 2013-08-24T07:52:43.290 回答