如何使用 iOS 5.1 打开首选项/设置?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9627451/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 17:14:19  来源:igfitidea点击:

How to open preferences/settings with iOS 5.1?

iphoneobjective-ciosipadios5.1

提问by James Jones

Looks like iOS 5.1 has broken the standard URL encoding for navigating a user to a Preference.

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

For example:

例如:

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

Works in iOS 5.0 but not in iOS 5.1 (both device and simulator).

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

Has anyone found a way to replicate this functionality in iOS 5.1?

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

采纳答案by JoePasq

No I don't know a way to replicate this functionality.

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

But what you can do is file a Radar requesting the restoration. Here is a radarrequesting that the schemes be documented in the first place.

但是您可以做的是提交请求恢复的雷达。这是一个雷达,要求首先记录这些计划。

David Barnardhas confirmed that iOS 5.1 breaks the settings apps URL schemes.

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



Update: iOS 8 has similar functionalityfor opening your app's settings. Thanks Apple, Mikeand Soto_iGhost.

更新iOS 8 具有用于打开应用设置的类似功能。感谢 Apple、MikeSoto_iGhost

The constant UIApplicationOpenSettingsURLString(UIApplication Documentation)will open the settings for your app and not, say Twitter's settings. Not exactly the same functionality but much cleaner than before and now officially recognized.

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

This should be extra useful now that each app has a place in Settings for using privacy, cellular data, background app refresh and notifications.

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

回答by PJR

It is little tricky , i get by the removing the subviews in *TWTWeetComposeViewController*, so it shows only alert when user is not loged in and by the clicking on setting button , we can open Setting page in my app.

这有点棘手,我通过删除中的子视图获得*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];
        }

     } 

here , delegate is your viewcontroller , if you are using this method inside your viewcontroller just use selfinstead of delegate.

在这里,delegate 是您的视图控制器,如果您在视图控制器中使用此方法,只需使用self而不是delegate.

EDIT:If you get any deprecated errors, use the following iOS6 compatible code instead:

编辑:如果您收到任何已弃用的错误,请改用以下 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];
    }
}

回答by Saad

you can do this.

你可以这样做。

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

回答by artysx

If you look in Twitter's framework (that Twitter view controller), it has "prefs:root=TWITTER" inside, 5.1 also has this line. So probably Apple made something to disable it for other apps, like some special key in plist or method "openURL" somehow checks if it's not a system app.

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