html - Injecting local files into UIWebView without breaking links -


i working on ios app needs display webpages server inside uiwebview while injecting relevant local png , css files needed in order speed load time. here code using try this:

nsdata *myfiledata = [[nsdata alloc] initwithcontentsofurl:[nsurl urlwithstring:[nsstring stringwithformat:@"http://www.example.com/index.html"]]]; nsstring* myfilehtml = [[nsstring alloc] initwithdata:myfiledata encoding:nsasciistringencoding]; [mywebview loadhtmlstring:myfilehtml baseurl:[nsurl fileurlwithpath:[[nsbundle mainbundle] bundlepath]]]; 

my problem of webpages have buttons in them link other webpages on server, , because uiwebview loading string, buttons when tapped don't cause uiwebview load new webpage url if had used loadrequest method.

my question how can the uiwebview behave loading request while still injecting local files baseurl?

thanks

the relative links in button cannot work, because linked pages on remote server , not on device's file system. can use uiwebviewdelegate method make work:

- (bool)webview:(uiwebview *)webview shouldstartloadwithrequest:(nsurlrequest *)request navigationtype:(uiwebviewnavigationtype)navigationtype {      if (navigationtype == uiwebviewnavigationtypelinkclicked) {         nsstring *localrootpath = [nsstring stringwithformat:@"file://%@", [[nsbundle mainbundle] bundlepath]];         nsstring *remoterootpath = @"http://yourdomain.com";          nsstring *remotepath = [[request.url absolutestring] stringbyreplacingoccurrencesofstring:localrootpath withstring:remoterootpath];           [self.webview loadrequest:[nsurlrequest requestwithurl:[nsurl urlwithstring:remotepath]]];          // or can use own loading mechanism here          return no;     }      return yes; } 

this method intercepts requests webview. if request triggered user tap / click url gets modified relative url absolute url can loaded server. don't forget set delegate on webview or method not called.


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -