This is the inaugural post on this new blog I just started. The goal of this blog is to document little code snippets and fixes for the semi common and not so common problems that aren’t well documented elsewhere.
Recently I’ve been delving into the wonderful world of PhoneGap in order to make my first iPhone App. My current PhoneGap stack is PG + jQTouch + PhoneGap Plugins (which are JS libraries that talk to native libraries, frameworks, etc…). I am using PhoneGap Plugins as much as possible as they make apps feel more native (and less buggy).
I tussled with MapKit for iOS for quite some time, until Shazron at Nitobi gave me some help in #phonegap on FreeNode. The problem I was experiencing was mostly because I was using XCode 4 which does things a little differently.
Add the MapKit Plugin files to your project
/ProjectName/Plugins ( drag these files into the file path in your XCode view)
Add the appropriate HTML + JS that is found in the example/index.html to your PhoneGap HTML page.
Update both the following files in XCode
OLD: #import "PhoneGapCommand.h" NEW: #ifdef PHONEGAP_FRAMEWORK #import <PhoneGap/PhoneGapCommand.h> #else #import "PhoneGapCommand.h" #endif
OLD: #import "SNJsonParser.h" #import "SNJSON.h" NEW: #import <PhoneGap/SBJsonParser.h> #import <PhoneGap/SBJSON.h>
Add the MapKit core framework to your project. Follow the instructions outlined here
- In the project navigator, select your project
- Select your target
- Select the ‘Build Phases’ tab
- Open ‘Link Binaries With Libraries’ expander
- Click the ‘+’ button
- Select your framework
- (optional) Drag and drop the added framework to the ‘Frameworks’ group
Considering all these steps have been performed correctly your app should now display a nice native map layer with a pin dropped on Nitobi’s HQ
As written at the top of this post- it is outdated, both XCode and PhoneGap have changed A LOT in 1.5 years since I wrote this- hopefully this post was helpful in helping you undersand how to use PhoneGap and the MapKit plugin work together