Getting Started with iOS Development in 60 Minutes

Table of Contents

This article is intended for iOS development beginners who already have programming experience in other languages ​​(such as Java, C, PHP, Javascript). The original intention is to let my colleagues understand how to start developing iOS Apps within one hour. The learning goals include:

  • Able to use Xcode IDE and simulator
  • Ability to modify and debug existing iOS Apps
  • Ability to create new modules within existing applications
  • Ability to create new applications
  • Ability to publish apps to the App Store

This article does not contain any advanced iOS development knowledge. Students who have already learned iOS development should not read it, and students who have learned it after reading this article do not need to read it anymore.

More than just learning a new language

People who have experience in script development (such as Javascript, PHP, Shell) will feel that the learning curve of iOS development is higher than that of scripting languages ​​when they first start learning iOS development. Yes, this feeling is correct. Because learning iOS development is not just about learning a new language, it includes:

  • One language: Objective-C
  • A framework: Cocoa Touch
  • An IDE: Xcode

Beginners usually don’t use scripting languages ​​to draw graphical interfaces and interact with people. If iOS didn’t make graphical interfaces and process text and operate databases like scripting languages, it would be meaningless.

Therefore, in the past, when I wrote other introductory tutorials for novices, I usually wrote "15-minute tutorial for getting started with XXX", but for iOS, it would take several times the time to write it.

Environmental preparation

To do iOS development, you must have Apple's software environment: Mac OS operating system, Objective-C compiler, device simulator, etc. The development tool does not necessarily need to use Xcode, as long as it is a source code editing tool (vim will do, but it does not have as many functions as Xcode).

Mac OS

The easiest way to have a Mac OS environment is to find an Apple computer, including iMac, MacBook Pro, MacBook Air, Mac Mini, but excluding Apple's mobile devices (iPod Touch, iPhone, iPad, iPad Mini, which run iOS systems, not Mac OS). Apple computers come with Mac OS pre-installed when they leave the factory. The latest version is Mac OS X 10.8, and the mainstream versions include Mac OS X 10.6 and Max OS X 10.7.

If you are short on money, you can borrow one or buy a second-hand one on Taobao.

black apple

When it comes to getting started with iOS development, it seems impossible not to mention Black Apple. The so-called black apple is to modify Mac OS and install it on non-Apple hardware. This is a violation of the DMCA Act. For more information about black apple,Can be found on the wiki

The price of Apple computers is high, and domestic software developers are under great pressure to survive. Therefore, there are some real black apples in China, and of course there are also some in foreign countries.

Black Apple is basically capable of iOS development, but there are some problems:

  • Installing black apples is illegal
  • Apple will generally not pursue personal behavior, but it will be looked down upon by peers.
  • Black Apple is super difficult to install, so you have to choose the hardware. Even if it is the exact same model and the same batch, it is possible that machine A can be installed but machine B cannot.
  • Black Apple systems have some usage problems, such as driver bugs, blue screens when recovering from standby, and problems with Internet browsing.
  • Black Apple cannot be upgraded at will. Upgrading Safari once may cause the entire system to crash.

Although the above will not directly affect Xcode writing and simulator testing, when I write that I want to check something online, Safari cannot turn pages, which does affect my mood. Therefore, if your wallet allows it, it would be easier to get an Apple computer.

Xcode and Simulator

Xcode can be downloaded for free from Apple’s official website:Xcode download address

The iOS SDK and simulator are automatically installed when you install Xcode.

It's quite nice that such a powerful IDE is free.

Start by modifying an existing application

When learning a new software development skill, it is very important to be able to make a working product as soon as possible, which helps to give yourself positive motivation. When I was in college, I wanted to learn a new language many times, but it often took half a month, and I was immersed in data types and syntax dictionaries. I didn't even make the first Hello World.

This time, let's start by modifying a ready-made application.

download

First, we download a sample code from the Apple Developer Center. I choseToolBarSearch

At the end of this document, there are some other URLs where you can download open source iOS products or code snippets, but after I tried it, Apple Sample Code was the easiest to succeed.

