2010-06-15 83 views
5

禁用您如何检测是否Safari浏览器已经在iPhone上的家长控制禁用如何检测?我知道这是可能的,因为App X3Watch拒绝工作,直到Safari被禁用。据我所见,家长控制没有api,那么可以使用哪种技术呢?如果是Safari浏览器在iPhone上

回答

4

我没有测试过这一点,但OS3.0或更高版本,可以检测一个URL可以用[[UIApplication sharedApplication] canOpenURL:myURL]系统上的任何应用程序中打开。我敢打赌,如果Safari被禁用,它将返回NO

+0

是的,我试过了,你说得对。谢谢! – zorro2b 2010-06-19 12:33:16

+2

这是否仍然有效?我在iOS 6(iPad 3)上尝试了这一点,但即使在限制中禁用了Safari,它也会返回YES。但是,如果我实际调用openURL :, Safari在禁用时不会打开,如预期的那样。 – Michael 2012-11-01 17:19:32

+2

回答我自己的问题:[链接](http://stackoverflow.com/questions/12771177/uiapplications-canopenurl-openurl-return-misleading-result) – Michael 2012-11-01 17:51:38

0

这里是我的尝试包括在一个视图控制器解决这个。这两个布尔需要使用,因为用户可以在加载视图时独立于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]; 
} 
相关问题