看起来iOS 5.1已经破坏了用于导航用户到首选项的标准URL编码。
例如:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=TWITTER"]];
在iOS 5.0中可以正常工作,但在iOS 5.1中无法工作(无论是设备还是模拟器)。
是否有人找到了在iOS 5.1中复制此功能的方法?
看起来iOS 5.1已经破坏了用于导航用户到首选项的标准URL编码。
例如:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=TWITTER"]];
在iOS 5.0中可以正常工作,但在iOS 5.1中无法工作(无论是设备还是模拟器)。
是否有人找到了在iOS 5.1中复制此功能的方法?
这有点棘手,我通过删除*TWTWeetComposeViewController*
中的子视图来实现,因此仅在用户未登录时显示警报,并通过点击设置按钮,可以打开我的应用程序中的设置页面。
+ (void)setAlertForSettingPage :(id)delegate
{
// Set up the built-in twitter composition view controller.
TWTweetComposeViewController *tweetViewController = [[TWTweetComposeViewController alloc] init];
// Create the completion handler block.
[tweetViewController setCompletionHandler:^(TWTweetComposeViewControllerResult result) {
[delegate dismissModalViewControllerAnimated:YES];
}];
// Present the tweet composition view controller modally.
[delegate presentModalViewController:tweetViewController animated:YES];
//tweetViewController.view.hidden = YES;
for (UIView *view in tweetViewController.view.subviews){
[view removeFromSuperview];
}
}
在这里,代理是你的视图控制器。如果您在视图控制器内使用此方法,请改用 self
而不是 delegate
。
编辑:如果您遇到任何过时的错误,请改用以下 iOS6 兼容代码:
- (void)setAlertForSettingPage
{
// Set up the built-in twitter composition view controller.
SLComposeViewController *tweetViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
// Present the tweet composition view controller modally.
[self presentViewController:tweetViewController animated:YES completion:nil];
for (UIView *view in tweetViewController.view.subviews){
[view removeFromSuperview];
}
}
对不起,我不知道复制此功能的方法。
但是您可以提交一个Radar请求恢复此功能。 这里有一个Radar 请求首先记录这些scheme的文档。
David Barnard 已经确认iOS 5.1破坏了设置应用程序的URL schemes。
更新: iOS 8有类似的功能 用于打开您的应用程序的设置。感谢苹果、Mike 和Soto_iGhost。
常量UIApplicationOpenSettingsURLString
(UIApplication Documentation)将打开您的应用程序的设置,而不是Twitter等的设置。虽然不完全相同,但比以前更加清晰,并得到了官方认可。
现在每个应用程序都有一个在设置中使用隐私、蜂窝数据、后台应用程序刷新和通知的位置,所以这应该特别有用。
你可以做到这一点。
TWTweetComposeViewController *ctrl = [[TWTweetComposeViewController alloc] init];
if ([ctrl respondsToSelector:@selector(alertView:clickedButtonAtIndex:)]) {
// Manually invoke the alert view button handler
[(id <UIAlertViewDelegate>)ctrl alertView:nil
clickedButtonAtIndex:0];
}
如果你查看Twitter的框架(即Twitter视图控制器),它内部有“prefs:root=TWITTER”的内容,5.1版本也有这一行。因此,很可能苹果公司做了一些事情来禁用其他应用程序的此功能,例如在plist中设置某些特殊键或方法“openURL”会检查是否为系统应用程序。