It is best to save the downloaded zip file in the "Downloads" or "Documents" directory, because before Mac OS 10.8, some directories (such as /var/private/tmp) were not visible in Finder and could only be accessed through Finder's "Go > Go to Folder" function.

Open

There are three ways to open an iOS Project

Double-click the project file

Open Finder, enter the ToolBarSearch directory you just downloaded and decompressed, find the ToolBarSearch.Xcodeproj file, double-click it, Xcode will automatically start and open the project

Select Project to open in Xcode

  • When Xcode has not started (if Xcode has already started, press Command Q to exit first), start Xcode, and the "Welcome to Xcode" welcome page will pop up. Click the "Open Other" button in the lower left corner, find the ToolBarSearch directory, double-click the ToolBarSearch directory, or double-click the ToolBarSearch.Xcodeproj file.
  • If Xcode is open, you can click File -> Open in its menu bar, or File -> Open Recent, and then select the project you want to open.

Open via command line

Before Mac OS 10.8, some directories (such as /var/private/tmp) could not be found by clicking the mouse in the File > Open dialog box of Finder and Xcode. At this time, they had to be opened through the command line terminal.

Open a terminal and execute:

cd /ToolBarSearch's parent directory/ToolBarSearch open -a Xcode  

open -a is a system command of mac os. In addition to iOS projects, other projects can also be opened in this way.

Run the app you just downloaded

Click the Run button in the upper left corner of Xcode (or press the Command and R keys at the same time), and Xcode will compile the source code and run the application in the simulator.

If the compilation is successful, "Build Succeeded" will be displayed lightly on the screen. Otherwise, if it fails, "Build Failed" will be displayed and the simulator will not be started.

Revise

You see "Performed search using..." on the simulator, let's change it below.

  • Below the Run button in the upper left corner of Xcode, there is a row of small buttons. The third one from left to right is a magnifying glass icon. Move the mouse up and it will display "Show the Search Navigator". Click it to open the search interface and enter "performed" in the Find input box that appears below it.
  • There is only one search result: ToolbarSearchViewController.m. Click on the highlighted "Performed" string below the file name. The code editing area on the right will automatically open the file and scroll the screen so that the line containing "Performed" appears in the middle of the editing area.
  • Modify the string in double quotes to whatever you want, and then press "Command S" to save.

Of course, you can also complete these operations through grep and vim in the terminal.

Run the modified application

Press Command R to run and see if you see the effect?

Yes, modifying an app is that easy.

Objective-C

Objective-C is the development language for Apple application software (including Mac OS App on Apple computers and iOS App on mobile devices). It is an object-oriented programming language.

Apple also provides a software called Interface Builder, or IB for short, which is used for visual interface production, just like using Dreamweaver to make web pages, or Visual Basic to make desktop software. Later, IB was integrated into Xcode and became part of Xcode. This document does not talk about IB, only Objective-C, because:

  • Basically, every book on iOS development (paper book, e-book) has a large number of screenshots to teach step-by-step how to develop iOS applications with IB, but there are not so many books on developing applications with Objective-C.
  • IB can be used to draw interfaces intuitively and conveniently, set control properties, and establish connections between code and controls. However, the backend business logic and data processing still rely on Objective-C. It can be seen that whether IB is used or not, Objective-C cannot be bypassed.

superset of C

Objective-C extends ANSI C and is a superset of C, that is to say:

  • Any C source program can be successfully compiled by the Objective-C compiler without modification.
  • Any C language code can be used directly in Objective-C source programs

Except for the object-oriented syntax that is SmallTalk style (discussed below), other non-object-oriented syntax and data types are exactly the same as C, so this article will not go into details. Let’s take a look at a classic Hello World example:

#import  int main(int argc, char *argv[]){ @autoreleasepool{ NSLog(@'Hello World!'); } return 0; } 

Doesn’t it seem like you’ve traveled back to the time when you were a freshman learning C language? It looks almost the same as C, right? Yes, because I haven’t used its object-oriented features yet, haha!

SmallTalk messaging syntax style

