How to determine if Safari is disabled on iPhone

How can you determine if Safari is disabled by parent controls on the iPhone? I know this is possible because the X3Watch application refuses to work until Safari is shut down. As far as I can see, there is no api for parental control, so which method can I use for this?

+5
source share
2 answers

I have not tested this, but it is OS3.0 and later, you can determine if the URL can be opened by any application on the system using [[UIApplication sharedApplication] canOpenURL:myURL]. I will return, it will return NOif Safari is disabled.

+4
source

. bools, , , , .

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

All Articles