Common crash problems in iOS, crash log analysis, and ioscrash Log Analysis
First, iOS common crash Problems
1. Insert an empty Element
Crash when an empty element is inserted for variable objects such as NSMutableArray, NSMutableDictionary, and NSMutableSet
The correct method is to add judgment. The sample code is as follows:
NSDictionary * dic;
NSMutableArray * arr = [NSMutableArray new];
If (dic ){
[Arr addObject: dic];
}
NSLog (@ "% @", arr );
Condition for non-null addition: if (dic)
2. Cross-border and pointer null judgment
This type of crash is similar to C ++. For NSArray objects, when calling objectAtIndex, you must determine whether to cross the border.
Pointer OC is rarely used in development. If you want to use it, you must determine whether it is null.
3. After NSNotification is added, removeObserve must be used in the dealloc function.
4. Create an NSTimer scheduled task. In the dealloc function, the task must be invalidate.
5. When you initiate a network request in the Code and set the proxy, you must release the change proxy in the dealloc function because there is time for network access, when the network data is returned and the proxy object is no longer in use, crash occurs.
6. Use APIs of the higher version. Because each app has an iphone version, when the user machine uses a lower version of the system, it will crash
7. If the memory usage is too large, crash will occur when two memory warnings are received. Therefore, the released items must be released in time.
8. The crash caused by multi-thread concurrent operations. In a multi-concurrency environment, if one thread has deleted the data and the other thread has accessed the data, it will inevitably crash because the data is not there, therefore, the locking mechanism must be used to solve the problem.
9. Call a nonexistent class or Method
If (NSClassFromString (@ "MFMailComposeViewController") respondsToSelector: