问题
I've implemented ShareKit in my app. I'm OK with the default way that it works, but I wish to control the services available to the user to select from; to be more specific, I don't want to deal with all the service embedded by default and just have Facebook, Twitter and Mail.
Where in the ShareKit files do I do these settings (removing all of these neglected services that I don't want to deal with their APIs and such)?
回答1:
You would need to edit SHK.m
in the ShareKit framework. Change the favoriteSharersForType:
method to only:
favoriteSharers = [NSArray arrayWithObjects:@"SHKFacebook", @"SHKTwitter", nil];
return favoriteSharers;
You can add/remove services from this array as you please.
EDIT
To remove the More... button, locate the actionSheetForType
method in SHKActionSheet.m
and remove:
[as addButtonWithTitle:SHKLocalizedString(@"More...")];
After completing this, you will need to fix the indices. Locate the dismissWithClickedButtonIndex:
delegate method and delete the entire else if (buttonIndex == sharers.count)
block.
回答2:
You can import the header files for each Sharekit service that you wish to use. For example, if you have a page with a UILabel on it which has a string of text in it, you can import the services you wish to use at the top of your implementation file.
#import "SHKTwitter.h"
#import "SHKFacebook.h"
#import "SHKMail.h"
You can then set it to share via these services through any action you wish, i.e. the tap of a Facebook, Twitter, or Mail button? Or you can manually enter your own UIActionSheet with three items in for Twitter, Facebook and Mail which will then call the specific Sharekit service upon request.
If you wanted to post a URL for example;
#import "SHKTwitter.h" //include the service's header at the top of your class
...
// Create the item to share (in this example, a url)
NSURL *url = [NSURL URLWithString:@"http://iPhoneHelpr.com"];
SHKItem *item = [SHKItem URL:url title:@"Check out my site!"];
// Share the item
[SHKTwitter shareItem:item]; // Specify the specific service you want to share with
That is a simple explanation but it can be applied to share images, documents, strings of text etc.
回答3:
When you create your own configure file, override this method:
- (NSString*)sharersPlistName
{
return @"MySHKSharers.plist"; // original value is "SHKSharer.plist"
}
Copy SHKSharer.plist from ShareKit project under Classes/ShareKit/Core to your project location.
Remove the unwanted actions and services from the file, your are done.
回答4:
Subclass DefaultSHKConfigurator from "DefaultSHKConfigurator.h" and implement the following methods:
- (NSArray*)defaultFavoriteURLSharers {
return [NSArray arrayWithObjects:@"SHKTwitter",@"SHKFacebook", @"SHKPocket", nil];
}
- (NSArray*)defaultFavoriteImageSharers {
return [NSArray arrayWithObjects:@"SHKMail",@"SHKFacebook", @"SHKCopy", nil];
}
- (NSArray*)defaultFavoriteTextSharers {
return [NSArray arrayWithObjects:@"SHKMail",@"SHKTwitter",@"SHKFacebook", nil];
}
In your stdAppDelegate:
//configure sharekit:
DefaultSHKConfigurator *configurator = [[MySHKConfigurator alloc] init];
[SHKConfiguration sharedInstanceWithConfigurator:configurator];
回答5:
The above solution is wrong in my opinion and not maintainable since you have to apply that change every time there is an update on ShareKit library (at least now, I don't know how it was in previous versions of ShareKit).
If you read SHK.m you will see that it first tries to get your sharers from preferences, if you have any, otherwise it will go to the SHKConfigurator and call defaultFavoriteURLSharers.
If you subclass the DefaultSHKConfigurator (which you probably do), you can override the defaultFavoriteURLSharers method (or ImageSharers, or TextSharers etc.) and you can define your favorite sharers there.
In @interface CLQShareKitConfigurator : DefaultSHKConfigurator
- (NSArray*)defaultFavoriteURLSharers
{
return [NSArray arrayWithObjects:@"SHKTwitter",@"SHKFacebook", nil];
}
回答6:
To remove more button you can add this method in you SHKConfigurator
-(NSNumber*)showActionSheetMoreButton {
return [NSNumber numberWithBool:false];
}
来源:https://stackoverflow.com/questions/6817538/ios-sharekit-selecting-the-required-sharing-services