第三方登录facebook登录简单集成iOS APP超详细教程

要成为facebook开发者首先你得是facebook用户,也就是说你得有一个facebook账号,没有的赶紧注册,全中文,注册步骤超简单,如果不会翻墙,不会注册的可以看这篇文章http://blog.csdn.net/huangxuan518/article/details/52688067

注册好后facebook账号,打开facebook开发者页面https://developers.facebook.com/,如果你已经登录facebook网站,则页面上面会出现注册按钮,如果没有登录,则会出现登录按钮,点击登录或者注册按钮


输入用户名、密码,点击登录,然后点击注册,这个注册是用facebook账号注册为开发者账号,一个账号,实际上就是多了一个开发者的身份和权限


点一下开关按钮,切换到是,表示你同意注册开发者账号,然后点注册


注册成功,点击完成。完成后会自动跳到如下界面


选择你是需要在什么端开发,苹果、安卓还是其他,我是苹果,所以选择iOS


选择一个已经存在的应用,如果没有会出现新建facebook应用编号按钮


点击后出现如下界面


选择类别后,点击创建应用编号



按照提示进行安全验证后点击提交,至此我们的应用就创建好了,然后会跳转到如何集成界面,我们按照步骤一步步来集成。


首先下载SDK


解压并打开,把文件夹中的FBSDKCoreKit.Framework, FBSDKLoginKit.Framework, FBSDKShareKit.Framework还有Bolts.framework,官网少了这个,拖拽到你的工程(注意红色的框架很重要,官网的文档少添加了这个框架,所以各种报错,我按照官网教程操作,也折腾了一天时间,后来用pod集成好的,如果你怕麻烦可以直接pod集成,超简单)

Configure your info.plist
找到 .plist 在你的 Xcode 工程中.
1. 鼠标右键点击 .plist 选择 "Open As Source Code"打开
2. 复制并粘贴 XML 到 ( <dict>...</dict> )之间.
<key>CFBundleURLTypes</key>
<array>
  <dict>
  <key>CFBundleURLSchemes</key>
  <array>
    <string>fb339911096346658</string>
  </array>
  </dict>
</array>
<key>FacebookAppID</key>
<string>339911096346658</string>
<key>FacebookDisplayName</key>
<string>LoginDemo</string>
3. If you use any of the Facebook dialogs (e.g., Login, Share, App Invites, etc.) that can perform an app switch to Facebook apps, your application's .plist also need to handle this.
<key>LSApplicationQueriesSchemes</key>
<array>
  <string>fbapi</string>
  <string>fb-messenger-api</string>
  <string>fbauth2</string>
  <string>fbshareextension</string>
</array>
Track App Installs and App Opens
App Events let you measure installs on your mobile app ads, create high value audiences for targeting, and view analytics including user demographics. To log an app activation event, first, import the Facebook SDK in your AppDelegate.m file:
#import <FBSDKCoreKit/FBSDKCoreKit.h>
Next, add the following to your app delegate:
- (void)applicationDidBecomeActive:(UIApplication *)application {
  [FBSDKAppEvents activateApp];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  [[FBSDKApplicationDelegate sharedInstance] application:application
                           didFinishLaunchingWithOptions:launchOptions];
  return YES;
}

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation {
  return [[FBSDKApplicationDelegate sharedInstance] application:application
                                                         openURL:url
                                               sourceApplication:sourceApplication
                                                      annotation:annotation];
}
When people install or engage with your app, you'll see this data reflected in your app's Insights dashboard.
Let's test out your integration
In one of your app's ViewController.m files, add:
#import <FBSDKLoginKit/FBSDKLoginKit.h>
Next, add the following code to the viewDidLoad method:
FBSDKLoginButton *loginButton = [[FBSDKLoginButton alloc] init];
loginButton.center = self.view.center;
[self.view addSubview:loginButton];
If you haven't done so already, add the following to your app's AppDelegate.m file:
#import <FBSDKCoreKit/FBSDKCoreKit.h>
- (BOOL)application:(UIApplication *)application
             openURL:(NSURL *)url
   sourceApplication:(NSString *)sourceApplication
          annotation:(id)annotation {
   return [[FBSDKApplicationDelegate sharedInstance] application:application
                                                         openURL:url
                                               sourceApplication:sourceApplication
                                                      annotation:annotation];
}
Now compile and run your app. You should see a Facebook Login button. If you can login to your app, the integration is successful.
至此你的facebook登录就集成完毕。更多操作请参照官方文档https://developers.facebook.com/docs/ios/getting-started
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值