我正在为一个客户构建一个IOS7原生应用程序--它是为健身教练准备的。
简要要求客户可以在社交上分享进度更新-其中包括一个教师网站的链接,以帮助推广,例如- 'Joe ran 3000 miles with the help of Debbie Personal Trainer',理想情况下还有一张培训师的小照片。
我看过SLComposeViewController
,可以很容易地创建tweet字符串,但我不知道如何在其中添加网址和图像--有人知道这是否可行吗?
发布于 2013-11-14 22:55:09
导入框架<Twitter/Twitter.h>
和<Social/Social.h>
。
-(void)sendFacebook:(id)sender {
SLComposeViewController *composeController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[composeController setInitialText:@"look me"];
[composeController addImage:[UIImage imageNamed:@"image.png"]];
[composeController addURL: [NSURL URLWithString:@"http://www.apple.com"]];
[self presentViewController:composeController animated:YES completion:nil];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultCancelled) {
NSLog(@"delete");
} else {
NSLog(@"post");
}
// [composeController dismissViewControllerAnimated:YES completion:Nil];
};
composeController.completionHandler =myBlock;
}
- (void)sendTwitter:(id)sender {
SLComposeViewController *composeController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[composeController setInitialText:@"look me"];
[composeController addImage:[UIImage imageNamed:@"image.png"]];
[composeController addURL: [NSURL URLWithString:
@"http://www.apple.com"]];
[self presentViewController:composeController
animated:YES completion:nil];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultCancelled) {
NSLog(@"delete");
} else {
NSLog(@"post");
}
// [composeController dismissViewControllerAnimated:YES completion:Nil];
};
composeController.completionHandler =myBlock;
}
发布于 2014-05-03 04:18:17
这几乎与llario的答案相同,但遵循了Apple文档的说明,并采用了带有一些额外错误检查的防御性编码。
#import <Social/Social.h>
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
SLComposeViewController *composeViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
if (composeViewController) {
[composeViewController addImage:[UIImage imageNamed:@"MyImage"]];
[composeViewController addURL:[NSURL URLWithString:@"http://www.google.com"]];
NSString *initialTextString = @"Check out this Tweet!";
[composeViewController setInitialText:initialTextString];
[composeViewController setCompletionHandler:^(SLComposeViewControllerResult result) {
if (result == SLComposeViewControllerResultDone) {
NSLog(@"Posted");
} else if (result == SLComposeViewControllerResultCancelled) {
NSLog(@"Post Cancelled");
} else {
NSLog(@"Post Failed");
}
}];
[self presentViewController:composeViewController animated:YES completion:nil];
}
}
https://stackoverflow.com/questions/19980565
复制相似问题