FacebookSDK in iOS Does not show close button and

2019-07-15 09:24发布

Hi I have integrated Facebook SDK for an iOS 6 app.The Facebook authentication & sharing works perfectly but there are no provision to close the FB Dialogue box.ie. When FB Dialogue box opens,it will be closed only after authentication success.No provision to close or navigate back.How can I make a close button.The code snippet I am using has been shown below.Thanks in Advance.

-(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];
                                  }
                              }];

}

2条回答
成全新的幸福
2楼-- · 2019-07-15 09:30

Add the Facebook SDK for iOS resource bundle by dragging the FacebookSDKResources.bundle file from the FacebookSDK.framework/Resources folder into the Frameworks section of your Project Navigator. http://developers.facebook.com/docs/getting-started/facebook-sdk-for-ios/

查看更多
Emotional °昔
3楼-- · 2019-07-15 09:48

I know what causes this bug! The button and the icon view (there are two views on the top right corner of the dialog box - a close button and an icon view) are actually exist (you can click it to see) but not visible. This is because the project can't see actual image files which are located in FBDialog.bundle. You should copy those images from the bundle and add them to project then set images directly. Your init method may look something like this:

 //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];

    .........

May be there is a better way to fix this bug but this worked for me.

查看更多
登录 后发表回答