我正在尝试使用Parse.com为我的ios应用程序实现Facebook登录,并且还没有成功,因为没有太多关于如何逐步实现目标c。
所以我希望这个问题对他人也有帮助。
在app delegate
我有:
didFinishLaunchingWithOptions:
[[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
[PFFacebookUtils initializeFacebookWithApplicationLaunchOptions:launchOptions];
- (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];
}
现在这里是我不确定将下面的代码放在哪个方法的地方:
1]对于我的Facebook登录按钮,我在故事板中的loginViewController中创建了一个视图,并使该视图成为一个FBlogin按钮。然后我将该视图连接到此IBOutlet
@property (weak, nonatomic) IBOutlet FBSDKLoginButton *loginButton;
然后在loginView.m中我有这个:
- (void)viewDidLoad {
[super viewDidLoad];
FBSDKLoginButton *loginButton = [[FBSDKLoginButton alloc] init];
self.loginButton.readPermissions = @[@"username", @"email", @"password"];
}
用它登录用户,但没有更多的事情发生回到登录界面,Facebook用户登录到Facebook。 所以我激活了按钮进入视图,现在我不确定何时放入注册登录的代码。
- (void)_loginWithFacebook{
[PFFacebookUtils logInInBackgroundWithReadPermissions:@[@"username", @"email", @"password"] block:^(PFUser *user, NSError *error) {
if (!user) {
// NSLog(@"Uh oh. The user cancelled the Facebook login.");
} else if (user.isNew) {
NSString *message = [NSString stringWithFormat:@"@%@ logged in! (%@)",
[PFUser currentUser].username, [PFUser currentUser].objectId];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Logged in!"
message:message
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
} else {
// NSLog(@"User logged in through Facebook!");
[self.navigationController popToRootViewControllerAnimated:NO];
}
}];
}
- (void)saveFacebookUser:(PFUser *)user UserData:(NSDictionary *)userData Picture:(NSString *)pictureUrl Thumbnail:(NSString *)thumbnailUrl
{
NSString *username = userData[@"username"];
NSString *email = userData[@"email"];
user.username = username;
user.username = [username lowercaseString];
user.email = email;
[user saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error)
{
if (error == nil)
{
}
else {
}
}];
}
一旦用户登录,我想让他们转到rootView,并让facebook用户成为PFUser.CurrentUser并显示用户名
因此,请帮助我登录用户将其带入rootView并将其用户名保留为解析用户。
答案 0 :(得分:0)
您是否在Info.plist文件中添加了键值???
此键值通过以下步骤添加到info.plist文件中:
<dict>
&amp;之间</dict>
以下<key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleURLSchemes</key> <array> <string>fb+”YOUR Facebook APP ID”</string> </array> </dict> </array> <key>FacebookAppID</key> <string>”YOUR Facebook APP ID”</string> <key>FacebookDisplayName</key> <string>Integration using Swift</string> <key>LSApplicationQueriesSchemes</key> <array> <string>fbapi</string> <string>fbauth2</string> </array> <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>