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];
}
}];
}
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/
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:May be there is a better way to fix this bug but this worked for me.