Objective-C's object-oriented syntax is derived from SmallTalk, message passing (Message Passing) style. In terms of source code style, this is the biggest difference from C Family languages ​​(including C/C++, Java, and PHP).

In the Java and C++ world, we call a certain method of an object. In Objective-C, this is called sending a message to the type. This is not just a word play, their technical details are also different.

In Java, the relationship between objects and methods is very strict. A method must belong to a class/object, otherwise compilation will report an error. In Objective-C, the relationship between types and messages is relatively loose. Message processing is not dynamically determined until runtime. Sending a message to a type that it cannot handle will only throw an exception and not hang.

[obj undefinedMethod];  

If you call an undefined method in the code (this is a common saying in the Java world, the professional term is to pass a message that it cannot handle to the obj object), Xcode will warn you, but the compilation will be successful, but an error will occur when running. It will output an error like this:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSObject undefinedMethod]: unrecognized selector sent to instance 0x8871710'  

Java-like OOP concepts

Some object-oriented concepts in Objective-C can also be implemented in Java (it can only be said to be similar, not exactly the same). My readers are basically Java and PHP programmers. I will try to use Java concepts for analogies below.

Someone on GoogleCode compiled the concepts and data type correspondence tables of Java and Objective-C.See here

string

In Objective-C, strings are wrapped in double quotes, and an @ symbol is added before the quotes, for example:

title = @'Hello'; if(title == @'hello') {}  

PHP programmers should note that single quotes cannot be used here, even if there is only one character. Objective-C, like Java and C, uses double quotes to represent strings.

function call

As mentioned earlier, it is exactly the same as C when object-oriented is not involved. Here are a few examples of function calls:

without parameters

startedBlock();  

With parameters

NSLog(@'decrypted string: %@', str); CGRectMake(0,0,0,0);  

Pass messages to class/instance methods

without parameters

[obj method];  

Corresponding Java version

obj.method();  

Take one parameter:

[counter increase:1];  

Corresponding Java version

counter.increase(1);  

with multiple parameters

For C Family programmers, this is the hardest to accept and the most anti-human:

- (void) setColorToRed: (float)red Green: (float)green Blue:(float)blue {...} //Define method [myObj setColorToRed: 1.0 Green: 0.8 Blue: 0.2]; //Call method  

Corresponding Java version

public void setColorToRedGreenBlue(float red, float green, float blue) {...} myObj.setColorToRedGreenBlue(1.0, 0.8, 0.2);  

Message nesting

UINavigationBar *bar = [[[UINavigationBar alloc] init] autorelease];  

Corresponding Java version

UINavigationBar bar = UINavigationBar.alloc().init().autorelease();//Java has no pointers, so the asterisk is removed  

Interface and implementation

Objective-C classes are divided into two parts: interface definition and implementation. The interface definition (Interface) is placed in the header file, and the file extension is .h. The implementation (implementation) is placed in the implementation file, and the file extension is .m (there is also an extension of .mm, indicating mixed code of Objective-C and C++).

The interface definition can also be written in a .m file, but it is best not to do this

It should be noted that the interface concept closest to Objective-C is the header file in C and C++, which appears in pairs with implementation and is used to declare member variables and methods of the class. It is completely different from Java's interface concept:

  • In Objective-C, interface has one and only one implementation, while Java's interface can have 0-N implementations.
  • In Objective-C, interface can define member properties, but not in Java.

In Objective-C, the concept similar to Java's Interface is Protocol, which will be discussed below.

See example:

Interface

@interface MyClass { int memberVar1; id memberVar2; } -(return_type) instance_method1; -(return_type) instance_method2: (int) p1; -(return_type) instance_method3: (int) p1 andPar: (int) p2; @end  

Implementation

@implementation MyClass { int memberVar3; } -(return_type) instance_method1 { .... } -(return_type) instance_method2: (int) p1 { .... } -(return_type) instance_method3: (int) p1 andPar: (int) p2 { .... } @end  

Interfaces and implementations start with @interface and @implementation and end with @end. The "@" symbol is a magical symbol in Objective-C.

The colon is also part of the method name. method and method: are two different method names, not overload. The second one takes parameters.

