Bridging calls between native and webview content

Pugpig allows you to implement custom actions in response to events in your content. For example, you might want to intercept taps on images and have them open in a modally presented view. You could even intercept taps on certain URLs and direct them to specific built-in resources like your device's built-in Mail or Browser app.

The Pugpig framework provides delegate methods for the KGPagedDocumentControl class that lets you intercept URL change events. Implementing these delegate methods will allow you to customise the behaviour in response to these URL events.

- (BOOL)document:(KGPagedDocControl*)doc didClickLink:(NSURL*)url;

This method gets called when a link to a URL is tapped in the content. Returning YES indicates you are handling it internally to the method and NO indicates that the standard framework behaviour should be observed. Any URL scheme is accepted EXCEPT pugpig:// URLs, which are handled by

- (void)document:(KGPagedDocControl*)doc didExecuteCommand:(NSURL*)url;

This gets called specifically when URLs with the pugpig:// scheme are tapped. You can then filter specific URL taps out and handle them with custom code. An example is that you could filter by the host of the URL to handle a certain type of link.

The most reliable way to forward a pugpig:// link to the native code is to use an iframe:

var Messaging =(function(){
 function Messaging(){}

 Messaging.fn = Messaging.prototype;
 Messaging.fn.postMessage = function( message ){
   var iframe = document.createElement("IFRAME");
   iframe.setAttribute("src","pugpig://"+ message);
   iframe = null;

 return new Messaging();

and then invoke it like this:


The first method operates in conjunction with the standard KGPagedDocumentControl method

- (void) setLinksOpenInExternalBrowser:(BOOL)shouldopen;

which determines whether to open in the iOS default external browser app, typically Mobile This behaviour will occur when the delegate method returns NO.

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request


Powered by Zendesk