2010-06-15 82 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]; 
} 
相關問題