【问题标题】:How to open preferences/settings with iOS 5.1?如何使用 iOS 5.1 打开首选项/设置?
【发布时间】:2012-03-26 12:20:08
【问题描述】:

看起来 iOS 5.1 破坏了用于将用户导航到偏好设置的标准 URL 编码。

例如:

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

适用于 iOS 5.0,但不适用于 iOS 5.1(设备和模拟器)。

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

【问题讨论】:

  • 哇,Apple 很快就删除了那个...您是否尝试过获取“设置”应用的 Info.plist 并检查是否有任何已注册的 URL 方案?
  • 我打开了 Preferences.plist。看起来他们删除了 kPreferencePositionKey 的值(以前是 prefs:...)。我看到了几个新键(WebDatabaseDirectory、WebKitLocalStoreDatabasePathPreferenceKey、AutomaticMinimizationEnabled 和 UserDictionarySampleShortcutsAdded)。其中一些听起来很有趣,现在有趣的部分是从哪里开始。
  • 自动最小化听起来确实很有趣...
  • 停止发布不良网址

标签: iphone objective-c ios ipad ios5.1


【解决方案1】:

不,我不知道如何复制此功能。

但是你可以做的是提交一个雷达请求恢复。 Here is a radar 要求首先记录方案。

David Barnard 已确认 iOS 5.1 破坏了设置应用程序 URL 方案。


更新iOS 8 has similar functionality 用于打开您应用的设置。感谢 Apple,MikeSoto_iGhost

常量 UIApplicationOpenSettingsURLString (UIApplication Documentation) 将打开您的应用程序的设置,而不是 Twitter 的设置。功能不完全相同,但比以前更干净,现在得到官方认可。

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

【讨论】:

  • 感谢您的回复。这是一个很大的麻烦,不知道为什么 Apple 觉得有必要删除这个功能。
  • 这些确实不是好消息。我们也将它用于企业应用程序中的客户端。
  • 我只是在苹果发布的我自己的应用程序中注意到它,如果我有一个常规按钮或表格视图中的一个动作去设置它什么都不做,但一个按钮在UIAlertView 确实有效。
  • @zambono 你能提供一个代码示例吗?我无法让它与 UIAlertView 一起使用。
  • @JoePasq 看来我们可以在 iOS8 中再次从应用程序内打开设置。 stackoverflow.com/a/25558855/2376248你能编辑答案吗?
【解决方案2】:

如果你查看 Twitter 的框架(即 Twitter 视图控制器),它里面有“prefs:root=TWITTER”,5.1 也有这一行。因此,Apple 可能会为其他应用程序禁用它,例如 plist 中的一些特殊键或方法“openURL”以某种方式检查它是否不是系统应用程序。

【讨论】:

    【解决方案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];
                        }
    

    【讨论】:

    【解决方案4】:

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

    在这里,delegate 是您的视图控制器,如果您在视图控制器中使用此方法,只需使用 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];
        }
    }
    

    【讨论】:

    • 这是我找到的唯一可行的解​​决方案!谢谢!
    • @EduardoCobuci 你能在后台删除推文框吗?我看到设置/取消警报,但后面有一个推文框,我们如何删除它?
    猜你喜欢
    • 2012-04-20
    • 1970-01-01
    • 1970-01-01
    • 2012-07-04
    • 2012-04-12
    • 2020-02-21
    • 2011-07-16
    • 1970-01-01
    • 2011-09-14
    相关资源
    最近更新 更多