IOS SDK

(Difference between revisions)
Jump to: navigation, search
Line 11: Line 11:
 
Call the following code to make the user log in with Facebook:
 
Call the following code to make the user log in with Facebook:
  
   [SIDFacebook logInWithPermissions:@[@"public_profile",@"email",@"user_birthday"] success:^(SIDSignIn *signIn) {
+
   [SIDLogin startFacebookLogin:^(SIDUser *user) {
      NSLog(@"Logged in Facebook!");
+
        NSLog(@"Logged in with Facebook! User id: %d", [user userId]);
 
   } failure:^(NSError *error) {
 
   } failure:^(NSError *error) {
      // do something
+
        NSLog(@"Facebook login error! %@", error);
 
   }];
 
   }];
  
 
Call the following code to make the user log in with Google+:
 
Call the following code to make the user log in with Google+:
  
   [SIDGoogle logInGoogle:^(SIDSignIn *signIn) {
+
   [SIDLogin startGoogleLogin:^(SIDUser *user) {
      NSLog(@"Logged in Google!");
+
        NSLog(@"Logged in with Google+! User id: %d", [user userId]);
 
   } failure:^(NSError *error) {
 
   } failure:^(NSError *error) {
      // do something
+
        NSLog(@"Google+ login error! %@", error);
 
   }];
 
   }];
  
Call the following code to make the user log in with LinkedIn:
+
For the LinkedIn login you need to setup a webview in the View Controller:
  
   [SIDLinkedin initializeLinkedin];
+
   [SIDLinkedin setWebView:self.webView];
  [[SIDLinkedin getInstance] setWebView:webView]; // this webview should be created and initialized separately
+
 
   [SIDLinkedin logInLinkedin:^(SIDSignIn *signIn) {
+
And call the following code to make the user log in with LinkedIn:
      NSLog(@"Logged in LinkedIn!");
+
 
 +
   [SIDLogin startLinkedinLogin:^(SIDUser *user) {
 +
        NSLog(@"Logged in with LinkedIn! User id: %d", [user userId]);
 
   } failure:^(NSError *error) {
 
   } failure:^(NSError *error) {
      // do something
+
        NSLog(@"LinkedIn login error! %@", error);
 
   }];
 
   }];
  
 
= Logout =
 
= Logout =
  
   [[SocialID getInstance] logout];
+
Cleans up the user information stored in the current session:
 +
 
 +
   [SIDUserSession logout];
 +
 
 +
You can also cleans up the login app session data:
 +
 
 +
  [SIDAppSession logout];
  
 
= Get the user profile =
 
= Get the user profile =
Line 43: Line 51:
 
To get the user profile, use the following code:
 
