如何检测iPhone上是否禁用了Safari

时间:2010-06-15 02:46:12

标签: objective-c iphone safari

如何检测Safari是否已被家长控制禁用?我知道这是可能的,因为在禁用Safari之前,App X3Watch拒绝工作。据我所知,父母控制没有api,那么可以使用什么技术呢?

2 个答案:

答案 0 :(得分:4)

我没有对此进行测试,但是OS3.0及更高版本,您可以使用[[UIApplication sharedApplication] canOpenURL:myURL]检测系统上的任何应用程序是否可以打开URL。我敢打赌,如果Safari被禁用,它将返回NO

答案 1 :(得分:0)

这是我尝试在视图控制器中包含此解决方案。需要使用两个bool,因为用户可以在加载视图时独立于safari打开外部程序,但是还没有打开需要safari的按钮。

@implementation ViewController {
@private BOOL externalProgramOpened;
@private BOOL buttonPressed;
}

-(void) setExternalProgramOpened {
    // Only set to yes if we're trying to open safari
    if(buttonPressed) {
        externalProgramOpened = YES;
    }
}

-(void) notifyUserOfRestrictedAccess {

    if(externalProgramOpened == NO) {
            [[[UIAlertView alloc] initWithTitle:@"Safari Needs to be enabled!"
                                    message:@"It looks like the Safari browser is
                                              disabled. Please enable it 
                                              (Settings>General>Restrictions) in order to 
                                              continue."
                                   delegate:nil
                          cancelButtonTitle:@"Ok"
                          otherButtonTitles: nil] show];
    } else {
        externalProgramOpened = NO;
    }

    buttonPressed = NO;
}

-(void) viewWillAppear:(BOOL)animated {
    externalProgramOpened = NO;
    buttonPressed = NO;

    [[NSNotificationCenter defaultCenter] addObserver:self 
                                          selector:@selector(setExternalProgramOpened)
                                          name:UIApplicationWillResignActiveNotification 
                                          object:nil];
}

-(void) viewWillDisappear:(BOOL)animated {

    [[NSNotificationCenter defaultCenter] removeObserver:self 
                                          name:UIApplicationWillResignActiveNotification
                                          object:nil];
    [super viewWillDisappear:animated];

}

- (IBAction)buttonPressed:(id)sender {
    buttonPressed = YES;

    NSString * URL = *someURL*;

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:URL]];

    [self performSelector:@selector(notifyUserOfRestrictedAccess) withObject:self 
               afterDelay:.75];
}