This article is aimed at iOS development beginners who already have programming experience in other languages (such as Java, C, PHP, Javascript). The original intention of this article is to let my colleagues know how to start iOS App development in one hour. The learning objectives include:

  • Ability to use Xcode IDE and emulator
  • Modify and debug existing iOS App
  • Ability to create new modules within existing applications
  • Ability to create new applications
  • Being able to publish apps to the App Store

This article does not contain any advanced knowledge of iOS development and should not be read by those who have already learned iOS development and should not be read by those who have learned iOS development after this article.

It’s not just about learning a new language

People who have experience with scripting (Javascript, PHP, Shell) will feel that the learning curve for iOS development is higher than for scripting when they first start learning iOS development, and yes, that feeling is correct. Because learning iOS development isn’t just about learning a new language, it includes:

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

Beginners in scripting languages don’t usually draw graphical interfaces and interact with people, and iOS doesn’t make much sense if it doesn’t do graphical interfaces and handles text manipulation databases like scripting languages do.

As a result, when I used to write other introductory tutorials, it was usually “getting started with XXX in 15 minutes”, whereas iOS would take many times longer to write.

Environment to prepare

IOS development requires apple’s software environment: Mac OS, Objective-C compiler, device emulators, etc. Development tools don’t have to be Xcode, just a source code editing tool (Vim will do, just not as versatile as Xcode).

Mac OS

The easiest way to have a Mac OS environment is to find an Apple computer, including the iMac, MacBook Pro, MacBook Air, Mac Mini, but not apple’s mobile devices (iPod Touch, iPhone, iPad, iPad Mini, They run iOS, not Mac OS.) Mac OS comes with Apple computers, and the latest version is Mac OS X 10.8. Mainstream versions include Mac OS X 10.6 and Max OS X 10.7.

If you’re strapped for cash, 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 talk about black Apple. Black Apple is a modification of the Mac OS to install on non-Apple hardware, which is a violation of the DMCA Act. More information on black Apple can be found on Wikipedia

Apple’s high price puts pressure on Chinese software developers to survive, so there are some real black Apples in China, as well as abroad.

Black Apple is basically good for iOS development, but there are a few issues:

  • It is illegal to install black apples
  • Personal behavior is generally not pursued by Apple, but it is frowned upon by its peers
  • Black Apple is super hard to install, pick the hardware. Even if the exact model and batch are the same, machine A may be loaded, but machine B cannot
  • Black Apple systems have some usage issues, such as driver bugs, blue screen for standby recovery, Internet browsing problems
  • Black Apple can’t upgrade at will, and one safari update could crash the whole system

None of this will directly affect Xcode writing or emulator testing, but safari’s ability to turn a page when you’re trying to find something online does make you feel bad. So, if your wallet allows, get an apple instead.

Xcode and emulator

Xcode can be downloaded for free from the Apple website: Xcode download address

The iOS SDK and emulator are automatically installed when Xcode is installed.

It’s nice that such a powerful IDE is free.

Start with an existing application

Learning a new software development skill and being able to make a working product in the first place is very important and helps motivate me. Many times when I was in college, I tried to learn a new language and spent half a month immersed in data types and grammar dictionaries, but I didn’t even make my first Hello World.

This time, let’s start with an existing application.

download

First, let’s download a sample code from the Apple Developer Center. I selected ToolBarSearch.

At the end of this document, there are several other sites where you can download open source iOS products or Code snippets, but WHEN I tried, Apple Sample Code was the most successful.

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 the Finder and could only be accessed through the Finder’s Go > Go Folder function.

Open the

There are three ways to open an iOS Project

Double click on project

Open Finder, go to the ToolBarSearch directory you just downloaded and unzipped, find the toolbarSearch.xcodeProj file, double-click on it, and Xcode will automatically launch and open the project

Select Project to open in Xcode

  • When Xcode is not started (press Command Q to exit if Xcode is already started), start Xcode and the Welcome page will pop up. Click on the “Open Other” button in the lower left corner to find the ToolBarSearch directory. Double-click the ToolBarSearch directory, or double-click the ToolbarSearch.xcodeProj file

  • If Xcode is Open, click File -> Open or File -> Open Recent on its menu bar and select the project to Open