The Java version corresponding to the above code:

public class MyClass { protected int memberVar1; protected pointer memberVar2; private int memberVar3; public (return_type) instance_method1() { .... } public (return_type) instance_method2(int p1) { .... } public (return_type) instance_method3andPar(int p1, int p2) { .... } }  

private methods and public methods

The methods written in the .h header file are all public. There is no concept of private methods in Objective-C.

The official did not mention how to implement private methods in Objective-C. I checked stackoverflow, and the unified answer is that the effect of private methods can only be achieved with the help of Category. However, according to my tests, even if Category is used, it cannot prevent external code from calling this "private method". However, Xcode does not support the automatic completion of "private methods", and there will be a warning prompt. When running, it will still be successful. As long as you readers know that this is the case, I won’t go into details here.

Variables and properties

Class methods and instance methods

class method

Class methods are Static Methods in Java and PHP, which can be adjusted without instantiation. Class methods are prefixed with a plus sign. Example:

class definition

@interface MyClass +(void) sayHello; @end @implementation MyClass +(void) sayHello { NSLog(@'Hello, World'); } @end  

use

[MyClass sayHello];  
instance method

Instance methods are ordinary methods in Java and PHP, which must be instantiated before they can be called. Instance methods are prefixed with a minus sign. Example:

class definition

@interface MyClass : NSObject -(void) sayHello; @end @implementation MyClass -(void) sayHello { NSLog(@'Hello, World'); } @end  

use

mycls = [MyClass new]; [mycls sayHello];  

Selector

The selector is a method pointer, similar to the dynamic method name in PHP:

$fun_name(); } }  

In Objective-C, selector is mainly used to do two types of things:

