facebook第三方登录 第三方登录facebook登录简单集成iOS APP超详细教程 - 刺猬明星娱乐网

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

来源:吃瓜网    作者:吃瓜网     2018-06-17 19:10:58   


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


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


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


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


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


点击后出现如下界面


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


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


首先下载SDK


解压并打开,把文件夹中的FBSDKCoreKit.Framework, FBSDKLoginKit.Framework, FBSDKShareKit.Framework还有Bolts.framework,官网少了这个,拖拽到你的工程

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.plistalso 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 yourAppDelegate.mfile:

#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'sInsights dashboard.

Let's test out your integration

In one of your app'sViewController.mfiles, add:

#import <FBSDKLoginKit/FBSDKLoginKit.h>

Next, add the following code to theviewDidLoadmethod:

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'sAppDelegate.mfile:

#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.