objective-c - 使用哈希标签搜索打开 native Twitter 应用程序

标签 objective-c ios twitter nsurl hashtag

在 iOS 5 上,我试图打开一个带有动态主题标签搜索词的本地 Twitter 应用程序。

我试过:

- (void)openForHashTag:(NSString *)hashTag {
UIApplication *app = [UIApplication sharedApplication];

NSURL *twitterURL = [NSURL URLWithString:[NSString stringWithFormat:@"twitter://search?q=%@", hashTag]];
DLog(@"Hashtag URL: %@ ", twitterURL);

if ([app canOpenURL:twitterURL]) {
    [app openURL:twitterURL];
}
else {
    NSURL *safariURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://mobile.twitter.com/search?q=%@", hashTag]];
    [app openURL:safariURL];
}

它似乎转到了主题标签搜索页面,但一直在加载... twitter://search?q=%@ 格式不对吗?

最佳答案

- (void)openForHashTag:(NSString *)hashTag {
    UIApplication *app = [UIApplication sharedApplication];

    // NOTE: you must percent escape the query (# becomes %23)
    NSString *cleanQuery = [hashTag stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSURL *twitterURL = [NSURL URLWithString:[NSString stringWithFormat:@"twitter://search?query=%@", cleanQuery]];
    if ([app canOpenURL:twitterURL]) {
        [app openURL:twitterURL];
    } else {
        NSURL *safariURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://mobile.twitter.com/search?q=%@", cleanQuery]];
        [app openURL:safariURL];
    }
}

关于objective-c - 使用哈希标签搜索打开 native Twitter 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10981794/

相关文章:

objective-c - 识别字符串中的表情符号字符并反转所有

ios - 如何在Objective-C中捕获JSON错误?

ios - 是否有可以将 ACAccountTypeIdentifier 转换为 SLServiceType 的函数?

iphone - 如何在 iphone sdk 中添加视频作为 HUD 元素

api - 最佳实践 - 是否存储 Twitter 凭据?

iphone - Twitter 是否可以在 iOS 后台自动分享?

iphone - iOS - IBAction - 用户正在输入的文本字段

iphone - 如何使用 iPhone SDK 为这样的图像制作动画?

ios - 当我重新安装应用程序时,对 xib 文件的新更改不会覆盖旧的更改,旧的更改仍然出现

ios - 为什么这个 UIViewController 在调用 twitter 后没有更新?