cordova - Using PhoneGap Cleaver in iOS to override method -
i using phonegap 2.3 - cleaver ios.
how can override shouldstartloadwithrequest, webviewdidstartload, webviewdidfinishload function?
if add "viewcontroller.webview.delegate = self" viewdidload, functions above can called phonegap api cannot invoked.
thanks.
myviewcontroller.m:
- (void)viewdidload { [super viewdidload]; cdvviewcontroller* viewcontroller = [cdvviewcontroller new]; viewcontroller.view.frame = self.view.bounds; //viewcontroller.webview.delegate = self; nsurlrequest *request = [nsurlrequest requestwithurl:[nsurl urlwithstring:landingurl]]; [viewcontroller.webview loadrequest:request]; [self.view addsubview:viewcontroller.view]; [self addchildviewcontroller:viewcontroller]; }
myviewcontroller.h:
@interface myviewcontroller : uiviewcontroller <uiwebviewdelegate> @end
you shouldn't override shouldstartloadwithrequest because there manage javascript urls call native functions.
or @ least copy code cdvviewcontroller view controller , add things need.
example phonegap 2.9.1
- (bool)webview:(uiwebview*)thewebview shouldstartloadwithrequest:(nsurlrequest*)request navigationtype:(uiwebviewnavigationtype)navigationtype { nsurl* url = [request url]; /* * execute commands queued cordova.exec() on js side. * part of url after gap:// irrelevant. */ if ([[url scheme] isequaltostring:@"gap"]) { [_commandqueue fetchcommandsfromjs]; return no; } /* * if url being loaded that's file/http/https url, load internally */ else if ([url isfileurl]) { return yes; } /* * if loaded html string, let app handle */ else if (self.loadfromstring == yes) { self.loadfromstring = no; return yes; } /* * tel: scheme urls let uiwebview handle using default behavior */ else if ([[url scheme] isequaltostring:@"tel"]) { return yes; } /* * about: scheme urls not handled */ else if ([[url scheme] isequaltostring:@"about"]) { return no; } /* * data: scheme urls handled */ else if ([[url scheme] isequaltostring:@"data"]) { return yes; } /* * handle other types of urls (tel:, sms:), , requests load url in main webview. */ else { if ([self.whitelist schemeisallowed:[url scheme]]) { return [self.whitelist urlisallowed:url]; } else { if ([[uiapplication sharedapplication] canopenurl:url]) { [[uiapplication sharedapplication] openurl:url]; } else { // handle custom schemes plugins [[nsnotificationcenter defaultcenter] postnotification:[nsnotification notificationwithname:cdvpluginhandleopenurlnotification object:url]]; } } return no; } return yes; }
the if ([[url scheme] isequaltostring:@"gap"])
manages phonegap calls
btw, shouldn't use phonegap 2.3, need @ least 2.5 pass apple store guidelines added in may, versions previous 2.5 used udid , it's forbidden apple
Comments
Post a Comment