簡體   English   中英

iOS打開FB和Twitter應用程序共享頁面

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM