gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-01 19:11:56 26 4
gpt4 key购买 nike

在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com