您好我已经为iOS 6应用程序集成了Facebook SDK.Facebook身份验证&分享工作完美,但没有规定关闭FB对话box.ie.当FB Dialogue框打开时,它将在认证成功后关闭。没有提供关闭或导航回来。如何创建一个关闭按钮。我正在使用的代码片段如下所示。谢谢提前。
-(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];
}
}];
}
答案 0 :(得分:5)
通过将FacebookSDKResources.bundle文件从FacebookSDK.framework / Resources文件夹拖到Project Navigator的Frameworks部分,添加适用于iOS资源包的Facebook SDK。 http://developers.facebook.com/docs/getting-started/facebook-sdk-for-ios/
答案 1 :(得分: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];
.........
可能有更好的方法可以解决这个问题,但这对我有用。