ShareKit

ShareKit是iPhone开发的第三方接口,允许你一键分享文字,图片,网址,文件到facebook,twitter,delicious,tumblr,google reader等第三方的网站。

 

下面是下载地址:

(1) Download : http://getsharekit.com/d/ShareKit.0.2.1.zip 
(2) Github : http://github.com/ideashower/sharekit/

 

下载之后按照官方提示,把整个ShareKit文件夹拖入工程文件中;如下:

 

ShareKit

 

接下来要对他进行一些详细的配置,如下:

一、SHKConfig.h文件的配置

 

#define SHKMyAppName            @"App name" 
#define SHKMyAppURL             @"itunes address" 

 


二、第三方平台的API key的配置

 

1.Fackbook的配置

(1)在facebook的developers中心中申请创建一个Application。申请地址如下:(http://www.facebook.com/developers/

(2)将上面生成的Key填写在对应的SHKConfig.h文件中的对应的定义里:

#define SHKFacebookUseSessionProxy        NO 
#define SHKFacebookKey                    @"xxxx" 
#define SHKFacebookSecret                 @"xxx" 
#define SHKFacebookSessionProxyURL        @"" // left it blank here 


2.Twitter的配置

(1)同Facebook一样配置一个application,地址为:(http://dev.twitter.com/apps/new)

(2)将申请生成的Key填写在SHKConfig.k文件对应的定义里:

#define SHKTwitterConsumerKey        @"xxx" 
#define SHKTwitterSecret             @"xxx" 
#define SHKTwitterCallbackUrl        @"itunes address" 
#define SHKTwitterUseXAuth           0 // To use xAuth, set to 1 
#define SHKTwitterUsername           @""  // left it blank here , if use xAuth 


3.其他的诸如Bit.ly,Read it Later等都可以上相应的网站注册API Key,然后在SHKConfig.h文件中找到相对应的定义填入进去。其中Tumblr和Google Reader是不需要配置API Key的。

三、如何使用:

调用之后如下:

 

ShareKit

因为我是只要分享到Facebook,不要其他的,所以需要修改他里面的源文件。修改步骤如下:

(1)在要调用分享的button里面调用如下方法,把要传递的url放入:

- (void)share:(id)sender

{

      NSURL *url = [NSURL URLWithString:@"http://getsharekit.com"];

      SHKItem *item = [SHKItem URL:url title:@"ShareKit is Awesome!"];

   

      // Get the ShareKit action sheet

      SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];

   

    [actionSheet showFromToolbar:self.navigationController.toolbar];

 

}

 

(2)在SHK.m中修改:+ (NSArray *)favoriteSharersForType:(SHKShareType)type方法:如下:

 

+ (NSArray *)favoriteSharersForType:(SHKShareType)type

{    

      NSArray *favoriteSharers = [[NSUserDefaults standardUserDefaults] objectForKey:[NSString stringWithFormat:@"%@%i", SHK_FAVS_PREFIX_KEY, type]];

           

      // set defaults

      if (favoriteSharers == nil)

      {

            switch (type)

            {

                  case SHKShareTypeURL:

                         favoriteSharers = [NSArray arrayWithObjects:@"SHKFacebook",nil];

                         break;

                        

                  case SHKShareTypeImage:

                         favoriteSharers = [NSArray arrayWithObjects:@"SHKMail",@"SHKFacebook",@"SHKCopy",nil];

                         break;

                        

                  case SHKShareTypeText:

                         favoriteSharers = [NSArray arrayWithObjects:@"SHKMail",@"SHKTwitter",@"SHKFacebook", nil];

                         break;

                        

                  case SHKShareTypeFile:

                         favoriteSharers = [NSArray arrayWithObjects:@"SHKMail", nil];

                         break;

            }

           

            // Save defaults to prefs

            [self setFavorites:favoriteSharers forType:type];

      }

     

      // Make sure the favorites are not using any exclusions, remove them if they are.

      NSArray *exclusions = [[NSUserDefaults standardUserDefaults] objectForKey:@"SHKExcluded"];

      if (exclusions != nil)

      {

            NSMutableArray *newFavs = [favoriteSharers mutableCopy];

            for(NSString *sharerId in exclusions)

            {

                  [newFavs removeObject:sharerId];

            }

           

            // Update

            favoriteSharers = [NSArray arrayWithArray:newFavs];

            [self setFavorites:favoriteSharers forType:type];

           

            [newFavs release];

      }

     

      return favoriteSharers;

}

(3)在SHKActionSheet.m文件中注释掉一下语句:

// Add More button

      [as addButtonWithTitle:SHKLocalizedString(@"More...")];

 

// More

      else if (buttonIndex == sharers.count)

      {

            SHKShareMenu *shareMenu = [[SHKCustomShareMenu alloc] initWithStyle:UITableViewStyleGrouped];

            shareMenu.item = item;

            [[SHK currentHelper] showViewController:shareMenu];

            [shareMenu release];

      }

这样运行之后就可以如上图所示,只分享到facebook,其他的具体都可以参照以上。

今天的第三方接口ShareKit就讲解到这里,欢迎大家支持哈。

上一篇:TOUCHXML解析xml


下一篇:UnicodeEncodeError: ‘gbk‘ codec can‘t encode character ‘\xa9‘ in position 6870: illegal multibyte s