uiwebview - create a InApp browser implementation in iOS app -
i have requirement in have create view display webpages back, forward , refresh button in ios app. how implement functionality?
use uiwebview
. set delegate view controller.
self.webview.delegate = self;
other remarkable properties,
self.webview.scalespagetofit = yes;
to load urlrequest,
[self.webview loadrequest:therequest];
or strings, use
[self.webview loadhtmlstring:htmlstring baseurl:nil];
and delegates here. web view has own history, can use calling , forward methods.
#pragma mark - uiwebview delegate // can handle own url scheme or let web view handle it. - (bool)webview:(uiwebview *)webview shouldstartloadwithrequest:(nsurlrequest *)request navigationtype:(uiwebviewnavigationtype)navigationtype { nslog(@"url=%@, %@, %@", request.url, request.url.query, request.url.host); if (navigationtype == uiwebviewnavigationtypelinkclicked) { if ([request.url.scheme compare:@"customescheme"] == nsorderedsame) { if ([request.url.host compare:ksomethingdotcom] == nsorderedsame) { [self mymethod]; } else if ([request.url.host compare:kanotherdotcom] == nsorderedsame) { [self method2]; } else { nslog(@"unsupported service."); } return no; } } return yes; } - (void)webviewdidfinishload:(uiwebview *)webview { [_activityindicator stopanimating]; } - (void)webview:(uiwebview *)webview didfailloadwitherror:(nserror *)error { [_activityindicator stopanimating]; [resources showalert:@"could not load." withtitle:@"error!"]; nslog(@"%@", [error localizeddescription]); } #pragma mark - actions - (ibaction)didpressbackbutton:(id)sender { [_webview goback]; } - (ibaction)didpressforwardbutton:(id)sender { [_webview goforward]; }
similarly can have stop method. refresh reload request again. before going or forward can check methods cangoback or cangoforward. see docs at, http://developer.apple.com/library/ios/#documentation/uikit/reference/uiwebview_class/reference/reference.html
Comments
Post a Comment