此後我無法回到應用程序(如下圖所示),並且無法檢索任何用戶的數據。我正在嘗試使用Facebook登錄,它在登錄時成功,但不返回到應用程序
我已經搜索,但沒有得到任何合適的答案給我的查詢。
登錄的圖片:
結束了像以下所示的畫面,不回來到應用程序,不存在用戶數據:
此後我無法回到應用程序(如下圖所示),並且無法檢索任何用戶的數據。我正在嘗試使用Facebook登錄,它在登錄時成功,但不返回到應用程序
我已經搜索,但沒有得到任何合適的答案給我的查詢。
登錄的圖片:
結束了像以下所示的畫面,不回來到應用程序,不存在用戶數據:
Step-1. Download latest Facebook SDK (it includes major changes).
Step-2. Add FBSDKCoreKit.framework and FBSDKLoginKit.framework to
your project.
Step-3. Now go to Project > Build Phases > add
SafariServices.framework
Step-4. There are three changes in info.plist we need to verify.
4.1 Make sure you have below in your info.plist file
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string><your fb id here eg. fbxxxxxx></string>
</array>
</dict>
</array>
<key>FacebookAppID</key>
<string><your FacebookAppID></string>
<key>FacebookDisplayName</key>
<string><Your_App_Name_Here></string>
4.2 Now add below for White-list Facebook Servers, this is must for iOS 9
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>facebook.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
<key>fbcdn.net</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
<key>akamaihd.net</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
</dict>
</dict>
4.3 Add URL schemes
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fb-messenger-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
</array>
Step-5. Now open AppDelegate.m file
5.1 Add below import statements
#import <FBSDKLoginKit/FBSDKLoginKit.h>
#import <FBSDKCoreKit/FBSDKCoreKit.h>
5.2 update following following methods
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
[FBSDKAppEvents activateApp];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
return [[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
}
Step-6. Now we need to modify our Login Controller, where we do Login task
6.1 Add these imports in Login ViewController.m
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>
6.2 Add Facebook Login Button
FBSDKLoginButton *loginButton = [[FBSDKLoginButton alloc] init];
loginButton.center = self.view.center;
[self.view addSubview:loginButton];
6.3 Handle Login button click
-(IBAction)facebookLogin:(id)sender
{
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
if ([FBSDKAccessToken currentAccessToken])
{
NSLog(@"Token is available : %@",[[FBSDKAccessToken currentAccessToken]tokenString]);
[self fetchUserInfo];
}
else
{
[login logInWithReadPermissions:@[@"email"] fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
{
if (error)
{
NSLog(@"Login process error");
}
else if (result.isCancelled)
{
NSLog(@"User cancelled login");
}
else
{
NSLog(@"Login Success");
if ([result.grantedPermissions containsObject:@"email"])
{
NSLog(@"result is:%@",result);
[self fetchUserInfo];
}
else
{
[SVProgressHUD showErrorWithStatus:@"Facebook email permission error"];
}
}
}];
}
}
6.4 Get user info (name, email etc.)
-(void)fetchUserInfo
{
if ([FBSDKAccessToken currentAccessToken])
{
NSLog(@"Token is available : %@",[[FBSDKAccessToken currentAccessToken]tokenString]);
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id, name, email"}]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error)
{
NSLog(@"results:%@",result);
NSString *email = [result objectForKey:@"email"];
NSString *userId = [result objectForKey:@"id"];
if (email.length >0)
{
//Start you app Todo
}
else
{
NSLog(@「Facebook email is not verified");
}
}
else
{
NSLog(@"Error %@",error);
}
}];
}
}
整合了Facebook API和閱讀文檔here
這是一個示例代碼
if ([FBSDKProfile currentProfile]) //checking the login status
{
NSLog(@"User name: %@",[FBSDKProfile currentProfile].name);
NSLog(@"User ID: %@",[FBSDKProfile currentProfile].userID);
}
錯誤導致不因facebook集成。 它可能是viewDidLoad中顯示視圖的問題。將其更改爲viewDidAppear。是指複製@(whose view is not in the window hierarchy)
你能展示一些代碼,你有什麼嘗試 –
你添加所有的plist東西,等的appDelegate –
的OpenURL代碼是的,我已經在plist中加入每個需要的東西@ Mr.UB –