简体   繁体   English

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

[英]How to open preferences/settings with iOS 5.1?

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中复制此功能的方法?

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*的子视图来*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 self instead of delegate . 在这里,委托是您的viewcontroller,如果您在viewcontroller中使用此方法,则只使用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];
    }
}

No I don't know a way to replicate this functionality. 不,我不知道复制此功能的方法。

But what you can do is file a Radar requesting the restoration. 但是您可以做的是向Radar申请恢复请求。 Here is a radar requesting that the schemes be documented in the first place. 这是一台雷达,要求首先记录这些方案。

David Barnard has confirmed that iOS 5.1 breaks the settings apps URL schemes. David Barnard已确认iOS 5.1破坏了设置应用程序的URL方案。


Update : iOS 8 has similar functionality for opening your app's settings. 更新iOS 8具有用于打开应用程序设置的类似功能 Thanks Apple, Mike and Soto_iGhost . 感谢Apple, MikeSoto_iGhost

The constant UIApplicationOpenSettingsURLString (UIApplication Documentation) will open the settings for your app and not, say Twitter's settings. 常量UIApplicationOpenSettingsURLString (UIApplication文档)将打开应用程序的设置,而不是Twitter的设置。 Not exactly the same functionality but much cleaner than before and now officially recognized. 功能不完全相同,但比以前更干净,现在已经正式认可。

This should be extra useful now that each app has a place in Settings for using privacy, cellular data, background app refresh and notifications. 由于每个应用程序在“设置”中都有一个使用隐私,蜂窝数据,后台应用程序刷新和通知的位置,因此这应该特别有用。

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

If you look in Twitter's framework (that Twitter view controller), it has "prefs:root=TWITTER" inside, 5.1 also has this line. 如果您查看Twitter的框架(该Twitter视图控制器),则其内部具有“ prefs:root = TWITTER”,而5.1也具有这一行。 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. 因此,Apple可能做出了一些禁用其他应用程序的操作,例如plist中的某些特殊键或方法“ openURL”,从而以某种方式检查它是否不是系统应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM