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