Open it from the command line

Prior to Mac OS 10.8, some directories (such as /var/private/tmp) would not be found by clicking the mouse in the Finder and Xcode’s File > Open dialog, and would need to be opened via the command line terminal.

Open the terminal and execute:

CD /ToolBarSearch parent directory /ToolBarSearch open -a XcodeCopy the code

Open-a is a MAC OS system command that can be opened in any project other than iOS.

Run the app you just downloaded

Click the Run button in the upper left corner of Xcode (or both Comman and R keys) and Xcode will compile the source code and Run the application in the emulator.

A “Build Succeeded” message is displayed on the screen. Otherwise, “Build Failed” is displayed and the emulator is not started.

Compiling IB Documents for earlier than iOS7 is no longer supported after Compiling the latest Xcode

Modify the

Performed Search using… Ok, so let’s change that.

  • In the upper left corner of Xcode, there is a row of small buttons below the Run button. The third one from left to right is a magnifying glass icon. If you move the mouse over it, it will Show “Show the Search Navigator”.

  • Search results have only one: ToolbarSearchViewController. M, points are highlighted below the filename “Performed” string, on the right side of the code editor area is automatically open this file, and the rolling screen, contains the “Performed” this line appears in the middle of the editing area.

  • Modify the string in the double quotation marks to whatever it is, and press “Command S” to save.

Of course, you can also use grep and vim at the terminal.

Run the modified application

So I’m going to run Command R and see if I can see it.

Yes, changing an app is as simple as that.

Objective-C

Objective-c is the development language for Apple applications, including Mac OS apps for Macs and iOS apps for mobile devices. It is an object-oriented programming language.

Apple also offers software called Interface Builder, or IB for short, for creating Visual interfaces, much like Dreamweaver for web pages or Visual Basic for desktop software. And then IB was integrated into Xcode and became part of Xcode. This document does not cover IB, but objective-C, because:

  • Almost every book on iOS development (paper, ebook) has a ton of step-by-step screenshots showing how to develop iOS apps in IB, while there aren’t that many books on Objective-C development.
  • IB can be used to intuitively and conveniently draw interface, set control properties, establish the connection between code and control, but the background business logic and data processing still rely on Objective-C, visible, regardless of IB, Objective-C is impossible to bypass.

A superset of the C

Objective-c extends ANSI C and is a superset of C, i.e. :

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

Except that the object-oriented syntax is SmallTalk style (described below), the other non-object-oriented syntax and data types are exactly the same as C, so this article will not repeat them. Take a look at a classic Hello World example:

#import <Foundation/Foundation.h> int main(int argc, char *argv[]){ @autoreleasepool{ NSLog(@"Hello World!" ); } return 0; }Copy the code

Is it like going back to the time of learning C language in freshman year? It looks almost the same as C, right? Yes, because it doesn’t use its object-oriented features, haha!

SmallTalk’s messaging syntax style

Objective-c’s object-oriented syntax is derived from SmallTalk, the Message Passing style. In terms of source style, this is where it differs most from the C Family languages (including C/C++, Java, and PHP).

In the Java, C++ world, we call a method on an object. In Objective-C, this is called sending a message to a type. It’s not just a word game, the technical details are different.

In Java, the object/method relationship is very strict, a method must belong to a class/object, otherwise compilation will report an error. In Objective-C, the relationship between type and message is looser, and the message is handled dynamically at runtime, sending a message to a type that it can’t handle, and throwing an exception instead of hanging.

[obj undefinedMethod];

Copy the code

If you call an undefined method in your code, Xcode will warn you, but it will compile successfully and run in error. It prints an error like this:

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

Copy the code

Java-like OOP concepts

Some of the object-oriented concepts in Objective-C can also be found in Java (similar, not identical). My readers are mostly Java and PHP programmers, so I’ll try to use Java concepts as analogies as possible.

