[英]iOS open fb and twitter app share page
我想从我的应用程序中打开facebook和twitter应用程序。 同时,我有一个必须在Facebook共享框中自动填充的文本。 我该如何实现? 我现在可以打开该应用程序。 但是,如何打开共享页面并传递要填充的文本。 请帮忙。
与twitter相同
您可以轻松地将图像和文本发布到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"]];
希望这可以帮助.. :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.