简体   繁体   English

Facebook api ios-sdk,代表不工作,fbDidLogin没有调用

[英]Facebook api ios-sdk, delegates not working, fbDidLogin not called

I have a problem with the latest iOS sdk. 我对最新的iOS sdk有疑问。 I successfully login and the application comes back but the delegation methods like fbDidLogin etc do not get called. 我成功登录并且应用程序返回但是fbDidLogin等委托方法没有被调用。

If tried it all in just one delegate file without any controllers and got it working. 如果在没有任何控制器的情况下只在一个委托文件中尝试了所有操作并使其工作。 But if I have several controllers it's not working anymore/ 但如果我有几个控制器它不再工作/

I use my self written class FacebookFetchter to deal with Facebook. 我使用自己编写的类FacebookFetchter来处理Facebook。

    //FacebookFetchter.h
    #import Foundation/Foundation.h>
    #import "FBConnect.h"

    @interface FacebookFetchter : NSObject <FBDialogDelegate,FBSessionDelegate,FBRequestDelegate> {
        Facebook *facebook;
        FacebookFetchter *facebookFetcher;  }

    @property (nonatomic, retain) IBOutlet UIWindow *window;  @property (retain) Facebook *facebook; @property (retain) FacebookFetchter
*facebookFetcher; @end


    //  FacebookFetchter.m
    #import "FacebookFetchter.h"

    @implementation FacebookFetchter @synthesize facebookFetcher,facebook;

    -(void)login{
        NSLog(@"facebook login...");
        facebook = [[Facebook alloc] initWithAppId:@"..."]; //took the id out
        NSArray *permissions =  [[NSArray arrayWithObjects: 
                                  @"read_stream", @"offline_access", @"user_photos", @"user_photo_video_tags" , @"friends_photo_video_tags", @"friends_photos",@"friends_about_me",@"user_about_me",@"manage_friendlists",@"read_friendlists",@"user_birthday",@"friends_birthday", nil] retain];

        [facebook authorize:permissions delegate:self];

    }

    ...
    -(void)fbDidLogin {
        NSLog(@"Erfolgreich eingeloggt...."); } ...

    @end

In my delegate I implemented this and I also set up the plist with the fbapp_id url scheme 在我的委托中,我实现了这个,并且我还使用fbapp_id url方案设置了plist

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { 
    NSLog(@"AppDelegate handleOpenURL");
    return [[[settings facebookFetcher] facebookFetcher] handleOpenURL:url];
}

there settings is my view controller: 那里的设置是我的视图控制器:

//settings.h @interface Settings : UIViewController {
    FacebookFetchter *facebookFetcher;
    //Facebook *facebook; }

@property (retain) FacebookFetchter
*facebookFetcher;
- (IBAction)sync; @end

//settings.m @synthesize facebookFetcher;

//within this action the facebook login is called
- (IBAction)sync{
    NSLog(@"sync...");
    facebookFetcher = [[FacebookFetchter alloc] init];
    [facebookFetcher login]; }

Any suggestions?? 有什么建议??

Thank you! 谢谢!

I just had this problem and believe I may have found your solution. 我刚遇到这个问题并相信我可能找到了你的解决方案。 When you create the app on facebook you must edit your app settings to allow for native ios app. 在Facebook上创建应用程序时,您必须编辑应用程序设置以允许本机ios应用程序。 The ios bundle id selected must match EXACTLY to your bundle ID in the app you are creating. 所选的ios软件包ID必须与您正在创建的应用程序中的软件包ID完全匹配。 Facebook states that they check this prior to authorizing your app. Facebook声明他们在授权您的应用之前检查了这一点。 Funny thing is if you remove the facebook app from the device and then try to authenticate it uses the web browser and seemingly bipasses this "security" completely. 有趣的是,如果您从设备中删除Facebook应用程序,然后尝试验证它使用Web浏览器,似乎完全转换这个“安全”。 Facebook doesn't send an error message back so it was a lot of fun to track down. Facebook不会发回错误消息,因此追踪会很有趣。 I figured I'd throw this answer out there in hopes to save some future devs some trouble. 我想我会把这个答案扔到那里,希望能为未来的开发者节省一些麻烦。 I hope this helps. 我希望这有帮助。

I had the same issue. 我遇到过同样的问题。 I had not set the permissions for facebook access. 我没有设置Facebook访问权限。 I wrote an extra line of code 我写了一行额外的代码

NSArray *permissions = [[NSArray arrayWithObjects:@"read_stream",@"offline_access","publish_stream", nil] retain];

Its working perfectly. 它的工作完美。

I encountered the same problem. 我遇到了同样的问题。 For me it was solved by unchecking the "Application does not run in background" property in the Info plist. 对我来说,它是通过取消选中Info plist中的“Application is not running in background”属性来解决的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM