众所周知,自 iOS5 以来,有一个原生的 Twitter 框架,可以轻松地从您的应用程序发布推文。
有没有办法提示将用户转发到设置应用并询问用户名和密码的警报?
我知道我可以用下面的代码解决这个问题:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=TWITTER"]];
但那是未记录的代码..
提前致谢
问候比利 (我关于 SO 的第一篇文章)
最佳答案
在 iOS5.1 中,我们应该使用 TWTweetComposeViewController 来显示对话框,因为苹果拒绝使用 prefs:root=TWITTER 的应用程序。
但是,我不喜欢显示推文屏幕和键盘
所以我想出了隐藏它们但显示弹出屏幕的方法。
更新:
Apple 使用此技巧批准了我的应用。
TWTweetComposeViewController *viewController = [[TWTweetComposeViewController alloc] init];
//hide the tweet screen
viewController.view.hidden = YES;
//fire tweetComposeView to show "No Twitter Accounts" alert view on iOS5.1
viewController.completionHandler = ^(TWTweetComposeViewControllerResult result) {
if (result == TWTweetComposeViewControllerResultCancelled) {
[self dismissModalViewControllerAnimated:NO];
}
};
[self presentModalViewController:viewController animated:NO];
//hide the keyboard
[viewController.view endEditing:YES];
//this approach doesn't work since you can't jump to settings
// [self dismissModalViewControllerAnimated:NO];
关于objective-c - 在 iOS5 中使用 Twitter 框架提示登录警报?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8870922/