Facebook iOS sdk xcode 4.3 / storyboards [英] Facebook iOS sdk xcode 4.3/storyboards

查看:112
本文介绍了Facebook iOS sdk xcode 4.3 / storyboards的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在看几周教程,无法找到在iOS中实现FB的任何故事板示例。



我有我的应用程序打开FBloginscreen,请求用户认证的应用程序,然后返回到应用程序...
像一些其他用户,fbdidlogin和handleopenurl方法不被调用。我确定我做错了事,但不知道什么。
i am在我的故事板中使用默认视图控制器(我没有创建一个vc程序的
),所以我可能需要做一些事情。



从我的理解,handleopenurl方法需要在我的应用程序委托文件,而不是在我的视图controller.m文件,但我不知道如何应该写,如何连接一个UIViewController对象我创建到VC在我的故事板(带有我正在使用的按钮和标签的故事板)中。

  ViewController.h(与FB相关)

#importFBConnect.h

@interface ViewController:UIViewController
< UIImagePickerControllerDelegate,
UINavigationControllerDelegate,FBSessionDelegate,FBDialogDelegate>
{
Facebook * facebook;
}

@property(非原子,保留)Facebook * facebook;'






  ViewController.m(与FB相关)

#importViewController.h

@implementation ViewController;
@synthesize Facebook;

- (void)LogintoFB
{
facebook = [[Facebook alloc] initWithAppId:@345872345487883andDelegate:self];
NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
if([defaults objectForKey:@FBAccessTokenKey]
&&&&default; ]。
facebook.expirationDate = [defaults objectForKey:@FBExpirationDateKey];
}
if(![facebook isSessionValid]){
[facebook authorize:nil];
NSLog(@登录);
}


}
//前iOS 4.2支持
- (BOOL)应用程序:(UIApplication *)应用程序handleOpenURL :( NSURL *)url {
NSLog(@ - 4.2 got calleld);
return [facebook handleOpenURL:url];
}
//对于iOS 4.2+支持
- (BOOL)应用程序:(UIApplication *)应用程序openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication注释:(id)annotation {
NSLog(@4.2+被调用);
return [facebook handleOpenURL:url];
}
}
- (void)fbDidLogin {
NSLog(@fbDidLogin);
NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[facebook accessToken] forKey:@FBAccessTokenKey];
[defaults setObject:[facebook expirationDate] forKey:@FBExpirationDateKey];
[默认同步];


[Facebook对话框:@feedandDelegate:self];


}'






/ p>

谢谢!

$ b如果你可以指导我在iOS中实现Facebook的故事板。 $ b

解决方案

- (BOOL)应用程序:openURL:sourceApplication:注释:应该在应用程序中实现代理。



将属性添加到appDelegate中:

  @property (非原子,强力)Facebook * facebook; 

合成它!



在你的登录到创建Facebook对象后添加此方法
(AppDelegate应该是你的appDelegate类名称)

  AppDelegate * appDelegate = [[UIApplication sharedApplication] delegate]; 
appDelegate.facebook = facebook;


i have been looking at tutorials for weeks now, not been able to find ANY storyboard examples implementing FB in iOS.

i got my app to open the FBloginscreen, request user auth for app, and then return to app... like some other users , fbdidlogin and handleopenurl method are not called. i am sure i am doing something wrong but just don't know what. i am using the default view controller in my storyboard (i did not create a vc programatically ) so i might need to do something with that.

from what i understand that handleopenurl method needs to be in my app delegate.m file and not in my view controller.m file, but i am not sure how it should be written and how to connect a UIViewController object i create to the VC in my storyboard (the one with the buttons and labels that i am using).

ViewController.h (relevant to FB)

#import "FBConnect.h"

@interface ViewController : UIViewController
<UIImagePickerControllerDelegate, 
UINavigationControllerDelegate, FBSessionDelegate, FBDialogDelegate>
{
Facebook *facebook; 
}

@property (nonatomic,retain) Facebook *facebook;'


ViewController.m (relevant to FB)

#import "ViewController.h"

@implementation ViewController;
@synthesize facebook;   

-(void)LogintoFB
{
    facebook = [[Facebook alloc] initWithAppId:@"345872345487883" andDelegate:self];
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    if ([defaults objectForKey:@"FBAccessTokenKey"] 
        && [defaults objectForKey:@"FBExpirationDateKey"]) {
        facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
        facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
    }
    if (![facebook isSessionValid]) {
        [facebook authorize:nil];
        NSLog(@"did log in");
    }


}
// Pre iOS 4.2 support
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
    NSLog(@"-4.2 got calleld");
    return [facebook handleOpenURL:url]; 
}
// For iOS 4.2+ support
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    NSLog(@"4.2+ got called");
    return [facebook handleOpenURL:url]; 
}
}
- (void)fbDidLogin {
    NSLog(@"fbDidLogin");
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
    [defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
    [defaults synchronize];


    [facebook dialog:@"feed" andDelegate:self];


}'


also if you can direct me to a tutorial that used storyboard when implementing Facebook in iOS that would be great.

thank you!

解决方案

-(BOOL)application:openURL:sourceApplication:annotation: should be implemented in the app delegate.

Add a property to the appDelegate :

@property (nonatomic, strong) Facebook *facebook;

Synthesize it!

In your logintoFB method add this after creating the Facebook object (AppDelegate should be whatever your appDelegate class name is)

AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
appDelegate.facebook = facebook;

这篇关于Facebook iOS sdk xcode 4.3 / storyboards的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