Framework for interacting with embedded WebView in iOS application

Last year around the same time I had written a post about Calling Objective-C code from JavaScript in iOS applications . I created a simple framework for it and described how to use it in that post.

Recently I was working on an application that required WebView to be embedded in the same View Controller along with other native iOS controls. I decided to use the above framework, but knew that  my ViewController class will have to extend WebViewController class of the framework. Though I could have done that, I thought separating the functionality of UIWebViewDelegate from the WebViewController would be a better design. So I replaced WebViewController with WebViewDelegate which implements UIWebViewDelegate protocol. I also removed getInitialPageName method from WebViewInterface.h . So here are the files in the new framework – Continue reading “Framework for interacting with embedded WebView in iOS application”

Using iOS Native Views in PhoneGap Projects

I am working on an iOS application where I want to use PhoneGap as well as a native iOS View. I want iOS view to be the first page from which user can navigate to a view created by PhoneGap. I have developed iOS applications either completely using PhoneGap or native APIs, but never tried to use both in the same application. So figuring out how to do that took some time and I thought I would share that here.

By the way, if you want to embed PhoneGap WebView into existing iOS project then follow instructions at Embedding WebViews. In this post I am going to explain how to embed native iOS view into a PhoneGap project and set it as the initial page.

First you create a PhoneGap project. I created the project using Command Line Interface of PhoneGap 3.1. Go to the folder where you want to create the project and run following command (I am assuming project name to be iOSPhoneGapProject here)

$ phonegap create iOSPhoneGapProject ram.kulkarni.iOSPhoneGapProject iOSPhoneGapApp

Continue reading “Using iOS Native Views in PhoneGap Projects”

Calling Objective-C code from JavaScript in iOS applications

In the last post I described how to Create iOS Application with HTML User Interface . In this post I am going to describe how to access Objective-C code from JavaScript running in the WebView. It is not as easy as it is in Android. There is no direct API in UIWebView to call native code, unlike in Android which provides WebView.addJavascriptInterface function.

However, there is a work-around. We can intercept each URL before it is being loaded in the WebView. So to call the native code, we will have to construct a URL and pass method name and argument as part of the URL. We then set this URL to window.location in the JavaScript and intercept it in our ViewController.
However most examples I have seen (including PhoneGap) create an instance of iframe and set its source to the URL –
Continue reading “Calling Objective-C code from JavaScript in iOS applications”

Creating iOS Application with HTML User Interface

Last year in April, I experimented with iOS development for the first time. I have described details in this post. I wanted to spend more time learning iOS application development then, however could not get around to actually doing that till very recently.

I had written a blog post on creating Android application using HTML user interface back in March last year. I was curious to know how to do the same in an iOS application.  In this post I will describe how to embed web view and set a URL in an iOS app and in the next post I would describe how to access native Objective-C code from JavaScript running in the web view control.

Continue reading “Creating iOS Application with HTML User Interface”

My Experiment with iOS Development

Last week I decided to experiment with iOS development. When I had started out learning Android development, it was not very difficult. Android programs are written in Java, which I have been using for many years and IDE used for Android development is Eclipse, which I have been using for many years now. All I had to get familiar was Android APIs.

However iOS development is very different for me. Applications are written in Objective-C, IDE is Xcode and they have to be developed on Mac platform using Cocoa framework. I have no experience with Objective-C, Xcode and Cocoa framework and have used Mac very little, only when I had to debug ColdFusion Builder issues specific to Mac. So I was not expecting smooth sailing; and I was not disappointed.
Continue reading “My Experiment with iOS Development”

Social