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

Jam*_*nes 35 iphone objective-c ipad ios ios5.1

看起来iOS 5.1已经破坏了用于将用户导航到Preference的标准URL编码.

例如:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=TWITTER"]];
Run Code Online (Sandbox Code Playgroud)

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

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

PJR*_*PJR 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];
        }

     } 
Run Code Online (Sandbox Code Playgroud)

在这里,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];
    }
}
Run Code Online (Sandbox Code Playgroud)


Joe*_*asq 11

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

但你可以做的是提交一份要求恢复的雷达.这是一个雷达,要求首先记录这些方案.

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


更新:iOS 8具有打开应用程序设置的类似功能.感谢Apple,MikeSoto_iGhost.

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

这应该是非常有用的,因为每个应用程序在设置中都有一个位置,用于使用隐私,手机数据,后台应用刷新和通知.

  • @zambono你能提供代码示例吗?我无法使用UIAlertView. (2认同)