在iOS5中使用Twitter框架提示login提醒?

大家可能知道,由于iOS5有一个原生的Twitter框架,可以很容易地从你的应用程序发布推文。

有没有办法提示提醒用户转到设置应用程序并要求input用户名和密码?

我知道我可以用下面的代码解决问题:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=TWITTER"]]; 

但那是没有文件的代码..

提前致谢

关心比利(我的第一篇文章)

你不需要实现这一点,如果你设置你的Twitter集成在Twitter上发布post,iOS检测到没有设置Twitter帐户,它会自动为你做!

这是iOS 5.1上我的iPhone 4S上运行的一个应用程序的屏幕截图

首选项链接的移除是参考开发人员的自定义操作,如链接到您自己的首选项菜单。 这不适用,因为Twitter不仅仅是iOS 5的内置函数,而且popup来通知你的UIAlertView不是由开发者处理的,它是iOS的自动function。

在这里输入图像描述

在iOS5.1中,我们应该使用TWTweetComposeViewController来显示对话框,因为苹果拒绝使用prefs的应用程序:root = TWITTER。

但是,我不喜欢显示推特屏幕和键盘
所以我想出了隐藏它们的方法,但显示popup式屏幕。

更新:苹果公司批准我的应用程序使用这个技巧。

在这里输入图像描述

  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]; 

在这里我find了方法:

如果您的设备设置上没有设置Twitter帐户,则显示自定义提醒:

  if (![TWTweetComposeViewController canSendTweet]) { UIAlertView *alertViewTwitter = [[[UIAlertView alloc] initWithTitle:@"No Twitter Accounts" message:@"There are no Twitter accounts configured. You can add or create a Twitter account in Settings." delegate:self cancelButtonTitle:@"Settings" otherButtonTitles:@"Cancel",nil] autorelease]; [alertViewTwitter show]; } - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ if (buttonIndex==0) { TWTweetComposeViewController *ctrl = [[TWTweetComposeViewController alloc] init]; if ([ctrl respondsToSelector:@selector(alertView:clickedButtonAtIndex:)]) { [(id <UIAlertViewDelegate>)ctrl alertView:alertView clickedButtonAtIndex:0]; } [ctrl release]; } } 

希望这将是有道理的:)

这是不可能的,虽然它应该自动要求用户login,如果用户没有login。

iOS 5.1 ,该function已被删除,如此处所示