如何在iOS 5.1中打开偏好设置?

35

看起来iOS 5.1已经破坏了用于导航用户到首选项的标准URL编码。

例如:

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

在iOS 5.0中可以正常工作,但在iOS 5.1中无法工作(无论是设备还是模拟器)。

是否有人找到了在iOS 5.1中复制此功能的方法?


哇,苹果很快就把那个移除了...你尝试过获取设置应用程序的Info.plist并检查是否有任何已注册的URL schemes吗? - fbernardo
1
我打开了Preferences.plist文件。看起来他们删除了kPreferencePositionKey的值(它曾经是prefs:...)。我发现了几个新的键(WebDatabaseDirectory,WebKitLocalStoreDatabasePathPreferenceKey,AutomaticMinimizationEnabled和UserDictionarySampleShortcutsAdded)。其中一些听起来很有趣,现在有趣的部分是从哪里开始。 - James Jones
自动最小化听起来确实很有趣... - fbernardo
请停止发布错误的URL。 - Swati
4个回答

13

这有点棘手,我通过删除*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];
    }
}

这是我找到的唯一有效的解决方案!谢谢! - Eduardo Cobuci
@EduardoCobuci,你能把后台的推文框去掉吗?我看到了设置/取消警报,但是后面有一个推文框,我们该如何移除它? - Jatin

11

对不起,我不知道复制此功能的方法。

但是您可以提交一个Radar请求恢复此功能。 这里有一个Radar 请求首先记录这些scheme的文档。

David Barnard 已经确认iOS 5.1破坏了设置应用程序的URL schemes。


更新: iOS 8有类似的功能 用于打开您的应用程序的设置。感谢苹果、MikeSoto_iGhost

常量UIApplicationOpenSettingsURLString (UIApplication Documentation)将打开您的应用程序的设置,而不是Twitter等的设置。虽然不完全相同,但比以前更加清晰,并得到了官方认可。

现在每个应用程序都有一个在设置中使用隐私、蜂窝数据、后台应用程序刷新和通知的位置,所以这应该特别有用。


1
这确实不是好消息。我们也在企业应用程序中为客户使用了这个。 - axooh
如果按钮在警报中,似乎仍然可以工作,但不适用于 UI 上的常规按钮。 - zambono
1
我刚刚在我的苹果应用程序中注意到了这一点,如果我有一个常规按钮或表视图中的操作来转到设置,它不会做任何事情,但UIAlertView中的按钮确实有效。 - zambono
2
@zambono,你能提供一个代码示例吗?我无法在UIAlertView中使其工作。 - lari
1
@JoePasq 看起来在iOS8中我们可以再次从应用程序内部打开设置。https://dev59.com/foLba4cB1Zd3GeqPlOoh#25558855 你能编辑这个答案吗? - Soto_iGhost
显示剩余2条评论

3

你可以做到这一点。

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 帐户后它没有返回应用程序,而且警报仍然存在 :( - Zubair
请查看以下链接:http://facebook.stackoverflow.com/questions/14950678/calling-uialertview-clickedbutton-at-index-programatically - Zubair

1

如果你查看Twitter的框架(即Twitter视图控制器),它内部有“prefs:root=TWITTER”的内容,5.1版本也有这一行。因此,很可能苹果公司做了一些事情来禁用其他应用程序的此功能,例如在plist中设置某些特殊键或方法“openURL”会检查是否为系统应用程序。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接