登录后 Facebook IOS SDK 导航到另一个控制器不起作用

Posted

技术标签:

【中文标题】登录后 Facebook IOS SDK 导航到另一个控制器不起作用【英文标题】:Facebook IOS SDK navigate to another controller after login not working 【发布时间】:2014-12-31 12:34:32 【问题描述】:

我已按照Facebook ios SDK Docs 中提到的所有步骤进行操作。

我的 ViewController.h 文件如下

#import <UIKit/UIKit.h>
#import <FacebookSDK/FacebookSDK.h>
@interface ViewController : UIViewController <FBLoginViewDelegate>


@end

我的 ViewController.m 文件如下

#import "AppDelegate.h"
#import "ViewController.h"
#import "pageLike.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet FBLoginView *fbloginbtn;
@property (weak, nonatomic) IBOutlet UILabel *name;
@property (weak, nonatomic) IBOutlet FBProfilePictureView *fbimage;
@property (weak, nonatomic) IBOutlet UILabel *status;

@end

@implementation ViewController

- (void)viewDidLoad 
[super viewDidLoad];

self.fbloginbtn.readPermissions = @[@"public_profile",@"email",@"user_friends"];
self.fbloginbtn.publishPermissions = @[@"publish_actions"];
self.fbloginbtn.delegate =self;
// Do any additional setup after loading the view, typically from a nib.
if(FBSessionStateOpen)
    pageLike *pg=[self.storyboard instantiateViewControllerWithIdentifier:@"pageLike"];
    [self.navigationController pushViewController:pg animated:YES];



- (void)didReceiveMemoryWarning 
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.


-(void)loginViewFetchedUserInfo:(FBLoginView *)loginView user:(id<FBGraphUser>)user
self.fbimage.profileID=user.id;
self.name.text = user.name;




@end

并且错误跟踪如下

2014-12-31 17:59:09.830 fbconnect[2274:96019] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** setObjectForKey: object cannot be nil (key: __view_impression_identifier__)'
*** First throw call stack:
(
    0   CoreFoundation                      0x0110a946 __exceptionPreprocess + 182
    1   libobjc.A.dylib                     0x009f2a97 objc_exception_throw + 44
    2   CoreFoundation                      0x00ffdbbc -[__NSDictionaryM setObject:forKey:] + 940
    3   CoreFoundation                      0x0107a210 -[NSMutableDictionary setObject:forKeyedSubscript:] + 48
    4   fbconnect                           0x0007c1b8 -[FBViewImpressionTracker logImpressionWithView:identifier:parameters:] + 76
    5   fbconnect                           0x000a8428 -[FBLikeControl drawRect:] + 183
    6   UIKit                               0x0175c95c -[UIView(CALayerDelegate) drawLayer:inContext:] + 519
    7   QuartzCore                          0x04ef9d61 -[CALayer drawInContext:] + 118
    8   QuartzCore                          0x04ef9c97 _ZL16backing_callbackP9CGContextPv + 96
    9   QuartzCore                          0x04dde4fe CABackingStoreUpdate_ + 2788
    10  QuartzCore                          0x04ef9c2f ___ZN2CA5Layer8display_Ev_block_invoke + 93
    11  QuartzCore                          0x04f2f416 x_blame_allocations + 15
    12  QuartzCore                          0x04ef9a95 _ZN2CA5Layer8display_Ev + 1591
    13  QuartzCore                          0x04ef9ce6 -[CALayer _display] + 33
    14  QuartzCore                          0x04ef9456 _ZN2CA5Layer7displayEv + 142
    15  QuartzCore                          0x04ef9cc0 -[CALayer display] + 33
    16  QuartzCore                          0x04eedef6 _ZN2CA5Layer17display_if_neededEPNS_11TransactionE + 322
    17  QuartzCore                          0x04eedf7c _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 38
    18  QuartzCore                          0x04e4c3c6 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 284
    19  QuartzCore                          0x04e4d78c _ZN2CA11Transaction6commitEv + 392
    20  QuartzCore                          0x04e4de58 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
    21  CoreFoundation                      0x0102d9de __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
    22  CoreFoundation                      0x0102d920 __CFRunLoopDoObservers + 400
    23  CoreFoundation                      0x0102335a __CFRunLoopRun + 1226
    24  CoreFoundation                      0x01022bcb CFRunLoopRunSpecific + 443
    25  CoreFoundation                      0x010229fb CFRunLoopRunInMode + 123
    26  GraphicsServices                    0x028da24f GSEventRunModal + 192
    27  GraphicsServices                    0x028da08c GSEventRun + 104
    28  UIKit                               0x016d18b6 UIApplicationMain + 1526
    29  fbconnect                           0x00079a0d main + 141
    30  libdyld.dylib                       0x060dcac9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

我创建了另一个名为 pageLike 的视图控制器,一旦用户登录,我需要在其中实际导航

【问题讨论】:

【参考方案1】:

检查 pageLike 控制器并删除所有 fb 登录视图控制器,因为它们可能会产生问题。

【讨论】:

我错过了我尝试添加新控制器的那部分,它工作正常:)

以上是关于登录后 Facebook IOS SDK 导航到另一个控制器不起作用的主要内容,如果未能解决你的问题,请参考以下文章

Facebook SDK Objective-C 登录后触发事件

IOS FACEBOOK SDK,从FB注销并登录后

更新 iOS 9 和 Facebook sdk 4.6 后,登录窗口未打开

用户更改密码后 Facebook iOS SDK 不会打开登录 UI (iOS 6)

登录成功后将视图导航到另一个视图

更改权限后无法在 Cordova iOS 上使用 Facebook SDK 登录