[英]Facebook SDK IOS xcode
Hi all i'm making an iOS application using Xcode. 大家好我正在使用Xcode制作iOS应用程序。 i want to implement Facebook login and get the username and the facebookid and send it to a webview link, is that possible?
我想实现Facebook登录并获取用户名和facebookid并将其发送到webview链接,这可能吗?
the first problem is that, even by following the Facebook guide at this link : https://developers.facebook.com/docs/ios/getting-started i can't let the Facebook login runs, the iOS simulator starts but it ends with this output message : 第一个问题是,即使按照此链接上的Facebook指南: https : //developers.facebook.com/docs/ios/getting-started我不能让Facebook登录运行,iOS模拟器启动但它结束使用此输出消息:
2015-04-21 19:51:20.069 DONAT[3899:96245] +[FBSDKButton defaultIcon]: unrecognized selector sent to class 0x103800908
2015-04-21 19:51:20.073 DONAT[3899:96245] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[FBSDKButton defaultIcon]: unrecognized selector sent to class 0x103800908'
*** First throw call stack:
(
0 CoreFoundation 0x00000001040e9f35 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000103d82bb7 objc_exception_throw + 45
2 CoreFoundation 0x00000001040f0f4d +[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010404927c ___forwarding___ + 988
4 CoreFoundation 0x0000000104048e18 _CF_forwarding_prep_0 + 120
5 DONAT 0x00000001037b6207 -[FBSDKButton configureButton] + 47
6 DONAT 0x00000001037b5509 -[FBSDKButton awakeFromNib] + 73
7 UIKit 0x00000001049dee75 -[UINib instantiateWithOwner:options:] + 2010
8 UIKit 0x000000010483df98 -[UIViewController _loadViewFromNibNamed:bundle:] + 242
9 UIKit 0x000000010483e588 -[UIViewController loadView] + 109
10 UIKit 0x000000010483e7f9 -[UIViewController loadViewIfRequired] + 75
11 UIKit 0x000000010483ec8e -[UIViewController view] + 27
12 UIKit 0x000000010475dca9 -[UIWindow addRootViewControllerViewIfPossible] + 58
13 UIKit 0x000000010475e041 -[UIWindow _setHidden:forced:] + 247
14 UIKit 0x000000010476a72c -[UIWindow makeKeyAndVisible] + 42
15 UIKit 0x0000000104715061 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2628
16 UIKit 0x0000000104717d2c -[UIApplication _runWithMainScene:transitionContext:completion:] + 1350
17 UIKit 0x0000000104716bf2 -[UIApplication workspaceDidEndTransaction:] + 179
18 FrontBoardServices 0x0000000107bc42a3 __31-[FBSSerialQueue performAsync:]_block_invoke + 16
19 CoreFoundation 0x000000010401f53c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
20 CoreFoundation 0x0000000104015285 __CFRunLoopDoBlocks + 341
21 CoreFoundation 0x0000000104015045 __CFRunLoopRun + 2389
22 CoreFoundation 0x0000000104014486 CFRunLoopRunSpecific + 470
23 UIKit 0x0000000104716669 -[UIApplication _run] + 413
24 UIKit 0x0000000104719420 UIApplicationMain + 1282
25 DONAT 0x000000010378d743 main + 115
26 libdyld.dylib 0x00000001068bc145 start + 1
27 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
this is my app delegate.h 这是我的app delegate.h
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
this is my app delegate.m 这是我的app delegate.m
#import "AppDelegate.h"
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[FBSDKLoginButton class];
return YES;
} //AGGIUNTO DA FB DEVELPER
- (void)applicationWillResignActive:(UIApplication *)application {
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
[FBSDKAppEvents activateApp]; //AGGIUNTO DA FACEBOOK DEVELOPER GUIDE
}
- (void)applicationWillTerminate:(UIApplication *)application {
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation];
}//AGGIUNTO DA fbdeveloper
@end
And in my Main.storyboard i've got a view controller named Login with his relative Login.h and Login.m and the View as tells Facebook with FBSDKButton class 在我的Main.storyboard中,我有一个名为Login的视图控制器,他的相对Login.h和Login.m以及View as告诉Facebook使用FBSDKButton类
EDIT 编辑
ok login works, but i can't show another view controller after login 确定登录工作,但登录后我无法显示另一个视图控制器
- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView
user:(id<FBGraphUser>)user {
NSString * storyboardName = @"dashBoardViewController";
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:@"dashBoardViewController"];
[self presentViewController:vc animated:YES completion:nil];
}
this is my method now, and the view controller has got a storyboard id = dashBoardViewController but it still not works 这是我的方法,视图控制器有一个故事板id = dashBoardViewController,但它仍然不起作用
This may not be quite on point to your question, but it's at least related. 这可能与你的问题无关,但它至少是相关的。 While the instructions from Facebook say to set the button's class to
FBSDKButton
, that doesn't work and crashes as you describe above. 虽然来自Facebook的说明将按钮的类设置为
FBSDKButton
,但FBSDKButton
,它不起作用并崩溃。 Setting the button's class to FBSDKLoginButton
seems to work. 将按钮的类设置为
FBSDKLoginButton
似乎可行。
i have got the same exact error. 我有同样的错误。
After inspection, it's appear i need in my project : FBSDKCoreKit, FBSDKLoginKit and FBSDKShareKit. 经过检查,我的项目似乎需要:FBSDKCoreKit,FBSDKLoginKit和FBSDKShareKit。
If you use cocoapods, this is the line in Podfile : 如果您使用cocoapods,这是Podfile中的行:
pod 'FBSDKCoreKit'
pod 'FBSDKLoginKit'
pod 'FBSDKShareKit'
after pod install
, add this to your bridging header .h file : pod install
后,将其添加到您的桥接头.h文件中:
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKShareKit/FBSDKShareKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>
In your storyboard, define a view with class type FBSDKLoginButton
: 在故事板中,定义类型为
FBSDKLoginButton
的视图:
I was facing the same issue. 我面临同样的问题。 u need to import FBSDKLoginKit in your view controller then use FBSDKLoginButton.
你需要在视图控制器中导入FBSDKLoginKit然后使用FBSDKLoginButton。 find the code snipped
找到被剪断的代码
import FBSDKLoginKit 导入FBSDKLoginKit
class ViewController: UIViewController { class ViewController:UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let fbButton = FBSDKLoginButton()
fbButton.center = self.view.center
self.view.addSubview(fbButton)
// Do any additional setup after loading the view, typically from a nib.
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.