[英]How to share selected text from iphone book app on Facebook
I have iphone book app like all other text when tap and hold a specific words you will see a (copy,define) menu, I want to add another item which is (share) when the user tap it the sharing action sheet will pop up and the user can share that particular words on (Facebook , Twitter , mail or text). 我拥有iPhone书本应用程序,就像其他所有文本一样,当点击并按住特定的单词时,您将看到一个(复制,定义)菜单,我想添加另一个项目(共享),当用户点击它时,共享操作表将会弹出并且用户可以在(Facebook,Twitter,邮件或文本)上共享特定的单词。 Please help me with details, any help will be appreciated.
请详细帮助我,任何帮助将不胜感激。
social framework: 社会框架:
share Fb or Twitter 分享Fb或Twitter
- (IBAction)socialSheet:(id)sender {
// create Facebook controller
SLComposeViewController *socialController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
// add initial text
[socialController setInitialText:@"Hello Facebook!"];
// add an image for you optional
[socialController addImage:[UIImage imageNamed:@"picture.jpg"]];
// add a URL for you optional
[socialController addURL:[NSURL URLWithString:@"http://wpguru.co.uk"]];
// present controller
[self presentViewController:socialController animated:YES completion:nil];
}
Facebook Api Facebook Api
-(void) postWithText: (NSString*) message_text
ImageName: (NSString*) image_name
URL: (NSString*) url
Caption: (NSString*) caption
Name: (NSString*) name
andDescription: (NSString*) description
{
NSMutableDictionary* params = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
url, @"link",
name, @"name",
caption, @"caption",
description, @"description",
message, @"message_name",
UIImagePNGRepresentation([UIImage imageNamed: image_name]), @"picture",
nil];
if ([FBSession.activeSession.permissions indexOfObject:@"publish_actions"] == NSNotFound)
{
// No permissions found in session, ask for it
[FBSession.activeSession requestNewPublishPermissions: [NSArray arrayWithObject:@"publish_actions"]
defaultAudience: FBSessionDefaultAudienceFriends
completionHandler: ^(FBSession *session, NSError *error)
{
if (!error)
{
// If permissions granted and not already posting then publish the story
if (!m_postingInProgress)
{
[self postToWall: params];
}
}
}];
}
else
{
// If permissions present and not already posting then publish the story
if (!m_postingInProgress)
{
[self postToWall: params];
}
}
}
-(void) postToWall: (NSMutableDictionary*) params
{
m_postingInProgress = YES; //for not allowing multiple hits
[FBRequestConnection startWithGraphPath:@"me/feed"
parameters:params
HTTPMethod:@"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
{
if (error)
{
//showing an alert for failure
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:@"Post Failed"
message:error.localizedDescription
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
m_postingInProgress = NO;
}];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.