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

时间:2012-03-09 00:53:04

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

看起来iOS 5.1已经破坏了用户导航到偏好的标准URL编码。

例如:

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

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

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

4 个答案:

答案 0 :(得分: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];
        }

     } 

这里,delegate是你的viewcontroller,如果你在viewcontroller中使用这个方法,只需使用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];
    }
}

答案 1 :(得分:11)

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

但是你可以做的是提交请求恢复的雷达。 Here is a radar要求首先记录这些计划。

David Barnard已确认iOS 5.1违反设置应用程序URL方案。


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

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

现在,每个应用在“设置”中都有一个用于使用隐私,移动数据,后台应用刷新和通知的位置,这应该会非常有用。

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

答案 3 :(得分:1)

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

相关问题