a.k.a devgeeks

Software development in the minutes a day I have spare

Finally submitted

It’s been almost two months since my last post, but that’s because I have been working hard on a new app. In fact, an entire new product.

I’ll be able to post more soon including some of the custom plugins I wrote for the app.

It’s a camera-based app at heart so I needed a custom camera overlay view as well as some changes to make the camera more responsive (there was a horrible delay after clicking the “use” button in the core PhoneGap Camera API).

I am hoping to find a way to make the camera functionality open source and abstract enough that it would be useful to someone else.

Until then, stay tuned? ;)

One of the developers working on the new PhoneGap-based Wikipedia Mobile was having some annoying issues with the PhoneGap ShareKit plugin and decided he’d rather just put the Facebook and Twitter sharing in with their individual plugins. 

He was happy with the decision where Facebook and Twitter were concerned, but lamented that the decision would mean there would no longer be support for Read it Later (http://readitlaterlist.com).

I had a look at Read it Later’s API and iOS SDK and it looked fairly straight forward, so when he asked if I would like to write a plugin for it I took on the challenge.

Just two hours later I had a shiny new PhoneGap plugin!

https://github.com/devgeeks/ReadItLaterPlugin

If you wanna be as cool as Wikipedia, run over to GitHub and clone it into your app now! 

Installation

This plugin allows you to save a URL to Read It Later from your app.

Add the plugin much like any other:

  1. Add the ReadItLaterPlugin.h and VolumeSlider.m classes to your Plugins folder in Xcode (use “Create groups for any added folders”)
  2. Add the ReadItLaterPlugin.js file to your www folder
  3. Add the ReadItLaterPlugin.js to your html file. eg:<script type="text/javascript" charset="utf-8" src="ReadItLaterPlugin.js"></script>
  4. Add the plugin to the PhoneGap.plist under Plugins (key: “ReadItLaterPlugin” value: “ReadItLaterPlugin”)

Next, get the Read It Later API iPhone Library and add it to your project:

  1. Download the library from Read It Later
  2. Unzip the library and examples
  3. Copy these four files into your Xcode project under the Plugins folder (again, use “Create groups for any added folders”)
    • ReadItLaterLite.h
    • ReadItLaterLite.m
    • ReadItLaterFull.h
    • ReadItLaterFull.m
  4. Get an API Key from Read It Later for your app
  5. Add your shiny new API key to the top of the ReadItLaterLite.m file you copied in above
    • static NSString *apikey = @"<api key here>";
  6. Add the name of your app (as you entered it to get your API key above) as well
    • static NSString *nameOfYourApp = @"<name of your app here>";

Finally, call the saveToReadItLater() method using a success callback and an object containing a url and a title:

Example

function onDeviceReady()
{
    var readItLaterPlugin = window.plugins.readItLaterPlugin;
    readItLaterPlugin.saveToReadItLater(
        function(){
            console.log("Successfully saved to Read It Later");
        }, 
        { 
            url: "http://github.com/devgeeks", 
            title: "Devgeeks on GitHub"
        }
    );
}

The PhoneGap installer for iOS overwrites the old version when you run it. It puts itself in over the top of your previous version.

However, when you have shipped an app with PhoneGap and it’s happily in the App Store, the last thing you want to do is have to deal with changes in the PhoneGap API between versions if you need to make small maintenance tweaks down the track. 

Here’s what I do in this instance.

  1. Before upgrading PhoneGap (running the installer) I back up the previous version of the framework. I copy ‘/Users/Shared/PhoneGap’ to ‘/Users/Shared/PhoneGap-<version>’ (such as ‘/Users/Shared/PhoneGap-1.2’).
  2. Next I go into the projects that I want to keep running that version, and I delete the PhoneGap.framework from the project (remove reference only). 
  3. Then I add the framework from the copied versioned folder I made in step #1. Select the target in Xcode, choose the “Build Phases” tab, open the “Link Binary With Libraries” section and click the + and choose “Add Other…”, browse to where you backed up your old PhoneGap.framework and add it in.
  4. Upgrade PhoneGap to latest version.

You now not only have a back up you can keep old projects maintained against, but you have a version you can use if the new PhoneGap changes something you want to use or breaks a plugin you need for your project. In fact, inside the ‘/Users/Shared/PhoneGap-1.2/Frameworks/PhoneGap.framework/www’ folder is the version-specific PhoneGap iOS JavaScript file if you need to downgrade a project.

It looks like those of us who rely heavily on plugins are in for a bad time.

Cordova devs working on 1.4.x began the process of deprecating some classes a great many plugins used, now it looks like the work on 1,5 and beyond is going to make the plugin landscape even shakier.

The work on the new unified js will be a great boon to many end users making it easier to develop for multiple platforms. Unfortunately, it looks like it is also going to be only a partial implementation on 1.5 and one that not only might break things for existing apps and/or plugins… but might not even be the final API we see shipped with 1.6…

…we’ve made no commitment on the plugin api (its never been official) so I don’t feel we’re breaking any promises

…and concerns about it are being dismissed.

I don’t know about you, but I think I might stick with 1.4.x for now unless a bug comes up that will make it worth it to me to work around these teething issues in the coming releases.

I do know the PhoneGap Google group, IRC and StackOverflow are gonna get an influx of confused devs very soon. I’m bracing for it.

In PhoneGap (in reality Cordova) 1.4.x some classes were deprecated in the effort to make it play nice as a component in an otherwise native app (as opposed to only being able to be the primary controlling view). This is causing some confusion when developers using this version try to use plugins written using those classes. Xcode is giving them warnings about the deprecation and making them worry.

The plugins affected are mostly those that pop up an entire native view controller over the top of the PhoneGap/Cordova app - EmailComposer, SMSComposer, Twitter and worst of all ChildBrowser.

The important thing to remember is that for now (1.4.x), although the methods are deprecated, they should still work just fine. They will warn you, but as a good friend of mine was fond of saying: “a warning is not an error”. The point of deprecation warnings are to warn you that what you are doing might go away some time in the future and to start thinking about a new way to do it.

AFAIK, the issue will be with the coming releases when the methods are actually removed (there is debate on if this should be soon… like 1.5 or 1.6… or wait for a major release like 2.0).

I am happy to update plugins and submit pull requests to the phonegap-plugins repo if the plugin is not being actively maintained or not overly complex. I have already submitted a pull request for an update to SMSComposer after someone asked for help in the PhoneGap IRC channel. As for any of the others affected, it might be that they will just use the deprecated calls until the upcoming plugin upgrade guide is ready I believe with 1.5.x.

In the case of most of the affected plugins, really all you should need to do is in the plugins PluginClassName.m file add in this initialization method just after ‘@implementation PluginClassName’ (note: this one might be optional, but most of the modern plugins seem to initialize self this way):

-(PGPlugin) initWithWebView:(UIWebView)theWebView 
{     
    self = (PluginClassName*)[super initWithWebView:theWebView];     
    return self; 
{

Then, where ever the deprecated ‘appViewController’ appears… change:

[[ super appViewController ] presentModalViewController:picker animated:YES];

to:

[self.viewController presentModalViewController:picker animated:YES];

This will make most of the basic plugins compile quite happily without warnings. Unfortunately… ChildBrowser not so much, but that plugin is far from simple. However, it is very popular so I am sure it will get some love before the deprecations truly take effect.

If you have any questions about this feel free to shoot me a message:

tommy AT devgeeks DOT org

Dear 4ZzZfm and lovers of the best community radio station ever

The 4ZzZfm iPhone app has been updated to version 3.0. This new version should always have an up to date Program Guide. It can now update the guide over the internet so it will no longer need an updated version to have a correct guide.

http://devgeeks.org/iphone-apps/4zzzfm-iphone

or on iTunes:

http://itunes.apple.com/au/app/4zzzfm/id359090535?mt=8

oh… and for those that have brought it up whenever the 4ZzZfm iPhone app is mentioned…

Meet the 4ZzZfm Android app!:

http://devgeeks.org/android-apps/4zzzfm-android-app

or on the Android Market:

https://market.android.com/details?id=org.devgeeks.fourzzzfm

So here we are. Almost four months to the day since I last posted about porting the 4ZzZfm iPhone app to PhoneGap, it’s finally awaiting review in the App Store.

A lot has changed from starting out to getting to this point. I’ll be writing a much bigger post about the whole experience (including my new-found hate for timezones and date math), but till then… I am just happy to see the back end of it. :)

Now let’s see if we can get past the approval process OK.

It’s that time again. Time to update the 4ZzZfm iPhone app. Actually, it’s way past due… but this is the way things go sometimes.

Early on I attempted to use some of the “write your app in HTML/Javascript/CSS and deploy to iPhone” technologies, but at the time their acceptability by Apple for App Store distribution was in doubt, and I couldn’t get them to do what I wanted anyway. This meant I had to actually learn Objetive-C. Now let me just say that I really like Objective-C. The problem is that I am primarily a PHP developer so HTML/JavaScript/CSS feels more natural to me.

This has lead me to revisit the above-mentioned web technology options for iPhone app development. PhoneGap in particular seems to be both quite mature, used a great deal in apps in the App Store and quite extendable via plugins. This last part is the bit that has tipped it for me. Not only are there some great plugins available for PhoneGap, but it is quite easy to write your own plugins.

What this all comes down to is that I am going to try and re-write the 4ZzZfm iPhone app using PhoneGap and write whatever plugins I need along the way that aren’t catered for in PhoneGap’s core or plugins written by others.

I have already started on this process and I have the Audio Streaming classes written by the amazing Matt Gallagher (cocoawithlove.com) that I used in the original Objective-C version of the app (mostly) working as a PhoneGap plugin. The remote control events don’t work yet, and I am not sure that will be possible from a plugin anyway… that might require some hacking of the PhoneGap core. We’ll see. It needs some more work update: I have had the remote control events working fine. No core hacking needed. Then between updating PhoneGap and iOS something went wrong.

Another piece of functionality I need for the 4ZzZfm iPhone app is a volume control slider. In the Objective-C iPhone SDK that is implemented using an MPVolumeView (from the MediaPlayer framework).  This turned out to be a very easy to make into a PhoneGap plugin. Now one of the best things about PhoneGap is that it and its plugins are open source. PhoneGap and its plugins are developed by the PhoneGap community and available on GitHub. So I have decided to join GitHub myself and submit any plugins I create for this project that I think others might find useful. The first of these that have been added to the main PhoneGap plugins repository is the aforementioned VolumeSlider plugin. I am pleased as punch about this as it is my first real contribution to a modern open source project. Hopefully it is just the first of many more such contributions.

Wish me luck. Worst case I can always just stick with Objective-C.