如何使用 iOS 5.1 打开首选项/设置?
-
09-12-2019 - |
题
看起来 iOS 5.1 已经破坏了用于将用户导航到首选项的标准 URL 编码。
例如:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=TWITTER"]];
适用于 iOS 5.0,但不适用于 iOS 5.1(设备和模拟器)。
有没有人找到在 iOS 5.1 中复制此功能的方法?
解决方案
但您可以做的是提交雷达请求恢复。 这里是一个雷达,要求首先记录这些计划。
更新: iOS 8具有类似的功能,用于打开您的应用程序的设置。谢谢苹果,麦克和 soto_iveoSt 。
常量 UIApplicationOpenSettingsURLString
(UIApplication文档)将打开您的应用程序的设置,而不是表示Twitter的设置。不是完全相同的功能,但比以前更清洁,现在正式认可。
这应该是额外的有用,现在每个应用程序在设置隐私,蜂窝数据,后台应用刷新和通知的设置中有一个地方。
其他提示
这有点棘手,我通过删除子视图来解决 *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];
}
}
你可以这样做。
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或方法的一些特殊键,如果它不是系统应用程序,请检查。