IOS SDK
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]; }