Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Facebook iOS SDK:使用Facebook登录失败_Ios_Facebook - Fatal编程技术网

Facebook iOS SDK:使用Facebook登录失败

Facebook iOS SDK:使用Facebook登录失败,ios,facebook,Ios,Facebook,在互联网上阅读了一些参考资料后,我决定使用Facebook iOS SDK,而不是XCode社交框架 因为我在我的应用程序上需要的是“使用facebook登录”会话,我在示例文件夹下跟踪其名为SessionLoginSample的示例代码,但当我添加代码时,它不起作用。这些代码是在iPad模拟器上成功构建的,但当我点击按钮时,什么也没发生 你能告诉我我错过了哪里吗。。。谢谢你 我有这个AppDelegate.h: #import <UIKit/UIKit.h> #import <

在互联网上阅读了一些参考资料后,我决定使用
Facebook iOS SDK
,而不是
XCode社交框架

因为我在我的应用程序上需要的是“使用facebook登录”会话,我在示例文件夹下跟踪其名为SessionLoginSample的示例代码,但当我添加代码时,它不起作用。这些代码是在iPad模拟器上成功构建的,但当我点击按钮时,什么也没发生

你能告诉我我错过了哪里吗。。。谢谢你

我有这个AppDelegate.h:

#import <UIKit/UIKit.h>
#import <FacebookSDK/FacebookSDK.h>

@class ViewController;

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) ViewController *viewController;

@property (strong, nonatomic) FBSession *session;

@end
#import "AppDelegate.h"
#import "ViewController.h"

@implementation AppDelegate

@synthesize window = _window;
@synthesize viewController = _viewController;
@synthesize session = _session;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    [FBAppEvents activateApp];
    [FBAppCall handleDidBecomeActiveWithSession:self.session];
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    [self.session close];
}


- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation {
    // attempt to extract a token from the url
    return [FBAppCall handleOpenURL:url
                  sourceApplication:sourceApplication
                        withSession:self.session];
}

#pragma mark Template generated code

@end
#import "ViewController.h"
#import "AppDelegate.h"

@interface ViewController ()

@property (strong, nonatomic) UINavigationController* navController;

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

- (void) alertWithTitle:(NSString *)title andMessage:(NSString *)msg
{
    UIAlertView *message = [[UIAlertView alloc] initWithTitle:title
                                                      message:msg
                                                     delegate:nil
                                            cancelButtonTitle:@"OK"
                                            otherButtonTitles:nil];
    [message show];
}

- (IBAction)loginFacebook {
    AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];

    if (appDelegate.session.isOpen) {
        [appDelegate.session closeAndClearTokenInformation];

    } else {
        if (appDelegate.session.state != FBSessionStateCreated) {
            appDelegate.session = [[FBSession alloc] init];
        }

        [appDelegate.session openWithCompletionHandler:^(FBSession *session,
                                                         FBSessionState status,
                                                         NSError *error) {
            [self alertWithTitle:(@"FB Login") andMessage:(@"It works!!")];
        }];
    } }
}
@end
myViewController.h

#import <UIKit/UIKit.h>
#import <FacebookSDK/FacebookSDK.h>

@interface ViewController : UIViewController
@property (strong, nonatomic) IBOutlet UITextField *fieldEmail;
@property (strong, nonatomic) IBOutlet UITextField *fieldPassword;
@property (strong, nonatomic) IBOutlet UILabel *titleLogin;
@property (strong, nonatomic) IBOutlet UILabel *labelOutput;

- (IBAction)buttonRegister;
- (IBAction)buttonLogin;
- (IBAction)loginFacebook;
- (IBAction)loginTwitter;

@end

更新:我已经在我的项目的框架文件夹下添加了FacebookSDK.framework,还修改了plist文件,因为:

在我看来,你是一个类似于任务中的-setActiveSession的调用

if (appDelegate.session.state != FBSessionStateCreated) 
{
   appDelegate.session = [[FBSession alloc] init];
   [FBSession setActiveSession:appDelegate.session];
}
一个月前,我在集成iOS Facebook sdk 3.5时遇到了同样的问题,我发现您当前的活动会话不会自动设置。因此,只要有机会获得不同的会话实例,我就有这个调用

而且

里面

    - (void)applicationDidBecomeActive:(UIApplication *)application
   {
      [FBAppEvents activateApp];
      [FBAppCall handleDidBecomeActiveWithSession:self.session];
   }
您不应该使用self.session,而应该使用FBSession.activeSession来确保FBAppCall获得与它获得结果的FBSession相同的实例


希望对您有所帮助。

在设备中检查您是否已授予使用您正在使用的应用程序的权限,以及您是否已在设备上注册facebook应用程序……检查这两个步骤,然后在设备上运行该应用程序。我想这样一来,它将在登录页面上显示facebook登录。我已经安装/运行了这个应用程序在我的iPad上,所以我相信我的设备已经获得了许可。我还在我的Facebook帐户上创建了一个应用程序。由于这是一个新应用,而且由于按钮不起作用,我还没有在我的设备上授权。希望您已经按照示例应用中提供的所有步骤进行了操作。您可以通过转到“设置”来检查在ipad上使用您正在使用的应用的facebook设置所授予的权限。我也遇到过同样的问题,只是因为这个原因,我在点击facebook按钮时什么都不做。请先检查一下。同时我会给你提供一些我有的链接。检查一下他的链接,把所有答案都检查一遍-。。也许对你有帮助。谢谢