Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (24.65 MB, 900 trang )
1. Make sure that you have fully tested the app on the simulator and you are happy
that your app is stable.
2. Gather the UDIDs (Unique Device Identifiers) of all those devices on which you
want to run your app. You can ask your friends and colleagues for these if the
devices belong to them.
3. Add these UDIDs to your iOS Portal.
4. Create an Ad Hoc Distribution provision profile. Provision profiles are a mix of
binary and XML content that allow an application to be executed on devices that
have been linked to that provision profile.
5. After you have your provision profiles (a file that end with .mobileprovision extension), tell Xcode to use that provision profile for release purposes, as we will soon
see.
6. Within Xcode, select the Product menu and then choose Archive. Xcode will now
archive your application and, when that is done, display Organizer to you. Here
you can export your archived application as a file (with the .ipa extension) that
your testers/colleagues/friends can drag and drop into their iTunes or iPhone Configuration Utility to install your app on their iOS devices.
To distribute your iOS app to testers/colleagues and friends, you have to create an Ad
Hoc provision profile. Follow these steps to create your Ad Hoc provision profile:
1. Log into the iOS Dev Center.
2. Select iOS Provision Portal from the right side of the screen.
3. If you have not created a Distribution certificate yet, follow these steps:
a. On the left hand side of iOS Provision Profile, select Certificates.
b. On the right hand side, select the Distribution tab on the top of the screen.
c. Follow the instructions on the screen, which will ask you to use Keychain
Access to create a new certificate on your computer and then upload that certificate to the portal. After this you will have your Distribution certificate.
d. Click on the Download button to the right side of your Distribution certificate
to download it. After you've downloaded it on your computer, double click
on it to install it in your Keychain Access.
4. Now move to the Devices item on the left hand side of the screen.
5. Select the Add Devices button on the right side of the screen.
6. Enter the device name and the device UDID in the boxes provided. If entering more
than one device, press the + button after every device to make room for a new
device. You can add a maximum of 100 devices to each provision portal (except
for Enterprise portals, which we won't cover in this book, as they are given only to
big organizations).
22 | Chapter 1: The Basics
www.it-ebooks.info
After a device is added to your iOS portal, it cannot be removed for the
period that you hold this portal (which is usually a year). After your
portal has expired or when it has been renewed, you will get a chance
to delete any unwanted devices, so make sure you are not adding devices
to your portal just for fun!
5.
6.
7.
8.
9.
10.
11.
12.
13.
Once you are done adding the devices, press the Submit button.
Select Provisioning on the left side of the screen.
Select the Distribution tab on the right hand side of the screen.
Select the New Profile button on the right side of the screen.
In the Create iOS Distribution Provisioning Profile screen, make sure the Distribution Method is Ad Hoc.
Under Profile Name, give a descriptive name to your provision profile. For instance,
something like Wildcard Ad Hoc Profile. Be creative and descriptive.
In the App ID dropdown, pick Xcode: Wildcard AppID. This will allow you to
provision your apps regardless of their App Identifiers so that you can use the same
Ad Hoc provision profile for all your iOS apps.
In the Devices section, select all the devices on which you want this provision
profile to work. Devices that are not selected in this list will not be able to run your
apps.
After you are done selecting the devices, press the Submit button.
Figure 1-19. Creating a new Ad Hoc provision profile
1.6 Packaging iOS Apps For Distribution | 23
www.it-ebooks.info
14. Now head back to the Distribution tab of the Provisioning section and press the
Download button for the provision profile that you just created. If the status of
this profile is Pending, refresh your page in your browser until the provision profile
is created.
15. Now that you have this provision profile downloaded on your computer, drag and
drop it into iTunes. iTunes will then install this profile for you.
All done; we are now ready to create an archived app. Follow these steps:
1. Select your profile file in Xcode (this is the file with the blue icon).
2. Now you will see the targets your app supports. Select the desired target.
3. Select Build Settings on the right side of the screen (Figure 1-20).
Figure 1-20. Xcode Displaying the Build Settings of an iOS App
4. In the Build Settings tab, scroll down until you get to the Code Signing category,
as shown in Figure 1-20.
5. Under Code Signing Identity→Release and Code Signing Identity→Release→Any
iOS SDK, make sure you pick the provision profile that you created earlier in this
recipe.
6. On the Scheme breadcrumb (Figure 1-11), make sure you've chosen iOS Device/
Your Device Name instead of iOS Simulator (iPad or iPhone). Under the simulator,
you cannot create an app for distribution.
7. Head over to the Product menu and choose Archive.
After the archiving process is finished, Xcode will open Organizer for you and will
display the Archives tab, as depicted in Figure 1-21.
24 | Chapter 1: The Basics
www.it-ebooks.info
Figure 1-21. An archived application in Organizer
8. Select the Share button on the top right side of the screen. You will be presented
with a dialog similar to that shown in Figure 1-22.
1.6 Packaging iOS Apps For Distribution | 25
www.it-ebooks.info
Figure 1-22. Selecting the type of archive we want to create
9. Keep the Contents selection as iOS App Store Package (.ipa file), as shown in
Figure 1-22.
10. In the Identity dropdown, again, choose the provision profile with which you want
to sign your app. We created this provision profile before, remember? Choose the
same profile again. Once you are done, press Next.
11. You will now be asked to specify the location where you would like to save this
file. Select your desired location and filename, then press Save.
All done. Now you have a file with an .ipa extension. When sending this file to your
friends/colleagues/etc., make sure you send the provision profile (which you created
in the iOS Dev Portal) as well. They will need both of these files (the .ipa and
the .mobileprovision files) in order to install your archived apps on their devices.
A user can use either iTunes or iPhone Configuration Utility (both are free) in order to
install your apps on their devices. I personally recommend iPhone Configuration Utility
(or iCU) since it is certainly more robust when it comes to installing Ad Hoc apps on
devices. iTunes has some issues when installing archived apps on devices, which I am
not going to bore you with. The more you work with these two pieces of software, the
more you get to know about their advantages and disadvantages.
26 | Chapter 1: The Basics
www.it-ebooks.info
See Also
XXX
1.7 Declaring Variables in Objective-C
Problem
You want to use variables with clear names in your iOS apps.
Solution
Apple conventions dictate certain rules for variable names. Determine the type of the
variable (for instance, integer, array, string, etc.) and then a descriptive name for it. In
an empty line of code, place the type of your variable first, following by its name.
Variable names are advised to follow these rules:
1. Follow the camelCase naming convention. If the variable name is one word, all
letters must be lower-case. If the variable name is more than one word, the first
word must be entirely lower-case and the subsequent words must have their first
letter upper-case and the rest of their letters lower-case. For instance, if you want
to have a counter variable, you can simply name it counter. If you want to call your
variable "first counter", declare it firstCounter. The variable name "my very long
variable name" would become myVeryLongVariableName. (Names of that length are
quite common in iOS programs.)
2. Variables should ideally have no underline in their names. For instance, my_varia
ble_name can and perhaps should be changed to myVariableName.
3. Variable names should contain only letters and numbers (no punctuations such as
comma and dash). This is a restriction in the Objective-C language.
Let's have a look at a few examples. There are a few primitive data types in ObjectiveC. A data type is a name that specifies the type of a variable. For instance, you can say
that you have an integer variable of type NSInteger or an integer variable of type NSUIn
teger, where the former is a signed variable and the latter is unsigned (note the "U"
after "NS") in the latter example). So we can then define these variables in our source
code like so:
Signed integers can contain negative numbers whereas unsigned integers cannot.
NSInteger signedInteger = -123;
/* Can take negative numbers */
NSUInteger unsignedInteger = 123; /* Cannot take negative numbers */
1.7 Declaring Variables in Objective-C | 27
www.it-ebooks.info
There are certain rules, as mentioned before, about naming your variables (for instance,
the camelCase rule). However, other aspects of your variable naming convention depend entirely on your choice. In general, I advise that you always assume you are
working for a big organization (whether it is your own company or somebody else's
company) and follow these rules:
1. Give descriptive names to your variables. Avoid names such as "i" or "x." These
names will never make any sense to anybody else but yourself and chances are that
they won't make sense to you either if you leave the project for some time and come
back to it after a few months. The compiler doesn't really care if the variable name
is 50 letters long. If that makes your variable name more descriptive and you cannot
do without it, then go for it.
2. Avoid creating vague variable names. For instance, if you have a string variable and
you want to place the full name of a person in that variable, avoid giving it names
such as "theString" or "theGuy" or "theGirl." These make no sense at all. It is best
to give a name such as "fullName" or "firstAndLastName" rather than something
that confuses everybody who looks at your source code, including yourself!
3. Avoid giving names to your variables that are likely to lead to mistyping. For instance, it is much better to call your variable "fullName" rather than
"__full______name." It is much better to avoid underlines in variables all together.
Discussion
Variables are placeholders for data that you want to hold in memory. For instance, if
you want to delete 100 files from the disk and those files are named 1.png, 2.png, on
to 100.png, it would be best to create a counter variale that starts from 1 and goes all
the way to 100 and then use the content of that variable (the number) to delete the files.
Programmers use variables to do arithmetic or simple operations such as prefixing the
last name of a person with their first name to create the resulting full name.
Every variable has to have a type. The type of a variable tells the compiler and the
machine that runs that program, what type of variable that is and what sort of value it
holds. For exmaple, a variable that is an integer can hold the value 123 but cannot hold
a value with decimal places such as 123.456. For the latter, we will need a floating point
variable. Integer and floating point here are the data types and in Objective-C are defined with NSInteger and float. Here are some of the commonly used data types in
Objective-C:
NSInteger
Variables of this type can store signed (positive or negative) integer values.
NSUInteger
Variables of this type can store unsigned (only positive or zero) integer values.
28 | Chapter 1: The Basics
www.it-ebooks.info