Upgrade to Pro — share decks privately, control downloads, hide ads and more …

iOS Development Social Network integration

Oursky Limited
May 20, 2012
130

iOS Development Social Network integration

Oursky Limited

May 20, 2012
Tweet

Transcript

  1. Facebook iOS SDK Facebook iOS SDK source code https://github.com/facebook/facebook-ios-sdk Use

    static library version if ARC is enabled in app % ~/facebook-ios-sdk/scripts/build_facebook_ios_sdk_static_lib.sh Sunday, 13 May, 12
  2. Simple code In [app]-info.plist Initialize Facebook object Facebook *facebook =

    [[Facebook alloc] initWithAppId:kAppId andDelegate:self]; if ( [[NSUserDefaults standardUserDefaults] stringForKey:@"FBAccessTokenKey"]) { facebook.accessToken = [[NSUserDefaults standardUserDefaults] stringForKey:@"FBAccessTokenKey"]; facebook.expirationDate = [[NSUserDefaults standardUserDefaults] objectForKey:@"FBExpirationDateKey"]; } Sunday, 13 May, 12
  3. Others Request with FBRequestDelegate Add App ID in Facebook app

    portal, for fast login [facebook requestWithGraphPath:@"me" andDelegate:self]; Sunday, 13 May, 12
  4. Twitter iOS 5 build in Twitter framework Tweet with dialog

    // Set up the built-in twitter composition view controller. TWTweetComposeViewController *tweetViewController = [[TWTweetComposeViewController alloc] init]; // Set the initial tweet text. See the framework for additional properties that can be set. [tweetViewController setInitialText:@"Hello. This is a tweet."]; // Create the completion handler block. [tweetViewController setCompletionHandler:^(TWTweetComposeViewControllerResult result) { NSString *output; switch (result) { case TWTweetComposeViewControllerResultCancelled: output = @"Tweet cancelled."; break; case TWTweetComposeViewControllerResultDone: output = @"Tweet done."; break; default: break; } // Dismiss the tweet composition view controller. [self dismissModalViewControllerAnimated:YES]; }]; // Present the tweet composition view controller modally. [self presentModalViewController:tweetViewController animated:YES]; Sunday, 13 May, 12
  5. Twitter Tweet with custom message // Create an account store

    object. ACAccountStore *accountStore = [[ACAccountStore alloc] init]; // Create an account type that ensures Twitter accounts are retrieved. ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; // Request access from the user to use their Twitter accounts. [accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) { if(granted) { // Get the list of Twitter accounts. NSArray *accountsArray = [accountStore accountsWithAccountType:accountType]; // For the sake of brevity, we'll assume there is only one Twitter account present. if ([accountsArray count] > 0) { // Grab the initial Twitter account to tweet from. ACAccount *twitterAccount = [accountsArray objectAtIndex:0]; // Create a request, which in this example, posts a tweet to the user's timeline. TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@"http://api.twitter.com/1/statuses/update.json"] parameters:[NSDictionary dictionaryWithObject:@"Hello. This is a tweet." forKey:@"status"] requestMethod:TWRequestMethodPOST]; // Set the account used to post the tweet. [postRequest setAccount:twitterAccount]; // Perform the request created above and create a handler block to handle the response. [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { NSString *output = [NSString stringWithFormat:@"HTTP response status: %i", [urlResponse statusCode]]; [self performSelectorOnMainThread:@selector(displayText:) withObject:output waitUntilDone:NO]; }]; } } }]; Sunday, 13 May, 12
  6. Sina Weibo All authorization data is stored in KeyChain No

    need to handle token save in delegate // in WBEngine #define kWBURLSchemePrefix @"WB_" #define kWBKeychainServiceNameSuffix @"_WeiBoServiceName" #define kWBKeychainUserID @"WeiBoUserID" #define kWBKeychainAccessToken @"WeiBoAccessToken" #define kWBKeychainExpireTime @"WeiBoExpireTime" Sunday, 13 May, 12
  7. Initialize weibo object Login Send Weibo After login WBEngine *engine

    = [[WBEngine alloc] initWithAppKey:[GeneralHelper weiboAppKey] appSecret:[GeneralHelper weiboAppSecret]]; WBEngine *weiBoEngine = [ad weiBoEngine]; weiBoEngine.rootViewController = self; [ad setWbEngineDelegate:self]; [weiBoEngine logIn]; [weiboEngine sendWeiBoWithText:@"message" image:self.image]; Sunday, 13 May, 12