35

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

例如:

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

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

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

4

4 回答 4

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 是您的视图控制器,如果您在视图控制器中使用此方法,只需使用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];
    }
}
于 2012-10-23T09:32:55.640 回答
11

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

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

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


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

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

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

于 2012-03-12T18:59:35.633 回答
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];
                    }
于 2012-08-29T11:09:56.510 回答
1

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

于 2012-03-16T19:57:58.897 回答