国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

IOS接入facebook詳解

瀏覽:34日期:2022-09-16 17:55:03
facebook 接入1.在 facebook 后臺 配置 ios 平臺, 獲取 fb appid

IOS接入facebook詳解

store id 可以先隨便找一個已存在的填入進去.

2.CocoaPods 引入幾個核心庫

pod ’FBSDKCoreKit’, ’~> 9.0.1’pod ’FBSDKLoginKit’, ’~> 9.0.1’pod ’FBSDKShareKit’, ’~> 9.0.1’

pod 工程構建出 靜態庫丟到 /Users/XXX/Library/Developer/Xcode/DerivedData/Build/Products 對應 真機/模擬器 的目錄下, 然項目工程編譯時可以鏈接到靜態庫

IOS接入facebook詳解

3.在 info.plist 文件的 <dict>...</dict> 內加入配置

<key>CFBundleURLTypes</key><array> <dict> <key>CFBundleURLSchemes</key> <array> <string>fb[APP_ID]</string> </array> </dict></array> <key>FacebookAppID</key><string>[APP_ID]</string><key>FacebookDisplayName</key><string>[APP_NAME]</string><key>LSApplicationQueriesSchemes</key><array> <string>fbapi</string> <string>fbapi20130214</string> <string>fbapi20130410</string> <string>fbapi20130702</string> <string>fbapi20131010</string> <string>fbapi20131219</string> <string>fbapi20140410</string> <string>fbapi20140116</string> <string>fbapi20150313</string> <string>fbapi20150629</string> <string>fbapi20160328</string> <string>fbauth</string> <string>fb-messenger-share-api</string> <string>fbauth2</string> <string>fbshareextension</string></array>

[APP_ID] 替換 fb appid.

[APP_NAME] 替換為 app 名.

4.代碼

在 app 啟動完后初始化 sdk

// AppDelegate.m @implementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {[[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions]; return YES;}- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(nonnull NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options{ [[FBSDKApplicationDelegate sharedInstance] application:application openURL:url options:options]; return YES;}

iOS 13 將打開網址的功能移到了 SceneDelegate 中

// SceneDelegate.m#import <FBSDKCoreKit/FBSDKCoreKit.h>@import FacebookCore;@implementation SceneDelegate- (void)scene:(UIScene *)scene openURLContexts:(NSSet<UIOpenURLContext *> *)URLContexts{ UIOpenURLContext *context = URLContexts.allObjects.firstObject; [FBSDKApplicationDelegate.sharedInstance application:UIApplication.sharedApplication openURL:context.URL sourceApplication:context.options.sourceApplication annotation:context.options.annotation];}

登錄, 登出, 獲取用戶信息, 展示 登錄頁面

#import 'FBHelper.h'#import <FBSDKCoreKit/FBSDKCoreKit.h>#import <FBSDKLoginKit/FBSDKLoginKit.h>@implementation FBHelperstatic FBHelper *_sharedIns = nil;+(instancetype) shareInstance { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{_sharedIns = [[self alloc] init] ; }) ;return _sharedIns ;}-(void)showLoginBtn:(UIView*)view{ FBSDKLoginButton *loginButton = [[FBSDKLoginButton alloc] init]; loginButton.center = view.center; [view addSubview:loginButton];}-(void)login:(UIViewController*)vc{ FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init]; [login logInWithPermissions:@[@'publish_actions'] fromViewController:vchandler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {if (error) { NSLog(@'--- login fail, err: %@', error); return;}FBSDKAccessToken* accessToken = [FBSDKAccessToken currentAccessToken];if (accessToken) { NSLog(@'--- login success, userId: %@, token: %@', accessToken.userID, accessToken.tokenString); return;}NSLog(@'--- login cancel'); }];}-(void)logout{ if ([FBSDKAccessToken currentAccessToken]) {NSLog(@'--- has accessToken');FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];[login logOut]; } else {NSLog(@'--- no accessToken'); }}-(void)getUserData{ if ([FBSDKAccessToken currentAccessToken]) {if ([FBSDKAccessToken currentAccessToken]) { [[[FBSDKGraphRequest alloc] initWithGraphPath:@'me?fields=id,name,token_for_business' parameters:nil] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {if (!error) { NSLog(@'--- fetched success, result: %@', result);} else { NSLog(@'--- fetched error: %@', error);} }];} } else {NSLog(@'--- no accessToken'); }}@end踩坑

編譯報錯: 找不到 swift 相關文件

報錯: Undefined symbol: __swift_FORCE_LOAD_$_

原因是因為 sdk 使用了 swift, 而工程配置里沒有配置 swift 頭文件搜索的路徑.

解決辦法很簡單: 創建一個 swift 文件即可, xcode 會提示創建橋接文件 Create Bridging Header

以上就是IOS接入facebook詳解的詳細內容,更多關于IOS接入facebook的資料請關注好吧啦網其它相關文章!

標簽: IOS
相關文章:
主站蜘蛛池模板: 久久成人国产精品 | 欧美日韩亚洲成色二本道三区 | 国产成人免费观看在线视频 | 99精品视频在线视频免费观看 | 456主播喷水在线观看 | 国产精品久久久久久搜索 | 91国内精品久久久久影院优播 | 亚洲精品99久久一区二区三区 | 欧美亚洲国产精品 | 在线免费观看日本视频 | 综合久久99久久99播放 | 亚洲精品国产精品精 | 亚洲精品99久久一区二区三区 | 国产成人精品一区二区不卡 | 久久综合久久精品 | 日本不卡一区视频 | 综合久久99久久99播放 | 成人毛片免费网站 | 九九综合视频 | 亚洲精品成人中文网 | 国产成人高清一区二区私人 | 亚洲免费一级视频 | 欧美手机手机在线视频一区 | 久久黄色视屏 | 国产91精品高清一区二区三区 | 成人 在线播放 | 国产在线一区二区 | 一个人看的免费观看日本视频www | 国产一区二区亚洲精品 | 欧美三级网站 | 午夜毛片免费观看视频 | 一级淫片免费视频 | 国产午夜亚洲精品第一区 | 欧美人成在线观看网站高清 | 国产情侣无套精品视频 | 久久久久久久国产精品影院 | 国产成人99精品免费观看 | 99精品国产兔费观看久久99 | 国产精品免费综合一区视频 | 国产在线精品福利一区二区三区 | 日本三级香港三级三级人!妇久 |