【发布时间】:2014-10-07 19:17:28
【问题描述】:
我想从我的应用程序中打开 Facebook 和 twitter 应用程序。同时,我有一个必须在 Facebook 共享框中自动填充的文本。我如何实现这一目标?我现在可以打开应用程序了。但是如何打开共享页面并传递要填充的文本。
Twitter 也是如此。
【问题讨论】:
标签: ios facebook twitter share
我想从我的应用程序中打开 Facebook 和 twitter 应用程序。同时,我有一个必须在 Facebook 共享框中自动填充的文本。我如何实现这一目标?我现在可以打开应用程序了。但是如何打开共享页面并传递要填充的文本。
Twitter 也是如此。
【问题讨论】:
标签: ios facebook twitter share
您可以使用图片和文字轻松发布到 Facebook。为此,您不必退出您的应用程序。试试这个:
- (void) postFacebook {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *fbSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[fbSheet setInitialText:@"Your Text here"];
[fbSheet addImage:[UIImage imageNamed:@"Icon-144.png"]];
[fbSheet addURL:[NSURL URLWithString:@"http://asdf.com"]];
[[CCDirector sharedDirector] presentViewController:fbSheet animated:YES completion:nil];
}
else {
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:@"Sorry!!!"
message:@"You can't share on facebook right now, make sure your device has an internet connection and you have at least one facebook account setup in your device."
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
}
对于高音扬声器,请执行以下操作:
- (void) callTwitter {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:@"Your text here"];
[tweetSheet addImage:[UIImage imageNamed:@"Icon-144.png"]];
[tweetSheet addURL:[NSURL URLWithString:@"http://asdf.com"]];
[[CCDirector sharedDirector] presentViewController:tweetSheet animated:YES completion:nil];
}
else
{
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:@"Sorry!!!"
message:@"You can't send a tweet right now, make sure your device has an internet connection and you have at least one twitter account setup in your device."
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
}
不要忘记添加 SOCIAL.FRAMEWORK 到
BuildPhases -> LinkBinaryWithLibraries
同样在 ViewController 中不要忘记在顶部导入 #import <Social/Social.h>
编辑:
我在 SO 中找到了这个:
NSString *myMessage = [NSString stringWithFormat:@"%@",
[self.txtAdreca.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSString *post = [NSString stringWithFormat:@"fb://publish/profile/me?text=%@",urlString];
BOOL canOpenURL = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:post]];
if (canOpenURL) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:post]];
}
对于高音:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"twitter://status?id=12345"]];
希望这会有所帮助.. :)
【讨论】: