from:https://developer.apple.com/library/prerelease/content/documentation/porting/conceptual/portingunix/ Distributing/distibuting.html#//apple_ref/doc/uid/tp40002855-tpxref101
Distributing Your Application
Developing an application are only part of the story. You must now get the it out there for people to use. Given a unix-based operating system, you could just and tar
gzip
your file. That ' s fine if your end users is mostly UNIX users, but this doesn ' t meet the needs for more general users. To complete the transition, your should package is application like other MAC apps. This chapter walks you through some of those details since they is probably new to you as a UNIX developer.
This chapter are important for all non-command-line developers, whether your application are an end-user commercial suite or An open source tool.
Bundles vs. installers
Most applications in OS X does not need to use an installer. To make installation and removal easy, OS X provides bundles.
A bundle is basically a directory, the contains an application. Unlike normal folders, however, it appears to the user like a ordinary file. The user can double-click a bundle, and the application would launch. Since The bundle is really a directory, it can contain all the support files and is needed for the application.
The reason to use bundles are somewhat obvious if you had installed many applications in OS x:applications in the form of A bundle can be installed simply by dragging the application to the destination folder in the Finder.
There is, however, some situations where bundles is problematic. An application-installs kernel extensions, startup items, System-wide preference panes, or any other system-wide Reso Urces cannot is installed by dragging the application, since those resources need to being in a separate place on the drive.
If your application requires installing a startup item, the only practical-to install your application N Installer. OS X makes this easy using Packagemaker. Other commercial solutions is also available from various third parties such as Stuffit Installermaker from Aladdin syste MS and Installer VISE from Mindvision.
In most cases, however, it's preferable to install System-wide components The first time your application is launched. You can do this using Authorization services, as described in the book Authorization Services ProgrammingGuide, Available from the Apple Technical publications website.
For more information on how to create a bundle, see Bundle ProgrammingGuide.
Packaging Basics
There is both main applications for compressing your application:disk Utility (or Disk Copy in older versions of OS X) an D Packagemaker. Disk Utility allows you-to-create compressed disk images (similar to a ISO file, but compressed), whereas Packagemaker CR Eates packages that can is installed using the OS X installer.
The recommended form of application distribution is a compressed disk image. A Compressed disk image preserves resource forks that could be present, allows Drag-and-drop installation, allows license di Splay, and even allows encryption of data, if required.
If your application is a single application bundle, simply put it and any relevant documentation on a disk image with disk Utility, then compress it and distribute it.
If you had an application, requires administrator privileges to install into privileged directories or requires more than a simple drag-and-drop installation, use Packagemaker ( /Developer/Applications/PackageMaker
) to build installer packages for Apple ' s installer appli cation.
The basics of using disk Utility to make a Disk image is given in the next section. For help using Packagemaker, choose Packagemaker Help from the Packagemaker Help menu.
Disk Utility (or disk Copy)
The following steps help-your application as a disk image ( .dmg
file) for distribution on OS X.
Open by /Applications/Utilities/Disk Utility.app
double-clicking it.
From the Image menu, choose New Blank Image. Disk Utility opens a new window with customization options as in Figure 8-1.
In the "Save as" text box, enter the name of the compressed file, which you'll distribute. By default, a suffix are appended to the name of you .dmg
enter. Although it is not required, it's a good idea to retain this suffix for clarity and simplicity.
In the Volume Name text field, enter the name of the Volume so you want to appear in the Finder of a user ' s computer. Usually this name is the same as the name of the compressed file without the .dmg
suffix.
In the file browser, set the location to save the file on your computer. This have nothing to does with the installation location on the end user's computer, only where it saves it on your computer.
Set The size pop-up menu to a size, that's large enough to hold your application.
Leave the format set to Mac OS Extended (the hfs+ file format).
Leave encryption set to none. If you change it, the end user must enter a password before the image can be mounted, which are not the normal-to Distr Ibute an application.
Click Create.
Figure 8-1 Disk Utility Options
Once you has a disk image, mount it by double-clicking it. You can now copy your files to that mounted image. When you are everything on the "image", you want and should make your image read-only. Again from Disk Utility, perform these steps:
Unmount the disk image by dragging the volume to the Trash, clicking the eject button next to the device in a Finder Windo W, or selecting the mounted volume and choosing Eject from the Finder ' s File menu.
Choose Convert Image from the Image menu.
In the file browser, select the disk image you just modified and click Convert.
Choose a location to save the resulting file with the change of the image format to Read-only, and click Convert.
You are now having a disk image for your application, that's easy to distribute.
Creating Disk Images Programmatically Using Hdiutil
If you find yourself regularly creating disk images, your may find it helpful to automate this process. While a complete script was beyond the scope of this document, this section includes a code snippet to get you started.
For more information on Hdiutil, see hdiutil
.
Listing 8-1 Automatic Disk Image Creation usinghdiutil
# Create An initial disk image (Megs) |
Hdiutil create-size 32m-fs hfs+-volname "My Volume" myimg.dmg |
|
# Mount The disk image |
Hdiutil Attach MYIMG.DMG |
|
# Obtain device information |
devs=$ (Hdiutil attach myimg.dmg | cut-f 1) |
dev=$ (echo $DEVS | cut-f 1-d ") |
|
# unmount the disk image |
Hdiutil Detach $DEV |
|
# Convert The disk image to Read-only |
Hdiutil Convert Myimg.dmg-format udzo-o myoutputimg.dmg |
Distributing Your application for OS X