Hey Apple Community,
i am currently learning iOS Programming with Swift and a little bit Objective C and now i am at a point i don't move forward.
I do not understand how to make the following things work:
I have a Facebook Login written in C, and a Parse Login written in Swift and in the future I want to write in Swift.
So i need a few contact details (first name, last name, email, id, facebookurl..) from the Objective C converted to Swift, so i can use it their.
I read the apple documentation but i don't understand it.
So what i must change or do to use this data in Swift.
Here is my code from the facebook login:
Thanks a lot! 😉
#import "LoginViewController.h"
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>
#import "DashboardViewController.h"
#import "MBProgressHUD.h"
@interface LoginViewController (){
/!
*properties of name, email,fbid and fburl.
*/
NSString* name;
NSString* email;
NSString* fbid;
NSURL *facebookurl;
}
@end
@implementation LoginViewController
- (void)viewDidLoad {
[super viewDidLoad];
/
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
/
}
/!
*Fb signin button clicked.
*/
- (IBAction)facebookLoginClicked:(id)sender {
/
[[NSUserDefaults standardUserDefaults]setObject:@"facebookSuccess" forKey:@"loginSuccess"];
[[NSUserDefaults standardUserDefaults]synchronize];
/
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions:@[@"email", @"user_friends", @"public_profile"] fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
NSLog(@"Process error");
} else if (result.isCancelled) {
NSLog(@"Cancelled");
}
/
else {
if ([result.grantedPermissions containsObject:@"email"])
{
NSLog(@"Logged in");
NSLog(@"result is:%@",result);
[self fetchedUser];
}
}
}];
}
/!
*This contains details of the fetched user details.
*/
-(void)fetchedUser{
NSLog(@"the user token is :%@", [FBSDKAccessToken currentAccessToken]);
/
if ([FBSDKAccessToken currentAccessToken] != nil && ![[FBSDKAccessToken currentAccessToken] isEqual: @"null"])
{
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id, name, link, first_name, last_name, picture.type(large), email, birthday, bio ,location ,friends ,hometown , friendlists"}]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error)
{
/
name = result[@"name"];
email = result[@"email"];
fbid = result[@"id"];
facebookurl = [NSURL URLWithString:[NSString stringWithFormat:@"https:/
/Alter method to access the profile pic*/
/
/
[[NSUserDefaults standardUserDefaults]setObject:name forKey:@"name"];
[[NSUserDefaults standardUserDefaults]synchronize];
[[NSUserDefaults standardUserDefaults]setObject:email forKey:@"email"];
[[NSUserDefaults standardUserDefaults]synchronize];
[[NSUserDefaults standardUserDefaults]setObject:fbid forKey:@"fbid"];
[[NSUserDefaults standardUserDefaults]synchronize];
[[NSUserDefaults standardUserDefaults]setObject:[facebookurl absoluteString] forKey:@"facebookurl"];
[[NSUserDefaults standardUserDefaults]synchronize];
/
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
[self performSegueWithIdentifier:@"facebookSuccess" sender:self];
[MBProgressHUD hideHUDForView:self.view animated:YES];
}
else
{
NSLog(@"Error %@",error);
}
}];
}
}
@end