To get the user profile, use the following code:
  
   [[SocialID getInstance] getUser:"display_name,verified_email,current_location" success:^(SIDUser *user) {
+
   [SIDUserSession getUser:^(SIDUser *user) {
       SIDUserProfile *profile = user.profile;
+
      NSLog(@"User id: %ld", (long)[user userId]);
 +
      NSLog(@"User name: %@", [[user profile] displayName]);
 +
      NSLog(@"User email: %@", [[user profile] verifiedEmail]);
 +
  } failure:^(NSError *error) {
 +
      NSLog(@"Error: %@", error);
 +
  }];
 +
 
 +
The method above uses the default profile fields specified in the SIDLogin. You can also get specific profile fields:
 +
 
 +
  [SIDUserSession getUserWithFields:@"display_name,picture_url,current_location,verified_email" success:^(SIDUser *user) {
 +
       NSLog(@"User id: %ld", (long)[user userId]);
 +
      NSLog(@"User name: %@", [[user profile] displayName]);
 +
      NSLog(@"User email: %@", [[user profile] verifiedEmail]);
 
   } failure:^(NSError *error) {
 
   } failure:^(NSError *error) {
 
       NSLog(@"Error: %@", error);
 
       NSLog(@"Error: %@", error);
Line 53: Line 73:
 
= Receive push notifications =
 
= Receive push notifications =
  
Add the following code to the (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method in your app delegate implementation file:
+
Add the following code to the "(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions" method in your App Delegate implementation file:
  
 
   // Let the device know we want to receive push notifications
 
   // Let the device know we want to receive push notifications

Revision as of 14:02, 17 September 2015

Contents

Download and Setup the SDK

You can download and setup the SDK using our iOS SDK Setup guide.

Social Login

After setting up the SDK (iOS SDK Setup), add the following statement to your ViewController:

 #import <SocialID/SocialID.h>

Call the following code to make the user log in with Facebook:

 [SIDLogin startFacebookLogin:^(SIDUser *user) {
        NSLog(@"Logged in with Facebook! User id: %d", [user userId]);
 } failure:^(NSError *error) {
        NSLog(@"Facebook login error! %@", error);
 }];

Call the following code to make the user log in with Google+:

 [SIDLogin startGoogleLogin:^(SIDUser *user) {
        NSLog(@"Logged in with Google+! User id: %d", [user userId]);
 } failure:^(NSError *error) {
        NSLog(@"Google+ login error! %@", error);
 }];

For the LinkedIn login you need to setup a webview in the View Controller:

 [SIDLinkedin setWebView:self.webView];

And call the following code to make the user log in with LinkedIn:

 [SIDLogin startLinkedinLogin:^(SIDUser *user) {
        NSLog(@"Logged in with LinkedIn! User id: %d", [user userId]);
 } failure:^(NSError *error) {
        NSLog(@"LinkedIn login error! %@", error);
 }];

Logout

Cleans up the user information stored in the current session:

 [SIDUserSession logout];

You can also cleans up the login app session data:

 [SIDAppSession logout];

Get the user profile

To get the user profile, use the following code:

 [SIDUserSession getUser:^(SIDUser *user) {
     NSLog(@"User id: %ld", (long)[user userId]);
     NSLog(@"User name: %@", [[user profile] displayName]);
     NSLog(@"User email: %@", [[user profile] verifiedEmail]);
 } failure:^(NSError *error) {
     NSLog(@"Error: %@", error);
 }];

The method above uses the default profile fields specified in the SIDLogin. You can also get specific profile fields:

 [SIDUserSession getUserWithFields:@"display_name,picture_url,current_location,verified_email" success:^(SIDUser *user) {
     NSLog(@"User id: %ld", (long)[user userId]);
     NSLog(@"User name: %@", [[user profile] displayName]);
     NSLog(@"User email: %@", [[user profile] verifiedEmail]);
 } failure:^(NSError *error) {
     NSLog(@"Error: %@", error);
 }];

The complete list of fields can be found on Social_Profile_Fields.

Receive push notifications

Add the following code to the "(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions" method in your App Delegate implementation file:

 // Let the device know we want to receive push notifications
 NSLog(@"Registering for push notifications...");
 if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
     [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIRemoteNotificationTypeBadge |
                                                                                                 UIRemoteNotificationTypeAlert |
                                                                                                 UIRemoteNotificationTypeSound) categories:nil]];
   
     [application registerForRemoteNotifications];
 } else {
     [application registerForRemoteNotificationTypes:
      UIRemoteNotificationTypeBadge |
      UIRemoteNotificationTypeAlert |
      UIRemoteNotificationTypeSound];
 }

And create the following methods on the delegate:

  - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
 {
     NSLog(@"My token is: %@", deviceToken);
     SIDDevice *device = [SIDDevice device];
     [device setDeviceFromData:deviceToken];
     [device save];
 }
 - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
 {
     NSLog(@"Failed to get token, error: %@", error);
 }
 - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
 {
     NSLog(@"Received notification: %@", userInfo);
     [SIDPush handleNotification:userInfo];
 }
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox