ios - Putting links in contact in UIWebView and display on different view controller -
i have view controller in have created simple contact app using apple's addressbook, have created view controller has web view create , displays contacts , phonenumber when user click on generate button. need that, on generate contacts should hyperlinks, , when click on contact should display details of contact have done in 1st view controller. know have use delete of webview not sure how implement it, far have written.
-(bool) webview:(uiwebview *)webview shouldstartloadwithrequest:(nsurlrequest *)request navigationtype:(uiwebviewnavigationtype)navigationtype { viewcontroller *latestview = [[viewcontroller alloc] initwithnibname:@"viewcontroller" bundle:nil]; [self.navigationcontroller pushviewcontroller:latestview animated:yes]; return yes; }
this function generates , displays contacts in webview, in want know how add hyperlink along contact details
- (ibaction)createfileaction:(id)sender { nsstring *tweet, *phonenumbers=@"", *temp, *allcontacts=@""; addressbooks =abaddressbookcreate(); cfarrayref people = abaddressbookcopyarrayofallpeople(addressbooks); (cfindex = 0; < cfarraygetcount(people); i++) { person12 = cfarraygetvalueatindex(people, i); tweet=[[nsstring stringwithformat:@"%@",(__bridge_transfer nsstring *)abrecordcopyvalue(person12, kabpersonfirstnameproperty)] stringbytrimmingcharactersinset:[nscharacterset whitespacecharacterset]]; //appending last name if(cfbridgingrelease(abrecordcopyvalue(person12,kabpersonlastnameproperty))!=null) { tweet=[tweet stringbyappendingstring:@" "]; tweet=[tweet stringbyappendingstring:[[nsstring stringwithformat:@"%@",(__bridge_transfer nsstring *)abrecordcopyvalue(person12, kabpersonlastnameproperty)] stringbytrimmingcharactersinset:[nscharacterset whitespacecharacterset]]]; } tweet=[@"<h5>" stringbyappendingstring:[nsstring stringwithformat:@"%@",tweet]]; if(cfbridgingrelease(abrecordcopyvalue(person12,kabpersonfirstnameproperty))!=null) { abmultivalueref multi = abrecordcopyvalue(person12, kabpersonphoneproperty); if(abmultivaluegetcount(multi)!=0) { //for fetching multiple phone numbers (int i=0; < abmultivaluegetcount(multi); i++) { temp = (__bridge nsstring*)abmultivaluecopyvalueatindex(multi, i); phonenumbers=[phonenumbers stringbyappendingstring:[nsstring stringwithformat:@"%@/",temp]]; } //for trimming characters in contacts (),-," " nscharacterset *trim = [nscharacterset charactersetwithcharactersinstring:@"()-\" \""]; phonenumbers = [[phonenumbers componentsseparatedbycharactersinset: trim] componentsjoinedbystring: @""]; phonenumbers=[phonenumbers substringtoindex:[phonenumbers length]- 1]; if([phonenumbers rangeofstring:@"/"].location!=nsnotfound) { phonenumbers = [phonenumbers stringbyreplacingoccurrencesofstring:@"/" withstring:@" / "]; } } else { phonenumbers=[phonenumbers stringbyappendingstring:@"no numbers"]; } tweet=[tweet stringbyappendingstring:@" ---> "]; tweet=[tweet stringbyappendingstring:[[nsstring stringwithformat:@"%@",phonenumbers] stringbytrimmingcharactersinset:[nscharacterset whitespacecharacterset]]]; phonenumbers=@""; nslog(@"%@",tweet); allcontacts = [allcontacts stringbyappendingformat:@"%@</h5>",tweet]; } } cfbridgingrelease(people); // create file [self.filemgr createfileatpath:file contents:nil attributes:nil]; [allcontacts writetofile:self.file atomically:no encoding:nsstringencodingconversionallowlossy error:nil]; //test if file exists have tried creating if([self.filemgr fileexistsatpath:self.file]) { nsstring *content = @"contact list generated click on view show list"; [webview loadhtmlstring:content baseurl:nil]; } else { nsstring *content = @"contact list not created yet, click on create generate contact list"; [webview loadhtmlstring:content baseurl:nil]; } }
can suggest modifications these 2 codes me achieve results??
if understand correctly, want have html links open , instance of viewcontroller. can create type of link <a href="myapp://{some_id_of_the_person}">click here</a>
, assuming want pass person's id viewcontroller.
then in [uiwebview webview:shouldstartloadwithrequest:navigationtype:]
check if request.url.scheme
matches scheme (myapp://
) in example:
- if yes, parse url person's id , open viewcontroller person (and
return no
method). - if not
return yes
(assuming there might other standard links in view should opened normally).
Comments
Post a Comment