Facebook App从IBAction开始,但Twitter不是吗?

时间:2013-11-19 16:25:26

标签: ios facebook twitter

我可以使用下面的代码打开Facebook应用程序,但不能打开Twitter。 twitter不会像facebook一样打开的推特代码有什么问题?当我尝试按下按钮打开twitter时,一切都没有发生。

- (IBAction)Facebook:(id)sender {

    NSURL* facebookURL = [ NSURL URLWithString: @"https://facebook.com/myProfile" ];
    NSURL* facebookAppURL = [ NSURL URLWithString: @"fb://profile/123456789" ];
    UIApplication* app = [ UIApplication sharedApplication ];
    if( [ app canOpenURL: facebookAppURL ] ) {
        [ app openURL: facebookAppURL ];
    } else {
        [ app openURL: facebookURL ];
    }

}
- (IBAction)Twitter:(id)sender {

    NSURL* twitterURL = [ NSURL URLWithString: @"http://twitter.com/myProfile" ];
    NSURL* twitterAppURL = [ NSURL URLWithString: @"twitter://‎" ];
    UIApplication* app = [ UIApplication sharedApplication ];
    if( [ app canOpenURL: twitterAppURL ] ) {
        [ app openURL: twitterAppURL ];
    } else {
        [ app openURL: twitterURL ];
    }
}

1 个答案:

答案 0 :(得分:0)

使用twitter URL策划器,您必须在调用本机应用程序许可者时添加user ....

if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"twitter://user?screen_name=PROFILE"]]) {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"twitter://user?screen_name=PROFILE"]];
}
else {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://twitter.com/intent/user?screen_name=PROFILE"]];

}