Someone at GoogleCode has compiled a Java and Objective-C concept and data type mapping table, see here

string

There are strings in Objective-C that are wrapped in double quotes and preceded by an @ sign, for example:

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

Copy the code

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

A function call

As mentioned earlier, it is exactly the same as C without involving object orientation. Here are a few examples of function calls:

With no arguments

startedBlock();

Copy the code

With parameters

NSLog(@"decrypted string: %@", str); ,0,0,0 CGRectMake (0);Copy the code

Pass messages to class/instance methods

With no arguments

[obj method];

Copy the code

The corresponding Java version

obj.method();

Copy the code

With one parameter:

[counter increase:1];

Copy the code

The corresponding Java version

counter.increase(1);

Copy the code

With multiple parameters

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

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

The corresponding Java version

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

Message nested

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

Copy the code

The corresponding Java version

UINavigationBar bar = UINavigationBar.alloc().init().autorelease(); //Java has no Pointers, so the asterisk is removedCopy the code

class

Interfaces and implementations

Objective-c classes are divided into interface definition and implementation. The Interface definition is in the header file, the file extension is.h, the implementation is in the implementation file, the file extension is.m (there’s also a.mm extension for mixed Objective-C and C++ code).

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

Note that the closest thing to the objective-C concept of interface is the header file in C and C++, which is paired with implementation to declare class member variables and methods. It is completely different from the Java concept of interface:

  • In Objective-C you have one and only one implementation of an interface, whereas in Java you can have zero to N implementations of an interface
  • In Objective-C, interfaces can define member attributes, but in Java they can’t

In Objective-C, the equivalent of Java’s concept of Interface is Protocol, which we’ll talk about later.

Take an 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

Copy the code

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

Copy the code

Interfaces and implementations start at sign interface, at sign implementation, both end at sign end. The “@” sign is an amazing sign in Objective-C.

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

Java version of the code above:

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) { .... }}Copy the code

Private and public methods

Methods written in the.h header are public, and there is no concept of private methods in Objective-C.

There is no official mention of how objective-C implements private methods. I looked at StackOverflow and the general answer is that the only way to implement private methods is with a Category. However, according to my tests, even using a Category does not prevent external code from calling the “private method.” However, Xcode does not support auto-completion of “private methods”, and there is a warning that when run, it will still succeed. You see the officer know there is such a thing can, here is not deep.

Variables and Attributes

Class methods and instance methods

Class method

Class methods are Static methods in Java and PHP that can be called without instantiation. Class methods have a plus prefix. Example:

The class definition

@interface MyClass
	+(void) sayHello;
@end

@implementation MyClass

+(void) sayHello {
	NSLog(@"Hello, World");
}
@end

Copy the code

use

[MyClass sayHello];

Copy the code
Instance methods

Instance methods are common Java, PHP methods, must be instantiated to call. Instance methods have a minus prefix. Example:

The class definition

@interface MyClass : NSObject
-(void) sayHello;
@end

@implementation MyClass

-(void) sayHello {
	NSLog(@"Hello, World");
}
@end

Copy the code

use

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

Copy the code

Selector

Selector is a pointer to a method, similar to a dynamic method name in PHP:

<?php
class Hello {
	public function sayHello() {}

	public function test() {
		$fun_name = "sayHello";
		$this->$fun_name();
	}
}

Copy the code

In Objective-C, selectors are used to do two main things:

The action triggered by the binding control
@implementation DemoViewController - (void)downButtonPressed:(id)sender {UIButton *button = (UIButton*)sender; [button setSelected:YES]; } - (void)drawAnButton { UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; btn.frame = _frame; btn.tag = 1; btn.backgroundColor = [UIColor clearColor]; [btn addTarget: self action: @selector(downButtonPressed:) forControlEvents: UIControlEventTouchUpInside]; // When this button is pressed, downButtonPressed: method} @end is triggeredCopy the code
Delayed asynchronous execution
@implementation ETHotDealViewController - (void)viewDidLoad {// get the data source HotDealDataSource *ds = [[HotDealDataSource *ds] alloc]init]; [ds reload]; _items = ds.items; [self performSelector: @selector(refreshTable) withObject: self afterDelay: 0.5]; } -(void)refreshTable {[self.tableView reloadData]; } @endCopy the code

In this example, the data source is asynchronously called to the server HTTP interface through the ASIHTTP component, refreshTable will use the data returned by the data source, if there is no delay of 0.5 seconds, it will be executed immediately, while the data is still on the road, the page will become blank.

inheritance

Inheritance is written in the Interface definition. The syntax is: the subclass name is on the left and the superclass name is on the right, separated by a colon. Example:

@interface MyClass : NSObject
@end

Copy the code

The corresponding Java version is:

public class MyClass extends NSObject {
}

Copy the code

Protocol

Interface is Java, PHP Interface.

Definition of protocol

The protocol is defined using the @protocol keyword:

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

Copy the code

The corresponding Java version is:

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

Copy the code
Inheritance of agreement

The protocol itself may also inherit from other protocols:

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

Copy the code

Corresponding Java version:

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

Copy the code
Optional methods

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

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

Copy the code

By adding the @optional keyword, a class implements the protocol without implementing the print: method.

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

Protocol implementation

A class that implements certain protocols is written into the Interface definition. The syntax is as follows: Protocol names are wrapped in Angle brackets, multiple protocol names are separated by commas, and protocols are written on the right side of the parent class (if there is no parent class, the protocol is written on the right side of the child class).

Example:

@interface MyClass : NSObject <Printable, Drawable>
@end

Copy the code

Printable and Drawablw are two protocols.

The corresponding Java version is:

public class MyClass extends NSObject implements Printable, Drawable {
}

Copy the code

Category (Category)

Classes can add methods to an existing class without changing its source code. There are no similar features in Java or PHP.

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

Header file: NSObject+ json.h

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

Copy the code

Implementation file: NSObject+ json.m

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

Copy the code

To use the toJson method, simply include NSObject+ json. h and instantiate the NSObject class:

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

Copy the code

Of course, NSObject’s original methods still work, nothing’s changed, just a toJson method. Doesn’t it look much different from inheritance (except that NSObject is instantiated instead of JsonObject)? Here’s another example where inheritance doesn’t work:

Header file: NSObject+Json+ xml.h

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

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

Copy the code

Implementation file: NSObject+Json+ xml.m

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

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

Copy the code

Use:

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

Copy the code

Cocoa Touch

Cocoa is the framework for developing Mac OS apps. Cocoa Touch is the framework for developing iOS. Most of the Cocoa Touch and Cocoa Touch are the same. The multitasking, multi-windowing features of Cocoa are also absent (or not identical to Cocoa) in Cocoa Touch.

Just as learning the Java language requires learning some Spring, Hibernate, Struts (or some similar Java class library) to get started with J2EE applications, learning objective-C requires learning the Cocoa Touch framework to get started with iOS applications.

Delegate for the most commonly used design pattern

Cocoa Touch makes heavy use of the Delegate design pattern.

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

TableView

WebView

The navigation bar

Xcode

run

Shortcut key: Comman R

search

Search text

Search for files

Create a file/directory

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

The breakpoint

Simulator and real machine test

Simulator test

Open your project in Xcode, and in the top toolbar of Xcode, there’s a drop-down menu to the right of the Stop button (the black square button to the right of the Run button), Displaying “ToolBarSearch > iPhone 5.0 Simulator” (your app’s English name > currently selected debug), click on the drop-down menu and select iPhone 5.0 Simulator (where 5.0 is the iOS version), If your project is an iPad app, select iPad 5.0 Simulator), press the “Run” button, and Xcode will automatically compile and install the app you are currently editing and developing.

When operating on the emulator, if you encounter a breakpoint you set in Xcode during execution, the emulator will pause and switch the active window back to Xcode for debugging.

Breakpoints can be added or removed in Xcode without recompiling or installing the application.

Switch the emulated device

In the “Hardware” menu of the simulator, you can choose which device you want to simulate, including iPad and iPhone.

  • “Retina” refers to the Retina display. IPhone (Retina) refers to the iPhone4 and iPhone4S
  • A 4-inch iPhone is a 4-inch iPhone with Retina display

Switch the emulated iOS version

In the Emulator’s Version menu, you can choose which version of iOS you want to emulate. The device and version are independent of each other, iPhone 4S can have 5.0, 5.1, 6.1 iOS version, of course, iPhone 5 can not have 4.3 iOS version.

Touch screen

Clicking the iPhone and iPad screens on the simulator with the mouse (no distinction is made between the left and right keys) simulates touching the iPhone and iPad screens with your fingers. Some touch effects can be achieved, such as:

  • A mouse click equals a finger tap
  • Mouse long press equals finger long press (for example, you can hold down the App icon on the emulator to bring up the delete app confirmation box)
  • Mouse hold and drag equals finger drag
  • Double clicking and clicking on the emulator’s Home button is also equal to double clicking and clicking on the real machine’s Home button
Multi-finger gestures

Multi-finger gestures are complicated, and simple two-finger gestures can be simulated on the White Apple Laptop. The White Apple trackpad naturally supports multi-finger touch, but locating to the area of the simulator and responding to multi-finger gestures requires some extra keys:

  • Hold down the Option key and use two fingers to operate the touchpad to simulate dragging and rotation with two fingers
  • Hold Option+Shift to simulate double finger closure

Input method and keyboard

Type in Chinese

Phone-specific input methods (such as the nine-grid 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, copy it in Mac OS, and then hold down the mouse for more than 3 seconds in the input box of the application running on the simulator. When “Paste” pops up, select it.
  • In the emulator, press the Home button, go to the Setting App icon (not the emulator menu at the top of the Mac OS, there is no Setting), open the Settings for the emulated iOS device, Click on “general-Keyboard – International Keyboards – Add New Keyboard…” Add a Chinese keyboard, and you’ll be able to type Chinese using the software disk of the simulated iOS device, just like on the real iPhone/iPad.

Use the Mac keyboard

If you need to type a lot of text and the soft keyboard in the emulator is inefficient, you can use a physical keyboard by going to the emulator menu bar at the top of the Mac OS, clicking on the hardware menu, and selecting the Analog Hardware Keyboard from the drop-down menu. When you use the simulator to run an iOS app in the future, click the input box in the iOS app and the soft keyboard will not pop up. You can directly use the Mac’s physical keyboard to input.

Note:

  • IOS in the emulator takes over the physical keyboard input, so you’re calling the emulator iOS input method, not your Mac. For example, if you have Sogou Wubi on your Mac OS, iOS has added a New Keyboard, so typing Chinese into an iOS app will invoke Pinyin.
  • To switch between the Chinese and English input methods of iOS in the emulator, you can only press the little Earth icon on the soft keyboard of the iOS device, not the Command+ space bar on the Mac.

The geographical position

However, the Mac does not have GPS hardware or software infrastructure for location, so the simulator cannot automatically obtain the current location and cannot test the location function with the simulator. (Note that while WiFi can also be located independently — the iPad WiFi version can be located without GPS, the Mac WiFi doesn’t have location-related software.)

To test location-dependent features in the simulator (e.g., “XX near me”), manually assign a latitude and longitude to the simulator by going to the Simulator menu at the top of the Mac and clicking “Debug – Location – Custom Location”. A dialog box will pop up.

How do you get latitude and longitude? Go to Google Map (ditu.google.cn), find the location you want on the map (for example, if you want to know the location of Hangzhou Building, you can find hangzhou Building through the search box), right click, choose “what is here”, the search box will appear the longitude and latitude of this location, the front is latitude, the back is longitude. The territory of our Chinese dynasty is north latitude and east longitude.

camera

The Mac has a camera, but the Mac OS has no API designed to call the iOS emulator, so you can’t use the emulator to test features like the focus flash.

To test the photo-dependent function on the simulator, you can create a workaround in the code, that is, when the code detects that the camera is unavailable, a photo selector will pop up and let the tester select a photo from the album for subsequent operations (such as photo beautification, face recognition, bar code scanning).

Real machine test

Emulators can validate most of the functionality of your iOS app, but they can’t simulate hardware that isn’t available on Mac devices. One way around these limitations was mentioned earlier, but the ability to capture current location, take photos, and sense acceleration can’t be simulated, and an app must be verified on real devices before it can be released to consumers.

There are three ways to install an App that has not been submitted to the App Store for approval on an iOS device for testing:

  • Join Apple’s Developer Program and become a paid member. With this paid member, you can directly click “Run” in Xcode to compile and package the newly modified code and install it on the iOS device used for development and testing. The breakpoint set in Xcode can be activated by operating the program under test on the iOS real phone.
  • Jailbreak aN iOS device. After jailbreaking iphones and ipads, you can upload ipA packages compiled by Xcode directly over SSH (an iOS App is essentially an IPA package).
  • Jailbroken iOS devices, in conjunction with Xcode, can even perform the same functionality as paid developer plans: click “Run” on Xcode and automatically compile and install it to Run on iOS devices
  • Enterprise deployment solutions. Just like Alibaba’s Xuanyuan Jian, visit this website with iPhone/iPad and click the Xuanyuan Jian link inside to install the application.

Breaking Xcode is against the law (jailbreaking is legal), and the versions are so choosy that not all versions of Xcode will work, and not all cracked versions of Xcode will work well with jailbroken iOS. Jailbreak +SSH upload is as inefficient as enterprise deployment (inefficient deployment, unable to activate breakpoints in Xcode). It can only be used for QA acceptance and is not suitable for development self-testing. Given all this, the first formal approach is best suited for developing real-time tests. Let’s focus on this:

Have a developer account

Apple’s Developer Program is divided into individual developers and corporate developers for $99 and $299 per year, respectively, and can register 100 and 500 Apple test devices, respectively. This sets restrictions in a pay not cleared within the year, for example, on April 1, 2013 to pay a success, paid membership effective before March 31, 2014, during this period, the registered a less a number, even if the device registration come in with a minute and deleted immediately after, reduce the quota will not come back.

Before handing in money, had better ask, the colleague around, have already handed in money. If so, all you need to do is sign up for a free Apple ID (the Apple ID you use to install software in the App Store) and ask him to send you an invitation email to add your Apple ID to his team. Apple will think that you two are on the same team. It is legal to share a quota of 100 devices.

Install the certificate and private key

certificate

If you want to log in, you can log in with your Apple ID (provided you pay for it, or ask someone who paid for it to add you to the team).

Don’t bother, or want to know how to enter certificate management next time you don’t have my document? Follow these steps:

  • Enter the Apple Developer Center
  • Click on the iOS Dev Center
  • Click the blue “Login” button and Login with your Apple ID. Successful Login will take you to the developer home page
  • Click on the iOS Provisioning Portal in the upper right corner.
  • Click Certificates in the left menu bar

There is a “Your Certificate” area on the page with a rounded button below. This is Your personal Certificate. Download it. The next line, “If you do not have the WWDR Intermediate Certificate installed, click here to Download now”, this is apple’s public certificate, also down.

Double click the downloaded certificate, and when the certificate is installed, it will prompt you to enter your password. This is [Keychain Access tool] asking you to boot your Mac OS account password (equivalent to Linux sudo), not your Apple ID password.

Install the private key

If you are a public accounts and other colleagues, let him give you a private key, is an extension of p12 file, double-click it, key string access will automatically come out, need you to enter a password, the password asked to p12 file to you, not your Mac OS boot password, not your Apple ID password.

Register the device with Provisioning Portal

  • Open Xcode, find the Organizer from the Window menu in Xcode, and open it (Shift Command 2).
  • Connect your iOS device to your computer, and The Organizer automatically identifies your device and displays it in the left sidebar.
  • Locate your Device in the Organizer left sidebar, right-click on “Add Device to Provisioning Portal”, and wait for Organizer to prompt you for success. (After the device is selected, a button “Use for Development” will be displayed in the device details area on the right. You can also click it.)

Run the beta on a real iOS phone

Back in the Xcode home screen, there is a drop-down menu to the right of the Stop button (the black square button to the right of the Run button) that displays “ToolBarSearch > iPhone 5.0 Simulator” (your app’s English name > Debug currently selected), Click on the drop down menu, select your real device name, and press the “Run” button. Xcode will automatically compile and install the application you are currently editing and developing on the real machine for testing.

Publish to the App Store

IPA package

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

  • To Build a project in Xcode, use Command B
  • In the left project navigator, expand the Products folder to find the app you want to package, your app name.app, right-click, and select Show in Finder
  • Go to the Finder and Copy the.app directory (select, Command C), and Copy it to a folder that you create called Payload
  • Find your app Logo, a 512 * 512 PNG file, copy it to the Payload, and rename it the iTunesArtwork.
  • Create a ZIP package for the Payload directory and the ItunesArtwork file and change the extension to IPA
  • Double-click the IPA file and it will be opened in iTunes. If it is opened successfully and the app Logo is displayed in iTunes, it is successful

Batch automatic packing

In addition to the App Store, there are many other iOS App markets (such as 91 Assistant, Sync, etc.). If an App needs to be distributed to many App markets and their code is slightly different (for example, the statistical code is different), manually modify the source code, package, and restore the above method, it is more prone to error. The good news is that Xcode has a command line. We can write a shell script, use SE to automatically modify the source code, then call Xcode command line to compile to get your — app. App directory, and finally call zip, mv and other commands to automatically execute the IPA packing action described in the previous chapter.

Read the app code

Create a new app from scratch: Hello World

other

Control size in the code

Control sizes and font sizes in iOS apps refer to Point, Retina devices (iPhone 4, 4s, 5; The New Pad) has the same number of points as non-Retina devices (iPhone 3GS, iPad, iPad 2), even though the iPhone 4 has twice the resolution of the 3GS. For example, 10point is 20 pixel on a Retina device and 10 pixel on a non-Retina device (iPhone 3G).

Use Point, not Pixel, when communicating with project members.

The SVN operates on files containing the @ symbol

File names like [email protected] often appear in iOS applications. They are large high-resolution images for Retina devices. When operating them from the SVN command line, they will be disturbed by the @ sign.

svn del [email protected]@
svn info [email protected]@

Copy the code

If you move dozens of PNG files at a time before SVN commit, you can use shell batch processing:

svn status | awk '($1=="!" ){print $2}' | grep -v @ | xargs svn delCopy the code

This command deletes the files whose file names do not contain the @ sign and are no longer on the hard disk from the SVN Version controll

for file in `svn status | awk '($1=="!" ){print $2}' `; do svn del $file"@"; doneCopy the code

This command deletes the files whose file names contain the @ sign and are no longer on the hard disk from the SVN Version controll

SVN add is the same as above.

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

It is recommended to create a directory in Finder and then go to Xcode’s Project Navigator and click “Add Files to” to Add it to the Project

The iPhone 5 adapter

Unlike previous iphones, the iPhone 5 has a 4-inch Retina display, so its Point count is 320 by 568 points

Open source code

  • Sample Code of Apple official
  • The open source iOS App on Wikipedia
  • IOS Opensource –Domain Parking, previously available for Twitter and WordPress clients
  • code 4 app
  • UI 4 App, sister site to Code4App

Objective – C tutorial

This is the end of the article, thank you for watching, just something to say to readers:

The iOS developer community is getting smaller and smaller, and to be honest, it’s always nice to see some feedback from readers on the back end, at least you guys are still working on iOS… In order to thank the readers, I would like to contribute some of my collection of programming dry goods to you, give back to every reader, I hope to help you.

Dry goods mainly include:

①iOS advanced development must-see hot books (classic must-see)

②iOS development technology advanced teaching video

③BAT and other major manufacturers iOS interview real questions + answers. PDF document

(4) iOS development in the senior interview “resume production” guidance video

You can take it if you need it; How to obtain, please refer to the specific content – my GitHub

Mine: GitHub address