Beginning with PhoneGap 1.4, you can use PhoneGap as a component in your iOS applications. This component is code-named "Cleaver".
New PhoneGap-based applications created using the Xcode template provided in PhoneGap 1.4 or greater uses Cleaver, and this template is considered the reference implementation for Cleaver.
It is recommended that you follow the PhoneGap.framework instructions below, the PhoneGapLib sub-project instructions are for PhoneGap core developers or users that have custom PhoneGapLib project code (for ease of debugging the core).
- PhoneGap 1.4 or greater installed
- Xcode 4.2 or greater installed
- PhoneGap.plist file
-
Copy the "PhoneGap.plist" file into your project folder on disk
-
Drag and drop the "PhoneGap.plist" file into the Project Navigator of Xcode
-
Choose the radio-button "Create groups for any added folders"
-
Press the key combination Option-Command-A, which should drop down a sheet to add files to your project (the "Add Files..." sheet). Make sure the "Created groups for any added folders" radio-button is selected
-
Press the key combination Shift-Command-G, which should drop down another sheet for you to go to a folder (the "Go to the folder:" sheet)
-
Enter "/Users/Shared/PhoneGap/Frameworks/PhoneGap.framework" in the "Go to the folder:" sheet and then press the "Go" button
-
Press the "Add" button in the "Add Files..." sheet
-
Select "PhoneGap.framework" in the Project Navigator
-
Press the key combination Option-Command-1 to show the File Inspector
-
Choose "Absolute Path" in the File Inspector for the drop-down menu for Location
-
Click on the project icon in the Project Navigator, select your Target, then select the "Build Phase" tab
-
Expand "Link Binaries with Libraries"
-
Click on the "+" button, and add these frameworks (and optionally in the Project Navigator, move them under the Frameworks group):
AddressBook.framework AddressBookUI.framework AudioToolbox.framework AVFoundation.framework CoreLocation.framework MediaPlayer.framework QuartzCore.framework SystemConfiguration.framework MobileCoreServices.framework CoreMedia.framework
-
Copy the "PhoneGap.plist" file into your project folder on disk
-
Drag and drop the "PhoneGap.plist" file into the Project Navigator of Xcode
-
Choose the radio-button "Create groups for any added folders"
-
Press the key combination Option-Command-A, which should drop down a sheet to add files to your project (the "Add Files..." sheet). Make sure the "Created groups for any added folders" radio-button is selected
-
Press the key combination Shift-Command-G, which should drop down another sheet for you to go to a folder (the "Go to the folder:" sheet)
-
Enter "~/Documents/PhoneGapLib/PhoneGapLib.xcodeproj" in the "Go to the folder:" sheet and then press the "Go" button
-
Press the "Add" button in the "Add Files..." sheet
-
Select "PhoneGapLib.xcodeproj" in the Project Navigator
-
Press the key combination Option-Command-1 to show the File Inspector
-
Choose "Relative to PHONEGAPLIB" in the File Inspector for the drop-down menu for Location
-
Click on the project icon in the Project Navigator, select your Project, then select the "Build Settings" tab
-
Enter "Header Search Paths" in the search field
-
Enter "$(PHONEGAPLIB)/Classes" and check the Recursive checkbox - for the "Header Search Paths" value
-
Click on the project icon in the Project Navigator, select your Target, then select the "Build Phases" tab
-
Expand "Link Binaries with Libraries"
-
Click on the "+" button, and add these frameworks (and optionally in the Project Navigator, move them under the Frameworks group):
AddressBook.framework AddressBookUI.framework AudioToolbox.framework AVFoundation.framework CoreLocation.framework MediaPlayer.framework QuartzCore.framework SystemConfiguration.framework MobileCoreServices.framework CoreMedia.framework
-
Expand "Target Dependencies"
-
Click on the "+" button, and add the "PhoneGapLib" build product
-
Expand "Link Binaries with Libraries"
-
Click on the "+" button, and add libPhoneGap.a
-
Add this header if you used the PhoneGap.framework:
#import <PhoneGap/PGViewController.h>
-
Add this header if you used the PhoneGapLib sub-project:
#import "PGViewController.h"
-
Instantiate a new PGViewController, and retain it somewhere:
PGViewController* viewController = [PGViewController new];
-
(OPTIONAL) Set the wwwFolderName property (defaults to "www"):
viewController.wwwFolderName = @"myfolder";
-
(OPTIONAL) Set the startPage property (defaults to "index.html"):
viewController.startPage = @"mystartpage.html";
-
(OPTIONAL) Set the useSplashScreen property (defaults to NO):
viewController.useSplashScreen = YES;
-
Set the view frame (always set this as the last property):
viewController.view.frame = CGRectMake(0, 0, 320, 480);
-
Add Cleaver to your view:
[myView addSubview:viewController.view];
-
Create a new folder in your project on disk, for example, name it "www"
-
Put your HTML, CSS and JavaScript assets into this folder
-
Drag and drop the folder into the Project Navigator of Xcode
-
Choose the radio-button "Create folder references for any added folders"
-
Set the appropriate "wwwFolderName" and "startPage" properties for the folder you created in (1) or use the defaults (see previous section) when you instantiate the PGViewController.
/* if you created a folder called 'myfolder' and you want the file 'mypage.html' in it to be the startPage */ viewController.wwwFolderName = @"myfolder"; viewController.startPage = @"mypage.html"
This file controls various settings of PhoneGap. This is application wide, and not set per PGViewController instance.
- A list of Plugins allowed to be used in a PGViewController (set in the Plugins dictionary - key is the servicename used in JavaScript, and the value is the Objective-C class for the plugin that is a PGPlugin sub-class)
- A white-list of hosts (with no scheme) that PhoneGap is allowed to connect to (set in the ExternalHosts array - wildcards allowed)
- Various other settings (TODO:)