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文件夾拖入工程文件中;如下:
接下來要對他進行一些詳細的配置,如下:
一、SHKConfig.h文件的配置
<span style="font-size:18px"> #define SHKMyAppName @"App name"
#define SHKMyAppURL @"itunes address"
</span>
二、第三方平台的API key的配置
1.Fackbook的配置
(1)在facebook的developers中心中申請創建一個Application。申請地址如下:(http://www.facebook.com/developers/)
(2)將上面生成的Key填寫在對應的SHKConfig.h文件中的對應的定義裡:
<span style="font-size:18px"> #define SHKFacebookUseSessionProxy NO
#define SHKFacebookKey @"xxxx"
#define SHKFacebookSecret @"xxx"
#define SHKFacebookSessionProxyURL @"" // left it blank here
</span>
2.Twitter的配置
(1)同Facebook一樣配置一個application,地址為:(http://dev.twitter.com/apps/new)
(2)將申請生成的Key填寫在SHKConfig.k文件對應的定義裡:
<span style="font-size:18px"> #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
</span>
3.其他的諸如Bit.ly,Read it Later等都可以上相應的網站注冊API Key,然後在SHKConfig.h文件中找到相對應的定義填入進去。其中Tumblr和Google Reader是不需要配置API Key的。
三、如何使用:
調用之後如下:
因為我是只要分享到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就講解到這裡,歡迎大家支持哈