This is the 10th day of my participation in the August More text Challenge. For details, see: August More Text Challenge
DSYM how do you analyze it?
What is dSYM?
When Xcode compiles the project, we will see a dSYM file with the same name. DSYM is a relay file that holds the address mapping information for hexadecimal functions. The symbols we are debugging will be included in this file, and a new dSYM file will be generated each time we compile the project. Located in the/User / < User name > / Library/Developer/Xcode/Archives directory, for every release we it is necessary to save the corresponding Archives files;
What’s the use of dSYM files?
When our software is packaged in release mode or goes online, we will not see the crash error as intuitively as we did in Xcode. At this time, we need to analyze the crash report file. There will be a log file in iOS device to save the memory address of the function where each application fails. The Organizer of Xcode can export DeviceLog from the iOS device into a crash file. At this time, we can query the corresponding function name and file name of the program in the dSYM file through the error function address. The main precondition is that we need to have dSYM files for the software version, which is why it is necessary to keep Archives files for every release.
How do I match files one to one?
Each xx.app and xx.app.dSYM file has its own UUID, and the crash file also has its own UUID. As long as the UUID of these three files – -, we can use them to resolve the correct error function information.
- 1. Check the
xx.app
Of the fileUUID
, terminal Enter the command:dwarfdump --uuid xx.app/xx
(XX stands for your project name) - 2. Check the
xx.app.dSYM
Of the fileUUID
, enter the command in terminal:dwarfdump --uuid xx.app.dSYM
- 3.
crash
The first line in the fileIncident Identifier
Is that thecrash
Of the fileUUID
.
What are the types of multithreading?
Multithreaded classification
- pthread
- A general purpose multithreaded API
- Suitable for Unix, Linux, Windows and other systems
- Cross-platform and portable
- Difficult to use
- Language: C language
- Frequency of use: Hardly ever
- Thread life cycle: managed by the developer
- NSThread
- object-oriented
- Easy to use, can directly operate the thread
- Language used: OC Language
- Frequency of use: Occasionally
- Thread life cycle: managed by the developer
- GCD
- Technology to replace NSThread
- Takes full advantage of the device’s multi-core (automatic)
- Language: C language
- Frequency of use: Often
- Thread life cycle: automatically managed
- NSOperation
- Based on the GCD
- More simple and practical features than the GCD
- Use more object orientation
- Language used: OC Language
- Frequency of use: Often
- Thread life cycle: automatically managed
Principle of multithreading
At the same time, the CPU can only handle one thread, only one thread at work (execute) multi-threaded concurrent execution, (and) is actually a CPU rapidly between the multiple thread scheduling (switch) if the CPU thread scheduling time fast enough, creates a multi-threaded concurrent execution of illusion to think: if the thread is very, very much, what happens? The CPU will be scheduled between N threads, the CPU will be tired, it will consume a lot of CPU resources and each thread will be scheduled to execute less often.
Advantages of multithreading
Can properly improve the efficiency of program execution can properly improve the utilization of resources (CPU, memory utilization)
Disadvantages of multithreading
Thread take up some memory space (by default, the main thread take up 1 m, the child thread take up 512 KB), a large number of threads, if open will take up a lot of memory space, reduce the performance of the program thread, the more the greater the overhead of CPU scheduling threads on the program design is more complicated: such as communication between threads, multi-threaded data sharing;
GCD versus NSOperation
- 1.
GCD
Is the underlying C language that makes up the API, whereasNSOperationQueue
And the related objects areObjc
The object. inGCD
Is executed in the queue byblock
Structure of tasks, which is a lightweight data structure; whileOperation
As an object, it provides us with more choices; - 2, in
NSOperationQueue
, we can cancel the task that has been set to be executed at any time (of course, the task that has already started cannot be stopped), andGCD
Can’t stop already joinedqueue
theblock
(There is, but it takes a lot of complex code); - 3,
NSOperatio
N is an easy way to set up dependencies, so we can have oneOperation
It depends on the other oneOperation
In this case, even twoOperation
In the same parallel queue, but the former will not execute until the latter is finished; - 4. Can we bring
KVO
The application inNSOperation
, you can listen to oneOperation
Whether to complete or cancel, this way can be compared toGCD
More effective control over the background tasks we perform; - 5, in
NSOperation
In, we can setNSOperation
thepriority
Priority enables tasks in the same parallel queue to be executed sequentially, while inGCD
, we can only distinguish the priority of different task queues, if we want to distinguishblock
The priority of the task, which also requires a lot of complex code; - 6. We can do the right thing
NSOperation
In this case, add member variables and member methods to increase the reusability of the entire code, which is much easier than simply usingblock
Tasks are queued for execution with more freedom. Add more custom features on. In general,Operation queue
Provides more functionality you need when writing multithreaded programs, and hides a lot of complex code for thread scheduling, thread cancellation and thread priority, providing us with a simple API entry point. As a programming principle, we should always use a high-level, well-encapsulated API whenever possible, and only use the low-level API when necessary. But I think when our requirements can be done with simpler underlying code, it’s neatGCD
Might be a better choice,The Operation queue
To give us more choices. - 7,
NSOperation
More functions are available, see the API.NSOperationQueue
Is in theGCD
Based on the realization of, it’s justGCD
A higher level of abstraction - 8, in
NSOperationQueue
In, you can build eachNSOperation
Between. - 9,
NSOperationQueue
supportKVO
. Can be used to detectoperation
Whether executing (isExecuted
), end or not (isFinished
), whether to cancel (isCanceld
) - 10,
GCD
Only supportFIFO
AndNSOperationQueue
You can adjust the execution order of the queue (by adjustingThe weight
).NSOperationQueue
Can easily manage concurrent,NSOperation
Priority between. - conclusion
- use
NSOperation
Operations depend on each other, operations need to be suspended, concurrency management, priority control between operations, and limit the number of threads that can be executed at the same time. Let the thread stop/continue waiting at some point. - use
GCD
Case: The general requirement is very simple multithreaded operation, usingGCD
All right, simple and efficient. As a rule of programming, we generally want to use a high-level, well-encapsulated API whenever possible, and only use the low-level API when necessary. When the requirements are simple, conciseGCD
Might be a better choice, andOperation queue
To give us more choices.
- use
The downside of singletons
- Advantages:
- A class is instantiated only once, providing controlled access to a unique instance
- Saving system resources
- A variable number of instances are allowed
- Disadvantages:
- A class has only one object, may cause the responsibility is too heavy, to a certain extent the violation
Single responsibility principle
- Because there is no abstraction layer in the singleton pattern, it is difficult to extend singleton classes
- The abuse of singleton will bring some negative problems. For example, in order to save resources, the database connection pool object is designed as a singleton class, which may lead to the connection pool overflow due to too many programs sharing the connection pool object. If an instantiated object is not used for a long time, the system will consider it garbage and collect it, resulting in the loss of the object’s state
- A class has only one object, may cause the responsibility is too heavy, to a certain extent the violation
This section describes how to start the App
App startup Process
- parsing
Info.plist
- Load related information, such as a splash screen
- Sandbox establishment, permission checking
Mach-O
loading- If it is a binary, look for the part that fits the current CPU category
- Load all dependencies
Mach-O
File (recursive callMach-o
Loading method) - Locate internal and external pointer references such as strings, functions, etc
- The execution declaration is
attribute(constructor)
The C function - Loads a method in an extension of a class
C++
Static object loading, callObjc
the+load
function
Program execution
main
function- perform
UlApplicationMain
function - create
UIApplication
object - create
UIApplicationDelegate
Object and copy - Reading a configuration file
info.plist
, to set some properties of the program launch - To create the application
Main Runloop
cycle UlApplicationDelegate
Object begins to process listener events- After the program starts, the first call
application.didFinishLaunchingWithOptions:
methods - Such as
If the info. The plist
Is configured in thestoryBoard
Is loadedstoryboard
file - If it is not configured, it is created from code
UIWindow
->rootViewController
– > show
The App starts slowly. What might be the cause?
- Factors that affect startup performance
App
Each step in the startup process affects startup performance, but some parts of the startup process take very little time, while others are unavoidable. Considering the input-output ratio, we only list the parts we can optimize:main
Factors that affect the time spent before the function - The more dynamic libraries are loaded, the slower the startup.
ObjC
The more classes, the slower the startupC
theconstructor
The more functions, the slower startupC++
The more static objects, the slower startupObjC
the+load
The more, the slower the startup experiment proves, inObjC
The more dynamic libraries that need to be loaded for the same number of classes,App
The slower it starts. Similarly, with the same number of dynamic libraries,ObjC
The more classes,App
The slower the startup. Need to load the dynamic library from1
A rose to10
When the user perceives almost no difference from10
One, go up to100
It will become very obvious when the time comes. In the same way,100
A class and1000
I mean, it might be hard to detect, but1000
A class and10000
The differences between the classes begin to become apparent. Again, try not to writeatribute((constrcror))
theC functions
And try not to use itC++
Static object of; As for theObjC
the+load
Method, it seems that people are used to not using it. In any case, yesdispatch_ _once()
Try not to use any of the above methods.main()
Factors that affect the time after a function- perform
main()
Time of function - perform
applicationWillFinishLaunching
The time-consuming - RootViewController and
childViewController
The loading,view
And itssubviews
The loadingapplicationWillFinishLaunching
The time-consuming
What does 0x8badF00d indicate?
0x8badf00d
: This code indicates that the application occurred becausewatchdog
Timeout byiOS
The termination. Often the application takes too much time to start, stop, or respond to system events.0xbad22222
: Indicates the codeVolP
The application was terminated because it restarted too oftenOxdead10cc
This code indicates that the application was terminated because it occupied system resources while running in the background, such as the address book database.Oxdeadfa11
: This code indicates that the application was forcibly logged out by the user. According to Apple documentation, forced exit occurs when the user holds down the switch button until a “swipe to shut down” appears, and then holds down the Home button. Forced exits will produce a crash log with 0xDeadFA11 exception code, because most forced exits are caused by the application blocking the interface.
How do I prevent decompilation?
- Local data encryption: one of the anti-decompile encryption technologies for iOS applications: Yes
NSUserDefaults
.sqlite
Encrypts file data to protect accounts and key information - URL encoding encryption:
iOS
Application of anti-decompile encryption technology two: on the program appearsURL
Code encryption to prevent thisURL
Statically analyzed - Network data encryption:
iOS
The third application of anti-decompilation encryption technology: provide encryption scheme for the data transmitted by the client, effectively prevent the interception of data through the network interface - Method body, method name advanced obfuscation:
iOS
Application of anti-decompile encryption technology four: on the applicationThe method name
andmethods
Body is obfuscated to ensure that the source code cannot be parsed after being reversed - Program structure mixed encryption:
iOS
Use anti-decompilation encryption technology five: the logical structure of the application to shuffle, to ensure that the source code readability to a minimum - Use a third-party APP for security hardening
What third party principles or underlying knowledge do you know?
Runtime, Runloop, block, SDWebImage, AFN, YYCache, GCD and other low-level implementation