Reputation: 2257
How can you detect whether Safari has been disabled by parental controls on the iPhone? I know it is possible because the App X3Watch refuses to work until Safari is disabled. As far as I can see there is no api for the parental controls, so what technique can be used for this?
Upvotes: 5
Views: 1522
Reputation: 772
Here's my attempt to include the solution to this in a view controller. The two bools need to be used because a user can open an external program independently of safari when the view is loaded, but the button that needs safari hasn't been opened yet.
@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];
}
Upvotes: 0
Reputation: 213
I haven't tested this, but is OS3.0 and later, you can detect if a URL can be opened by any application on the system using [[UIApplication sharedApplication] canOpenURL:myURL]
. I'll betcha it will return NO
if Safari is disabled.
Upvotes: 4