IOS SDK
From Social ID Developers
Revision as of 13:14, 3 December 2014 by Dirceu.tiegs (Talk | contribs)
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:
[SIDFacebook logInWithPermissions:@[@"public_profile",@"email",@"user_birthday"] success:^(SIDSignIn *signIn) { NSLog(@"Logged in Facebook!"); } failure:^(NSError *error) { // do something }];
Call the following code to make the user log in with Google+:
[SIDGoogle logInGoogle:^(SIDSignIn *signIn) { NSLog(@"Logged in Google!"); } failure:^(NSError *error) { // do something }];
Call the following code to make the user log in with LinkedIn:
[SIDLinkedin initializeLinkedin]; [[SIDLinkedin getInstance] setWebView:webView]; // this webview should be created and initialized separately [SIDLinkedin logInLinkedin:^(SIDSignIn *signIn) { NSLog(@"Logged in LinkedIn!"); } failure:^(NSError *error) { // do something }];
Logout
[[SocialID getInstance] logout];
Get the user profile
To get the user profile, use the following code:
[[SocialID getInstance] getUser:"display_name,verified_email,current_location" success:^(SIDUser *user) { SIDUserProfile *profile = user.profile; } 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]; }