• Apfeltalk ändert einen Teil seiner Allgemeinen Geschäftsbedingungen (AGB), das Löschen von Useraccounts betreffend.
    Näheres könnt Ihr hier nachlesen: AGB-Änderung
  • Das Monatsmotto Juli lautet -- Kitsch as Kitsch can -- Jeder von Euch kann dafür ganz individuell bestimmen, was für ihn Kitsch ist und ein Foto davon einsenden. Macht mit, traut Euch! --> Klick

Objc C in Swift implementieren

Softis

Erdapfel
Registriert
28.01.16
Beiträge
1
<div class="bbWrapper">Hallo Leute,<br /> <br /> ich bin noch ziemlich am Anfang mit dem iOS Development aber stehe jetzt entgültig vor einem Problem wo ich nicht mehr weiter weiß.<br /> Ich habe nun eine App mit Facebook Login programmiert in C, und einen Parse Login in Swift.<br /> Ich möchte nun gerne in Swift weiterarbeiten, bräuchte aber die Logindaten vom Facebookuser dafür im Swift Code.<br /> Aus der Doku von Apple und anderen Seiten im www werde ich auch nicht schlau, bis auf die Sache mit dem Bridging Header.<br /> Vielleicht könnt ihr mir weiterhelfen, wäre sehr nett. <br /> <br /> Ich bräuchte in Swift nur den &quot;name, email, fbid, facebookurl&quot; zu wiedergeben.<br /> <br /> Das ist der Code in C, von denen ich die Daten haben möchte.<br /> <br /> <div class="bbCodeBlock bbCodeBlock--screenLimited bbCodeBlock--code"> <div class="bbCodeBlock-title"> Code: </div> <div class="bbCodeBlock-content" dir="ltr"> <pre class="bbCodeCode" dir="ltr" data-xf-init="code-block" data-lang=""><code>// LoginViewController.m // facebookLogin #import &quot;LoginViewController.h&quot; #import &lt;FBSDKCoreKit/FBSDKCoreKit.h&gt; #import &lt;FBSDKLoginKit/FBSDKLoginKit.h&gt; #import &quot;DashboardViewController.h&quot; #import &quot;MBProgressHUD.h&quot; @interface LoginViewController (){ /*! *properties of name, email,fbid and fburl. */ NSString* name; NSString* email; NSString* fbid; NSURL *facebookurl; } @end @implementation LoginViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /*! *Fb signin button clicked. */ - (IBAction)facebookLoginClicked:(id)sender { //saving the login method inorder to swap the main screen when the app goes background... [[NSUserDefaults standardUserDefaults]setObject:@&quot;facebookSuccess&quot; forKey:@&quot;loginSuccess&quot;]; [[NSUserDefaults standardUserDefaults]synchronize]; //FBSDKLoginManager in order to read permission with the viewcontroller.. FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init]; [login logInWithReadPermissions:@[@&quot;email&quot;, @&quot;user_friends&quot;, @&quot;public_profile&quot;] fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) { if (error) { NSLog(@&quot;Process error&quot;); } else if (result.isCancelled) { NSLog(@&quot;Cancelled&quot;); } //On success case, the granted permission access will be email... else { if ([result.grantedPermissions containsObject:@&quot;email&quot;]) { NSLog(@&quot;Logged in&quot;); NSLog(@&quot;result is:%@&quot;,result); [self fetchedUser]; } } }]; } /*! *This contains details of the fetched user details. */ -(void)fetchedUser{ NSLog(@&quot;the user token is :%@&quot;, [FBSDKAccessToken currentAccessToken]); //Checking for the usertoken of the current user is not null or nill... if ([FBSDKAccessToken currentAccessToken] != nil &amp;&amp; ![[FBSDKAccessToken currentAccessToken] isEqual: @&quot;null&quot;]) { [[[FBSDKGraphRequest alloc] initWithGraphPath:@&quot;me&quot; parameters:@{@&quot;fields&quot;: @&quot;id, name, link, first_name, last_name, picture.type(large), email, birthday, bio ,location ,friends ,hometown , friendlists&quot;}] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) { if (!error) { //Fetching the user details and saving it in the properties... name = result[@&quot;name&quot;]; email = result[@&quot;email&quot;]; fbid = result[@&quot;id&quot;]; facebookurl = [NSURL URLWithString:[NSString stringWithFormat:@&quot;https://graph.facebook.com/%@/picture?type=large&quot;,result[@&quot;id&quot;]]]; /*Alter method to access the profile pic*/ // NSLog(@&quot;picture: %@&quot;,result[@&quot;picture&quot;][@&quot;data&quot;][@&quot;url&quot;]); //saving this in the NSUserDefaults [[NSUserDefaults standardUserDefaults]setObject:name forKey:@&quot;name&quot;]; [[NSUserDefaults standardUserDefaults]synchronize]; [[NSUserDefaults standardUserDefaults]setObject:email forKey:@&quot;email&quot;]; [[NSUserDefaults standardUserDefaults]synchronize]; [[NSUserDefaults standardUserDefaults]setObject:fbid forKey:@&quot;fbid&quot;]; [[NSUserDefaults standardUserDefaults]synchronize]; [[NSUserDefaults standardUserDefaults]setObject:[facebookurl absoluteString] forKey:@&quot;facebookurl&quot;]; [[NSUserDefaults standardUserDefaults]synchronize]; //performing a segue to the dashboard view. [MBProgressHUD showHUDAddedTo:self.view animated:YES]; [self performSegueWithIdentifier:@&quot;facebookSuccess&quot; sender:self]; [MBProgressHUD hideHUDForView:self.view animated:YES]; } else { NSLog(@&quot;Error %@&quot;,error); } }]; } } @end</code></pre> </div> </div><br /> Danke <img src="/community/styles/apfeltalk/smilies/SmilingCheeks.png" class="smilie" loading="lazy" alt=":)" title="Smile :)" data-shortname=":)" /></div>