Action triggered by bound control
@implementation DemoViewController - (void)downButtonPressed:(id)sender {//Method to respond to "button pressed event" UIButton *button = (UIButton*)sender; [button setSelected:YES]; } - (void)drawAnButton { UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; btn.frame = _frame; btn.tag = 1; btn.backgroundColor = [UIColor clearColor]; //When this button is pressed, trigger the downButtonPressed: method } @end  
Delayed asynchronous execution
@implementation ETHotDealViewController - (void)viewDidLoad { //Get the data source HotDealDataSource *ds = [[HotDealDataSource alloc]init]; [ds reload]; _items = ds.items; [self performSelector: @selector(refreshTable) withObject: self afterDelay: 0.5]; //Delay 0.5 seconds to call the refreshTable method } -(void)refreshTable { [self.tableView reloadData]; } @end  

In this example, the data source is obtained by asynchronously calling the server HTTP interface through the ASIHTTP component. The refreshTable uses the data returned by the data source. If it is not delayed by 0.5 seconds, it will be executed immediately. During execution, the data is still on the way, and the page will become blank.

inherit

Inheritance is written in the Interface definition. The syntax is: the subclass name is on the left, the parent class name is on the right, separated by colons in the middle. Example:

@interface MyClass : NSObject @end  

The corresponding Java version is:

public class MyClass extends NSObject { }  

Protocol

It is the Interface in Java and PHP.

Definition of agreement

The protocol is defined using the @protocol keyword:

@protocol Printable -(void)print:(NSString)str; @end   

The corresponding Java version is:

public interface Printable { public void print(String str); }  
Protocol inheritance

The protocol itself can also inherit other protocols:

@protocol Printable  -(void)print:(NSString)str; @end 

Corresponding Java version:

public interface Printable extends NSObject { public void print (String str); }  
optional methods

Protocols can contain optional methods, which, as the name implies, may not be implemented by the class:

@protocol Printable @optional -(void)print:(NSString)str; @end  

With the addition of the @optional keyword, a class does not need to implement the print: method when it implements this protocol.

There is no similar implementation in Java, except that there are some methods in Collection with optional annotations, but Collection is a special case.

Implementation of the protocol

A class's implementation of certain protocols is written in the Interface definition. The syntax is: the protocol name is wrapped in angle brackets, multiple protocol names are separated by commas, and the protocol is written on the right side of the parent class (if there is no parent class, it is written directly on the right side of the subclass).

Example:

@interface class MyClass : NSObject  @end 

Printable and Drawablw are two protocols.

The corresponding Java version is:

public class MyClass extends NSObject implements Printable, Drawable { }  

Category

Classification can add methods to an existing class without changing its source code. There is no similar feature in Java or PHP.

For example, NSObject is a built-in system class in Objective-C, and we want to add a toJson method to it, like this:

Header file: NSObject+Json.h

@interface NSObject (Json) -(NSString)toJson; @end  

Implementation file: NSObject+Json.m

@implementation NSObject (Json) -(NSString)toJson { //... } @end  

When using it, as long as you include NSObject+Json.h and instantiate the NSObject class, you can use the toJson method:

import 'NSObject+Json.h' @implatementation XYZController -(void)test { NSObject *obj = [[NSObject alloc]init]; NSString *str = [obj toJson]; } @end  

Of course, the original methods of NSObject are still available. Nothing has changed, except for the addition of the toJson method. Doesn’t it seem to be much different from inheritance (except that NSObject is instantiated instead of JsonObject when used)? Let’s look at another example where inheritance cannot be implemented:

Header file: NSObject+Json+XML.h

@interface NSObject (Json) -(NSString)toJson; @end @interface NSObject (XML) -(NSString)toXML; @end  

Implementation file: NSObject+Json+XML.m

@implementation NSObject (Json) -(NSString)toJson { //... } @end @implementation NSObject (XML) -(NSString)toXML { //... } @end  

use:

import 'NSObject+Json+XML.h' @implatementation XYZController -(void)test { NSObject *obj = [[NSObject alloc]init]; NSString *json = [obj toJson]; NSString *xml = [obj toXML]; } @end  

Cocoa Touch

Cocoa is the development framework for Mac OS App, and Cocoa Touch is the framework for iOS development. Cocoa Touch and Cocoa are mostly the same, except that Cocoa Touch has some additional things unique to mobile devices, such as touch screens, acceleration sensors, and GPS positioning. The multi-tasking and multi-window features in Cocoa are not available in Cocoa Touch (or are not exactly the same as Cocoa).

Just like after learning the Java language, you need to learn some Spring, Hibernate, Struts (or other similar Java libraries) before you can start making J2EE applications. After learning the Objective-C language, you also need to learn the Cocoa Touch framework to successfully develop iOS applications.

Delegate, the most commonly used design pattern

Cocoa Touch makes extensive use of the Delegate design pattern.

Common controls: buttons, text blocks, pictures, input boxes

TableView

WebView

Navigation bar

Xcode

run

Shortcut key:Comman R

search

Search text

Search files

Create new file/directory

It is recommended to create a new one in Finder and then add it.

breakpoint

Simulator and real machine testing

Simulator test

Open your project in Xcode. To the right of the Stop button (the black square button to the right of the Run button) on the top toolbar of Xcode, there is a drop-down menu that displays "ToolBarSearch > iPhone 5.0 Simulator" (that is, the English name of your application > currently selected debugging). Click this drop-down menu and select iPhone 5.0 Simulator (5.0 here refers to the iOS version, not iPhone5. If your project is an iPad application, please select iPad 5.0 Simulator), and then press the "Run" button, Xcode will automatically compile and install the application currently being edited and developed into the simulator.

When operating on the simulator, if the breakpoint you set in Xcode is encountered during execution, the simulator will pause and switch the current active window back to Xcode for you to debug.

Adding or canceling breakpoints in Xcode will take effect without recompiling and installing the application.

Switch emulated devices

In the "Hardware" menu of the simulator, you can choose what device you want to simulate, including iPad and iPhone.

  • Retina: stands for retina screen, iPhone (Retina) stands for iPhone4, iPhone4S
  • 4-Inch: means 4-inch iPhone, iPhone (Retina 4-Inch) is iPhone 5

Switch simulated iOS version

In the "Version" menu of the simulator, you can choose which version of iOS you want to simulate. Devices and versions are independent of each other. iPhone 4S can have iOS versions 5.0, 5.1, and 6.1. Of course, iPhone 5 cannot have iOS version 4.3.

touchscreen

Clicking with the mouse (without distinguishing between left and right buttons) on the iPhone or iPad screen on the simulator is simulating touching the iPhone or iPad screen with your fingers, which can achieve some touch effects such as:

  • Mouse click equals finger tap
  • A long press of the mouse is equal to a long press of the finger (for example, you can long press the application icon on the simulator to bring up the confirmation box for deleting the application)
  • Mouse hold down dragging equals finger dragging
  • Double-clicking and clicking the Home button on the emulator is also equivalent to double-clicking and clicking the Home button on the real device.
multi-finger gesture

Multi-finger gestures are more complicated. Simple two-finger gestures can be simulated on the White Apple notebook. The White Apple touchpad naturally supports multi-finger touch, but to locate the simulator area and respond to the multi-finger gesture, you need to use some additional keys:

  • Hold down the Option key and use two fingers to operate the touchpad to simulate two-finger dragging and rotation.
  • Hold down Option+Shift to simulate two-finger pinching

Input method and keyboard

Enter Chinese

Unique input methods on mobile phones (such as Jiugongge input method) cannot be simulated. The default iOS soft keyboard of the simulator only has English input. When testing the application, we need to use Chinese. There are two ways:

  • Use the clipboard to copy in Mac OS, then press and hold the mouse on the input box of the application running in the simulator (simulating a long press with a finger) for more than 3 seconds, and then select it when "Paste" pops up.
  • In the simulator, press the Home button, find the Setting App icon (not the simulator menu at the top of Mac OS, there is no Setting there), open the settings of the simulated iOS device, click "General - Keyboard - International Keyboards - Add New Keyboard...", add a Chinese keyboard, and then you can use the simulated iOS device software disk to enter Chinese, just like on the real iPhone/iPad.

Using a Mac computer keyboard

If you need to enter a large amount of text, using the soft keyboard in the simulator is too inefficient. You can use a physical keyboard at this time. The method is: on the simulator menu bar at the top of Mac OS, click the "Hardware" menu and check "Simulate Hardware Keyboard" in the drop-down menu. When you use the simulator to run an iOS application in the future, click the input box in the iOS application and the soft keyboard will not pop up. You can directly use the physical keyboard of the Mac computer for input.

Notice

  • The iOS in the simulator takes over the physical keyboard input, so the input method of the simulator iOS is called, not the input method of your Mac computer. For example, if Sogou Wubi is installed on your Mac OS, and a Pinyin input method (Add New Keyboard) is added to iOS in the simulator, then inputting Chinese in the iOS application will call the Pinyin input method.
  • To switch between the Chinese and English input methods of iOS in the simulator, you can only press the small globe icon on the soft keyboard of the iOS device. Pressing Command+Spacebar on a Mac computer will not work.

geographical location

However, Mac computers do not have the hardware (GPS) and software foundation for positioning, so the simulator cannot automatically obtain the current geographical location and cannot use the simulator to test the positioning function. (Note that although WiFi can also be positioned independently - the iPad WiFi version can be positioned without GPS, but the WiFi of Mac computers does not have positioning-related software)

To test functions that rely on geographical location (such as "xx near me") in the simulator, you can manually specify a longitude and latitude to the simulator. Method: In the simulator menu at the top of the Mac computer, click "Debug - Location - Custom Location", a dialog box will pop up, just fill in the latitude and longitude in the pop-up box.

How to get latitude and longitude? Go to Google Maps (ditu.google.cn), find the location you want on the map (for example, if you want to know the location of Hangzhou Tower, just find Hangzhou Tower through the search box), right-click and select "What is here", the longitude and latitude of this location will appear in the search box, with latitude in front and longitude behind. The territory of our celestial dynasty is all about northern latitude and east longitude.

Camera

Mac computers have cameras, but Mac OS has no API designed to be called by the iOS simulator. Therefore, you cannot use the simulator to test functions such as focus flash.

To test functions that rely on photos on the simulator, you can make a workaround in the code. That is, when the code detects that the camera is unavailable, a photo selector pops up and allows the tester to select a photo from the album for subsequent operations (such as photo beautification, face recognition, and barcode scanning).

Real machine test

The simulator can verify most functions of the iOS application you develop, but the simulator cannot simulate some hardware that is not available on the Mac device. The previous article mentioned a way to bypass these restrictions, but obtaining the current location, taking pictures, and accelerometer cannot be simulated. Before an application is released to consumers, it must be verified on a real device.

There are three ways to install an application that has not been submitted for App Store review to an iOS device for testing:

  • Join Apple's Developer Program and become a paid member. With this paid membership, you can directly click "Run" in Xcode to compile, package and install the code you just changed on the iOS device used for development and testing. Operating the tested program on a real iOS device can activate the breakpoints set in Xcode.
  • Jailbreak iOS devices. After jailbreaking the iPhone and iPad, you can directly upload the Xcode-compiled ipa package through SSH (an iOS App is essentially an ipa package).
  • Jailbroken iOS devices, combined with cracked Xcode, can even achieve the same function as the paid developer plan: click "Run" on Xcode, and it will automatically compile, install and run on the iOS device.
  • Enterprise deployment plan. Just like Alibaba’sXuanyuan SwordSimilarly, visit this website with iPhone/iPad and click the Xuanyuan Sword link inside to install the Xuanyuan Sword application.

It is illegal to crack Xcode (jailbreaking is legal), and it is very difficult to choose the version. Not all Xcode versions can be cracked, and not all cracked versions of Xcode can work well with jailbroken iOS. Jailbreak + SSH upload is as inefficient as enterprise deployment (deployment efficiency is low and breakpoints in Xcode cannot be activated). It can only be used for QA acceptance and is not suitable for development and self-testing. To sum up, the most suitable way to develop real-time tests is the first formal way. Let’s focus on this:

Have a developer account

Apple's Developer Program is divided into individual developers and corporate developers, which cost US per year and US9 per year respectively. They can register 100 and 500 Apple test devices respectively. This limit on the number of devices will not be cleared within a payment year. For example, if the payment is successful on April 1, 2013, the paid membership will be valid until March 31, 2014. During this period, registering one device will result in one less quota. Even if the device is deleted immediately after being registered and used, the reduced quota will not be returned.

Before paying, it is best to ask if any of your colleagues around you have already paid. If so, you only need to register a free Apple ID (the Apple ID you use to install software in the App Store), ask him to send you an invitation email, and add your Apple ID to his team. Apple will think that the two of you are on the same team. You use your own account and share the limit of 100 devices. This is legal.

Install certificate and private key

Certificate

If you don’t want to see the various clicks below to jump to various pages, you can directly access it with a browser.Certificate management, if you want to log in, just log in with your Apple ID (provided you have paid money, or found someone who paid money to add you to the team).

Don’t you find it annoying, or would you like to know how to enter certificate management next time you don’t have this document like mine? Follow these steps:

There is a "Your Certificate" area on the page, and there is a Download rounded button below. This is your personal certificate, download it. On the next line, there is the sentence "If you do not have the WWDR intermediate certificate installed, click here to download now", this is Apple's public certificate, also downloaded.

Double-click the downloaded certificate. When installing the certificate, you will be prompted to enter your password. This is the [Keychain Access Tool] asking you for your Mac OS account startup password (equivalent to sudo in Linux), not your Apple ID password. Don't make a mistake.

Install private key

If you share an account with another colleague, just ask him to give you a private key, which is a file with a p12 extension. Double-click it, and the keychain access will automatically come out, requiring you to enter a password. This password is asked by the person who gave you the p12 file. It is not your Mac OS system startup password, nor is it your Apple ID password.

Register the device to the Provisioning Portal

  • Open Xcode, find Organizer from Xcode's Window menu, and open it (Shift Command 2).
  • Connect your iOS device to your computer and Organizer will automatically recognize your device and display it in the left sidebar.
  • Find your device in the left sidebar of Organizer, right-click, click "Add Device to Provisioning Portal", and then wait for Organizer to prompt you that the operation is successful. (After selecting the device, a button "Use for Development" will be displayed in the device details area on the right, you can also click it).

Run the beta program on a real iOS device

Return to the Xcode main interface. To the right of the Stop button (the black square button to the right of the Run button), there is a drop-down menu that displays "ToolBarSearch > iPhone 5.0 Simulator" (that is, the English name of your application > currently selected debugging). Click this drop-down menu, select your real device name, and then press the "Run" button. Xcode will automatically compile and install the application currently being edited and developed to the real device for testing!

Publish to App Store

Pack an IPA

The IPA package is essentially a ZIP compressed package, but it has a special directory structure and the extension is ipa. The production method is as follows:

  • Build project in Xcode, shortcut key Command B
  • In the project navigator on the left, expand the Products folder, find the application you want to package, your application name.app, right-click and select show in finder
  • Go to Finder and copy the .app directory (select it, press Command C), and copy it to a new folder named Payload (case-sensitive)
  • Find your application logo, which is a 512 * 512 pixel PNG file, copy it together with the Payload (side by side with the Payload, do not put it in the Payload), and rename it to iTunesArtwork (case-sensitive, no extension)
  • Make the Payload directory and ItunesArtwork file into a zip package, and change the extension to ipa
  • Double-click the ipa file and it will be opened with iTunes. If the opening is successful and the application logo is displayed in iTunes, it is successful.

Automatic batch packaging

In addition to the App Store, there are many other iOS application markets (such as 91 Assistant, synchronous push, etc.). If an application needs to be published to many application markets, and their codes are slightly different (for example, the statistics code is different), it is more error-prone to manually modify the source code according to the above method, package it, and then restore it. The good news is that Xcode has a command line. We can write a shell script, first use se to automatically modify the source code, then call the Xcode command line to compile to get your-app.app directory, and finally call zip, mv and other commands to automatically execute the ipa packaging action mentioned in the previous chapter.

Read application code

Create a new application from scratch: Hello World

other

Control size in code

The control size and font size in the iOS App refer to Points. The number of Points for Retina devices (iPhone 4, 4S, 5; the new Pad) and non-Retina devices (iPhone 3GS, iPad, iPad 2) is the same, although the resolution of iPhone 4 is twice that of 3GS. For example, 10point is 20 pixels on Retina devices, and 10 pixels on non-Retina devices (iPhone 3G).

When communicating between project members, Point should be used instead of pixel.

SVN operates files containing the @ symbol

Often seen in iOS appsxxxx@2x.pngSuch file names are high-resolution large images for retina devices. When you use the svn command line to operate them, they will be interfered by the @ symbol. The solution is to add an @ symbol at the end of the svn command, such as:

svn del icon@2x.png@ svn info Default@2x.png@  

If you move dozens of png files at a time and then svn commit, you can use shell batch processing:

svn status | awk '(=='!'){print }' | grep -v @ | xargs svn del  

The above command deletes files whose names do not contain the @ symbol and are no longer on the hard disk from svn version control.

for file in `svn status | awk '(=='!'){print }' `; do svn del $file'@'; done  

The above command deletes files whose names contain the @ symbol and are no longer on the hard disk from svn version control.

svn add is the same as above, just follow the same method.

The code structure in Xcode is not consistent with the file system on the operating system

It is recommended to create the directory in Finder and then click "Add Files to" in Xcode's Project Navigator to add it to the project.

Adapted to iPhone 5

iPhone 5 is different from previous iPhones in that it uses a 4-inch Retina screen, so its Point count becomes 320 * 568 points.

Open source code

Objective-C Tutorial

This siteOriginal articleAll follow "Attribution-NonCommercial-ShareAlike 4.0 License (CC BY-NC-SA 4.0)". Please keep the following tags for sharing and interpretation:

Original author:Jake Tao,source:"Get started with iOS development in 60 minutes"

198
0 1 198

Further reading

Leave a Reply

Log inCan comment later

Comment list (1)

  • Adan
    Adan 2015-03-24 17:54

    good

Share this page
Back to top