【问题标题】:FacebookSDK in iOS Does not show close button and not able to closeiOS 中的 FacebookSDK 不显示关闭按钮且无法关闭
【发布时间】:2012-11-25 09:35:24
【问题描述】:

您好,我已经为 iOS 6 应用程序集成了 Facebook SDK。Facebook 身份验证和共享工作完美,但没有规定关闭 FB 对话框。即。当FB对话框打开时,只有在验证成功后才会关闭。没有关闭或导航返回的规定。如何制作关闭按钮。我使用的代码sn-p如下所示。提前致谢。

-(NSDictionary *)shareFacebook
{

    NSDictionary *userInfo;
    if (FBSession.activeSession.isOpen)
    {

        if (FBSession.activeSession.isOpen)
        {

            [self.closeButton setHidden:NO];
            [FBRequestConnection startForMeWithCompletionHandler:^(FBRequestConnection *connection, id<FBGraphUser> user, NSError *error) {

                NSUserDefaults *standardUserDefaults=[NSUserDefaults standardUserDefaults];
                [standardUserDefaults setObject:user forKey:@"fbUserInfo"];



                    [self.manager authenticateUserUsingFB:[user objectForKey:@"email"]];


            }];
        }

    }
    else{
        NSLog(@"fb session not active.");
        [self openSessionWithAllowLoginUI:YES];
    }
    return userInfo;
}

- (void)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {

    NSArray *permissions = [[NSArray alloc] initWithObjects:

                            @"user_photos",
                            @"publish_actions",
                            @"read_stream",
                            @"friends_photos",
                            @"email" ,nil];

    [FBSession setActiveSession:[[FBSession alloc] initWithPermissions:permissions]];


    [[FBSession activeSession] openWithBehavior:FBSessionLoginBehaviorForcingWebView

                              completionHandler:^(FBSession *session,

                                                  FBSessionState state,

                                                  NSError *error) {

                                  NSLog(@" state=%d",state);
                                  if(FBSessionStateOpen)
                                  {
                                      [self shareFacebook];
                                  }
                              }];

}

【问题讨论】:

    标签: objective-c facebook facebook-graph-api ios6 ios5


    【解决方案1】:

    通过将 FacebookSDKResources.bundle 文件从 FacebookSDK.framework/Resources 文件夹拖到 Project Navigator 的 Frameworks 部分来添加 Facebook SDK for iOS 资源包。 http://developers.facebook.com/docs/getting-started/facebook-sdk-for-ios/

    【讨论】:

    • 这对我帮助很大,伙计。谢谢
    【解决方案2】:

    我知道是什么导致了这个错误!按钮和图标视图(对话框右上角有两个视图——关闭按钮和图标视图)实际上存在(您可以单击它查看)但不可见。这是因为该项目无法看到位于FBDialog.bundle 中的实际图像文件。您应该从捆绑包中复制这些图像并将它们添加到项目中,然后直接设置图像。您的 init 方法可能如下所示:

     //This is your FBDialog.m file
    - (id)init {
      if (self = [super initWithFrame:CGRectZero]) {
        .........
    
        UIImage* iconImage = [UIImage imageNamed:@"fbicon.png"];
        UIImage* closeImage = [UIImage imageNamed:@"close.png"];
    
        _iconView = [[UIImageView alloc] initWithImage:iconImage];
        [self addSubview:_iconView];
    
        _closeButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
        [_closeButton setImage:closeImage forState:UIControlStateNormal];
        [_closeButton addTarget:self action:@selector(cancel)
          forControlEvents:UIControlEventTouchUpInside];
    
        .........
    

    可能有更好的方法来修复这个错误,但这对我有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-18
      • 2019-01-09
      • 2021-01-24
      • 1970-01-01
      • 2018-12-20
      • 2022-01-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多