Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS开放fb和twitter应用共享页面_Ios_Facebook_Twitter_Share - Fatal编程技术网

iOS开放fb和twitter应用共享页面

iOS开放fb和twitter应用共享页面,ios,facebook,twitter,share,Ios,Facebook,Twitter,Share,我想从我的应用程序中打开facebook和twitter应用程序。同时,我有一个文本必须自动填充在facebook共享框中。我如何做到这一点?我现在可以打开应用程序了。但是如何打开共享页面并传递要填充的文本呢。请帮忙 与twitter相同,你可以轻松地用图片和文本发布到facebook。为此,您不必退出应用程序。试试这个: - (void) postFacebook { if ([SLComposeViewController isAvailableForServiceType:SLS

我想从我的应用程序中打开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];
    }
}

对于tweeter,请执行以下操作:

- (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中,不要忘记在顶部导入

编辑:

我在这里发现了这个:

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"]];

希望这有助于

不要忘记通过进入BuildPhases->LinkBinaryWithLibraries添加Social.framework。同样在ViewController中,不要忘记在顶部导入导入导入@michael>谢谢。已添加。@Rashad感谢您的回复。这很有用,但我必须打开应用程序并将其发布到那里。“有什么办法吗?”拉沙德谢谢你。我也可以在推特上使用它吗?你当然可以在推特应用程序中打开页面,但我不确定文本参数是否有效。