• Home
  • Blog
  • Determine file extension on tap and push view controlelr

Determine file extension on tap and push view controlelr

0 comments

Basically I need to know how a webview knows what kind of file extension is being tapped, (png, zip, etc) and then push another view controller. So far I have this.

UPDATE 6/13 – I have updated my code per what Hunter has suggested, yet it still only opens the png, instead of pushing the vc.

    – (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {        

       

        if(navigationType == UIWebViewNavigationTypeLinkClicked) {

            NSURL *theRessourcesURL = [request URL];

            NSString *fileExtension = [theRessourcesURL pathExtension];

            if ([fileExtension isEqualToString:@”png”]) {

               

                MYViewController *vc = [[MYViewController alloc] init];

                [dlvc downloadURL:theRessourcesURL userInfo:nil];

                [self.navigationController pushViewController:vc animated:YES];

               

                vc.delegate = self;

            }            

            else{}

        }      

        return YES;

    }

I have tried this before without the file extension code and it will push another view just fine.

    – (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {

        if(navigationType == UIWebViewNavigationTypeLinkClicked) {

            NSURL *theRessourcesURL = [request URL];

   

   

            DetailViewController *vc = [[DetailViewController alloc] init];

            [vc downloadURL:theRessourcesURL userInfo:nil];

            [self.navigationController pushViewController:vc animated:YES];

   

            vc.delegate = self;

   

        }

   

        return YES;

    }

I also tried to use this as a starter base without success, as I don’t use interface builder, so I don’t know if IBActions can be used (if they can I dont know how to implement them properly). http://stackoverflow.com/questions/7377565/how-to-download-files-from-uiwebview-and-open-again

Any help would be appreciated.

About the Author

Follow me


{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}