2011-05-26 18 views
6

Quiero abrir un enlace de iTunes en mi webView, pero cuando el webView inicia la página, se redirige al navegador Safari. Allí, la URL se está abriendo, pero quiero que se abra en mi webView.UIWebView enlaces de apertura en Safari

- (void)viewDidLoad { 

    NSString *urlAddress = @"http://itunes.apple.com/us/app/foodcheck-traffic-light-nutrition/id386368933?mt=8"; 

    //Create a URL object. 
    NSURL *url = [NSURL URLWithString:urlAddress]; 

    //URL Requst Object 
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; 

    //Load the request in the UIWebView. 
    [webView loadRequest:requestObj]; 

    [super viewDidLoad]; 
} 

Por favor, sugiera una forma de solucionar este problema.

Respuesta

1

Es posible que desee intentar el registro de las solicitudes de carga cuando ejecuta la aplicación. Puede ser que la manzana cambie automáticamente http:// a itms-apps o http://phobos o algo similar. Si es así, entonces puede bloquear la carga cuando es llamada utilizando algo como esto:

- (BOOL)webView:(UIWebView *)webView 
shouldStartLoadWithRequest:(NSURLRequest *)request 
navigationType:(UIWebViewNavigationType)navigationType; 
{ 
    NSURL *loadURL = [[request URL] retain]; 
    NSLog(@"%@",loadURL); 
    if([[loadURL absoluteString] hasPrefix:@"http://"]) 
    { 
     [loadURL release]; 
     return TRUE; 
    } 
    [loadURL release]; 
    return FALSE; 
} 

Buena suerte. Tengo curiosidad por saber lo que finalmente funciona.

+0

gracias mucho por su response.But muy rápido todavía no está mostrando. – Gypsa

+0

¿Qué obtienes de los registros? ¿Hay una redirección? – PengOne

+0

Usa el código de PengOne y necesitas implementar UIWebViewDelegate en tu ViewController así como también establecer un delegado para tu WebView en viewDidLoad – Xuvi

0

No estoy seguro de si alguna vez tengo trabajo, pero esto funciona bien para mí:

NSString *responseString = [NSString stringWithContentsOfURL:myURL]; 
[self.webView loadHTMLString:responseString baseURL: nil)]; 
Cuestiones relacionadas