Developer on Alibaba Coud: Build your first app with APIs, SDKs, and tutorials on the Alibaba Cloud. Read more ＞
<span id="Label3"></p>As an app developer, have you had the following experience? To make sure your app is correct, you must have done a lot of testing before submitting it to the app Store. It also works well on your device, but after the app store, there are users complaining that it will come back! If you're as good a perfectionist as I am, you definitely want to make the app Perfect. So you open the code ready to fix the problem of the flash back ... But where do you start? This is where the iOS crash log comes in Handy. In most cases, you can learn about the details and useful information about the FLASHBACK. In this tutorial, you will learn some common crash log cases, and how to get crash log files from development devices and itunes Connect. You will also learn to symbolize (symbolication), from log tracking to Code. You will also learn to debug an application that will be rolled out in a pending situation. Let's get started!<strong><strong>What is a crash log and where can I get it?</strong></strong>When an app on an iOS device flashes, the operating system generates a crash report, also known as a crash log, to be on the Device. The crash log has a lot of useful information, including what the app is for. typically, There is full stack trace information for each executing thread, so you can learn what each thread is doing when the flashback occurs, and tell which thread the flashback occurred On. There are several ways to get crash logs from your device. after syncing with the itunes Store on your computer, the crash log will be saved on your computer. Depending on your computer's operating system, The crash log will be saved in the following location: Mac OS x:~/library/logs/crashreporter/mobiledevice/ windows xp: c:documents and Settingsapplication dataapple computerlogscrashreportermobiledevice<device_name> windows Vista or 7: c:usersappdataroamingapple computerlogscrashreportermobiledevice<device_name> When the user complains about the Flash back, You can ask him to allow the device to sync with itunes and, depending on the operating system, download the crash log to the above location and send it to you via Email. You must try to get all the crash logs generated by the user Device. Because the more crash logs, the easier it is to diagnose the problem! in addition, if you have xcode, you can easily get the crash log from your device via Xcode. Connect your iOS device to your computer, and then turn on Xcode. Select Window menu from the menu bar and select Organizer (shortcut is shift-cmd-2). on the organizer window, Select the Devices tab bar. On the left side of the navigation panel, select device logs, as shown in the: look, there are several Device Logs menu items on the left. LIBRARY The following device logs is a log of all your devices (once connected to xcode). The device Logs under each device is a log of the corresponding Devices. After the app is submitted to the app store,You can also get the crash log from ITunes connect to the User. Log on to ITunes Connect, select manage Your applications, Click the appropriate app, click the view details button below the app icon, then click &nbs in the Links section on the right column P Crash reports . If there is no crash log, try clicking the refresh button and refreshing it. If your app isn't selling much, or it's just been on the shelves, there may not be any crash logs on your iTunes connect Account. If there is a crash log on itunes connect, you will see the crash report as: sometimes, Despite the user reporting the flashback, you still don't see it. At this point, it's a good idea to let users send crash reports directly to You. <strong><strong>what happens when a crash log is generated?</strong></strong>There are two main scenarios that create a crash log:<strong><strong>1. Application violates operating system Rules. </strong></strong><strong><strong>2. There are bugs in the Application. </strong></strong>Violating IOS rules includes watchdog timeouts on startup, recovery, suspend, exit, user forced exit, and low memory Termination. Let us have a detailed look at it.<strong><strong>Watchdog Timeout mechanism</strong></strong>Starting with iOS 4.x, when exiting the app, the app does not terminate immediately, but instead comes back to the Background. however, If your app responds quickly enough, the operating system may terminate your app and generate a crash log. These events correspond to the following uiapplicationdelegate: application:didFinishLaunchingWithOptions:applicationWillResignActive: ApplicationDidEnterBackground:applicationWillEnterForeground:applicationDidBecomeActive: Applicationwillterminate: above all of these methods, the application has only a limited amount of time to complete processing. If it takes too long, the operating system terminates the app. Note: This is very easy to do if you do not place operations that take longer (such as network Access) on a background thread. For information on avoiding this situation, please refer to our other two tutorials: Grand central Dispatch and Nsoperations.<strong><strong>User forced Exit</strong></strong>IOS 4.x starts to support Multitasking. If you apply a blocking interface and stop responding, the user can terminate the app by double-clicking the Home button on the home Screen. At this point, the action app will generate a crash log. Note: when you double-click the home button, you'll See all the apps you've Run. Those apps aren't necessarily running, or they're not necessarily suspended. typically, when a user taps the home button, the app remains in the background for about 10 minutes, and then the operating system automatically terminates it. So double-clicking the Home button shows a list of apps that are just a series of apps that have been opened in the Past. Deleting icons for those apps does not generate any crash logs.<strong><strong>Low Memory termination</strong></strong>When you subclass uiviewcontroller, you may have noticed the didreceivememorywarning method. Apps running in the foreground have the highest level of optimization for accessing and using Memory. however, This does not mean that the app can use all the available memory on the device--only a fraction of the available memory can be used per app. When memory usage reaches a certain level, the operating system issues a uiapplicationdidreceivememorywarningnotification Notification. also, Call the didreceivememorywarning method. At this point, in order for the app to continue to function properly, the operating system starts terminating other apps in the background to free up some memory. After all the background apps have been terminated, if your app needs more memory, the operating system will also terminate your app and generate a crash log. In this case, the background app is terminated, and the crash log is not Generated.<strong><strong>note:</strong></strong>Depending on the Apple documentation, Xcode does not automatically add a low memory log. You must manually get the Logs. however, based on my personal experience, using Xcode 4.5.2, low memory logs are also automatically imported, except that the "Process" and "Type" properties are labeled Unknown (unknown). also, It is worth mentioning that allocating a large chunk of memory in a very short period of time will be a huge burden on system memory. In this way, a memory warning notification is also generated.<strong><strong>There are bugs in the app</strong></strong>As you can imagine, most of the flashbacks are due to bugs in the app, so most crash logs are caused by bugs in the app. There are many kinds of bugs. In the latter part of the tutorial, you'll learn how to find the problem and fix it by debugging an app with bugs that will generate a crash log!<strong><strong>instance of crash log</strong></strong>Let's take a look at an example of a crash log so that you have a mental spectrum before dealing with some practical problems. Without further ado, meet your new friend: the report looks like a heavenly book. :) WE'LL read it in a few points.: (1) process information The first part is the information about the process of the FLASH-BACK. incident identifier is a unique identifier for the crash Report. The crashreporter key is a unique key value that corresponds to the device Identity. Although it is not a true device identifier, it is also a very useful intelligence: if you see the Crashreporter key value of 100 crash logs is the same, or only a few different crashreport values, it is not a common problem, Occurs on only one or a few devices. hardware model identifies the device Type. If many crash logs come from the same device type, the app only has a problem with a particular type of device. In the above log, the crash log produced the device is the iphone 4s. Process is the app Name. The numbers inside the brackets are the process IDs that are applied when the flash is rolled Out. The next few lines are self-explanatory, no need to repeat. (2) Basic Information This section gives some basic information, including the date and time of the flashback, the iOS version of the Device. If there are many crash logs from iOS 6.0, the problem only occurs on iOS 6.0. (3) exception in this section, you can see the type of exception thrown when a flashback occurs. You can also see the exception code and the thread that throws the Exception. Depending on the type of crash report, you can see some additional information in this Section. (4) Thread Backtracking This section provides a backtracking log of all threads in the app. Backtracking is the list of all active frames when a flashback occurs. It contains a list of functions that are called when a flashback Occurs. Look at the following line of logs: it includes four columns: frame Number--here is 2. The name of the binary Library-here is xyzlib. the address of the calling Method--here is 0x34648e88. the fourth column is divided into two sub-columns, one base address and one offset. Here is 0x83000 + 8740, the first digit pointing to the file, and the second number pointing to the line of code in the File. (5) Thread state This part is the value in the register when the Flash is rolled back. This part of the information is generally not needed, because the information in the backtracking section is enough to let you find out where the problem lies. (6) binary Image This section lists the binaries that were loaded when the flash was rolled Out. <strong><strong>Symbolic Symbolication</strong></strong>The first time you see backtracking on a crash log, you may find it meaningless. We are accustomed to using the method name and the number of rows, rather than mysterious places like this: the process of translating these hexadecimal addresses into the method name and the number of rows is called Symbolization. After a few seconds after getting the crash log from the Organizer window of xcode, The crash log is automatically symbolized. The following signed version of the above line is as follows: when Xcode signs the crash log, it needs to access the corresponding application binaries on the App Store and The. DSYM file that was generated when the binaries were Built. Must match exactly. otherwise, The log will not be fully symbolized. therefore, It is important to keep each compiled version that is distributed to the User. When you archive your app before submitting it, Xcode saves the App's binaries. All archived app files can be found under the Archives tab bar in Xcode organizer. When a crash log is found, Xcode automatically signs the crash log if there is a matching. dsym file and application Binaries. If you switch to another computer or create a new account, be sure to move all binaries to the correct location so that Xcode can find Them. （<strong><strong>note:</strong></strong>You must keep both the app binaries and the. dSYM file in order to symbolize the crash log intact. Every build that is submitted to itunes Connect must be archived.. dsym files and binaries are specific bindings for each build and subsequent build, and even from the same source code files, each build is different from other constructs and cannot be replaced with each other. If you use the build and Archive commands, These files are automatically placed in Place. If you are not using the build and archive commands, place them in a location that spotlight can search (such as the home directory). ）<strong><strong>low memory Flash back</strong></strong>Because the low memory crash log is slightly different from the normal crash log, This tutorial is specifically explained Separately. When the iOS device detects low memory, the virtual memory system sends a notification request that the app frees the Memory. These notifications are sent to all running apps and processes, trying to reclaim some memory. If memory usage remains high, the system terminates the background thread to relieve memory Pressure. If enough memory is available, the app will be able to continue running without generating a crash report. otherwise, The app will be terminated by iOS and generate a low memory crash Report. There is no stack backtracking on the application thread on the low memory crash log. instead, It shows the amount of memory used per process in memory Pages. (when writing this article, the size of a memory page is 4KB.) You will see the jettisoned word after the process name that was terminated by iOS for releasing the memory Page. If you see that it appears behind your App's name, your app is terminated because it uses too much memory. A low memory crash log looks like this: when an app has a low memory flash, you need to look at how memory is used in your app and how to handle low memory warnings. You can use the instruments tool to use allocations and leaks to discover memory allocation problems and memory leak Issues. If you don't know how to use Instruments to check for memory problems, you can take a look at this tutorial. also, Don't forget the virtual memory! The leaks and allocations of the instruments tool cannot track memory Usage. You must use VM Tracker to view memory Usage. VM Tracker is turned off by Default. Open instrument, manually check the automatic snapshotting flag or press the snapshot now Button. Later in this tutorial, you will learn how to study low memory crash logs.<strong><strong>Exception Encoding</strong></strong>Before studying the Real-world flashback scenario, There is one more point to highlight: the interesting exception codes. You can find the exception code in the exception section of the Report-the 3rd part of the preceding Code. Some encodings are more common. typically, The exception code begins with some text, followed by one or more hexadecimal values, which is exactly where the underlying nature of the flashback is. From these encodings, it is possible to distinguish between a program error, illegal memory access, or other Reasons. Here are some common exception codes: 0x8badf00d: read "ate bad food"! (does the number change to a letter, does it look like:p) the code indicates that the app was terminated by iOS because of a watchdog Timeout. It is usually the application that takes too much time to start, stop, or ring the application system Events. 0xbad22222: This code indicates that the VoIP application was terminated because it was restarted too frequently. 0xdead10cc: Read "dead lock"! This code indicates that the app is terminated because it consumes system resources when it is running in the background, such as when the Contacts database is not Released. 0xdeadfa11: Read "dead fall"! This code indicates that the app was forcibly exited by the User. According to the Apple documentation, the force exit occurs when the user presses the switch button until the "swipe to shut down" appears, and then long press the home Button. Forcing the exit will result in a crash log containing the 0XDEADFA11 exception encoding because most of the forced exits are due to the application blocking the Interface. （<strong><strong>note:</strong></strong>Shutting down suspended apps in the background tasks list does not result in a crash log. Once the application is suspended, it is justified when it is Terminated. therefore, The crash log is not Generated. It's time to do your job! You have learned all the basics of analyzing crash logs and fixing bugs! Suppose you just entered Rage-o-rage co., Ltd. to Work. The company has a hot-selling app on the app store called Rage Masters. Your boss, andy, wants you to help Out. several users often complain about the Flash-back Problem. Your task is to study these flashbacks, symbolize the user-provided crash logs, find the problem, and fix it. You can download the App's source code from Here. （<strong><strong>note:</strong></strong>If you want to regenerate the crash report yourself, follow these guidelines: 1. Download the source code and open the project file in Xcode. 2. Connect to the iOS device using the correct provisioning Profile. 3. Select iOS device from the Xcode toolbar--not the simulator as target, then build the app. 4. When you are on the device to the default page (full screen image applied), immediately click on the Stop button on Xcode. 5. Turn off Xcode. 6. Open the app directly on the Device. 7. Test the scene, connect the device to the computer when finished, and get the crash log through Xcode. ）<strong><strong>Scenario 1: Bad code</strong></strong>A message from the User: "big brother, your application is a piece of excrement!" I downloaded it to my own ipod Touch and iphone and downloaded it to my son's ipod Touch. On all the equipment, it is not open on the flash back ... " A message from the user says, "i downloaded your app and just turned it back on." It's so sad ... " Another message is more Specific: "your app won't work." I downloaded it to my wife's device. All devices are on the blink of an open ... "well, don't lose heart!" What do these opinions hide? Let's look at the crash log: did you find the problem? The exception code is 0x000000008badf00d, and there is a later report: this shows that the app is flashing at startup, and the iOS watchdog mechanism terminates the Application. Handsome! Found a problem, but why did it happen? Then look down at the log. Reads the backtracking log from the bottom up. The bottom frame 25:libdyld.dylib is the first call, then the frame, Rage Masters, main (main.m:16), and so On. The frames associated with the application source code are the most Important. Ignore system libraries and frameworks. The next frame associated with the code is: the application is rolled out when executing the Rmappdelegate (rmappdelegate.m:35) class application:didfinishlaunchingwithoptions: the 35th line of Code. Open Xcode and look at that line of code: that's it! Call the Web service synchronously?! On the main thread?! On the Application:didfinishlaunchingwithoptions: method?!! Who wrote the code?! Network calls on the main thread makes kittens Sad. In any case, you have to fix the Problem. This call must be done asynchronously, and even more ideally, the Web service will be executed in the other part after Application:didfinishlaunchingwithoptions: return Yes. Calls in other places may require more modifications. At the moment, we just have to make the app Non-refundable. Better design can be achieved in the Future. Replace the nasty code above (and the three lines below) with the following asynchronous version:<strong><strong>Scenario 2: A button that cannot respond to an event</strong></strong>One user said, "i can't add a rage master to a bookmark." I want to add a time when the app will flash back ... " With a user said: "bookmarks can not be used ... On the detailed page, click on the Bookmark button and the app will flash back! "the above complaint is not very clear, the cause of the problem must be Varied. Look at the crash log: The exception code is Sigabrt. typically, A SIGABRT exception is caused by an object that receives an implementation message. or, in simple terms, a non-existent method is called on an object. This generally does not occur because the A object calls the B method, and if the B method does not exist, the compiler will Error. however, If you are using selector to indirectly invoke the method, the compiler cannot detect whether the object exists for that Method. Back to the crash log. It indicates that the flashback occurred on a thread numbered 0. This means that it is possible to invoke a method on the main thread that an object is not Implemented. If you continue to read the backtracking log, you will find that the only frame that is related to your code is main.m:16. It's not much Help. Continue to view the frame call up, This appears: this is not the code you wrote yourself. But at least it confirms that the object called a method that was not implemented. Go back to the rmdetailviewcontroller.m file, because that's where the bookmark button implements the Action. Find the Bookmark function code: look no problem, check the storyboard (xib file), confirm the correctness of the button Connection. That's it! In mainstoryboard.storyboard, the button is connected to Bookmarkbuttonpressed: instead of bookmarkbuttonpressed (note that the following semicolon indicates that the method has a parameter). Just modify the method signature above to fix the problem: of course, you can simply delete the wrong connection on the Xib file, and then reconnect the method so that the Xib file is connected to the correct method. Both methods are Ok. And a flash-back problem, good Work.<strong><strong>Scenario 3: bugs on the table</strong></strong>Another user complained, "cannot delete bookmarks on Bookmark view ..." There is another user complaining about the same problem, "when I try to delete a bookmark, the app flash back ..." These messages don't work, or look at the crash log! It looks like the crash log in front of Me. is another SIGABRT Exception. You may wonder if the same question is being sent to an object that does not implement the appropriate method? Let's look at the backtracking logs to see which methods are Called. Starting at the bottom, your source code is finally called Frame 6: This is a method of Uitableviewdatasource. Oh?! There is no doubt that Apple has implemented the method-you can reload it, but it doesn't seem to have been implemented Yet. also, This is an optional delegation method. So the problem is not to call a method that is not Implemented. Then look at the frames above: frame 5, UITableView called its own other method deleterowsatindexpaths:withrowanimation: and then it looks like the Apple internal method _ Endcellanimationswithcontext: Called. Then the foundation framework has an exception handleFailureInMethod:object:file:lineNumber:description:. These analyses, combined with user complaints, appear to be a bug in the process of handling UITableView Delete Rows. Back to Xcode. Do you know where to look? Can you tell from the crash log? is the 68th line of the RMBOOKMARKSVIEWCONTROLLER.M File: did you find the problem? Give you some time to take a closer look. Find it! What about the data source? The code deletes a row on the table view, but does not modify the data source behind it. Replace the above code with the following to fix the problem: it's done! go, Nasty bug!!.<strong><strong>Scenario 4: When you eat a lollipop, you are back!</strong></strong>User email says, "when rage master eats lollipops, the app will flash back ..." Another user said, "i let rage master eat lollipop, and not a few times the app just flashed back!" Crash Log below: This log is much different from what we saw Earlier. This is a low memory crash log from iOS 6. As we said earlier, low memory crash logs are very different from other types of crash logs, and they do not point to specific files and lines of Code. instead, They draw a graph of the memory usage on the device during the FLASH-BACK. at the very least, the head is similar to the other crash Logs: provides information such as Incident Identifier, crashreporter Key, Hardware Model, OS version, and More. The next section is specific to the low memory crash log: free pages refers to the number of available memory Pages. The size of each page is approximately 4KB, the above log, the available memory is approximately 3,872 KB (or 3.9 MB). Purgeable pages is the portion of memory that can be purged or reused. In the above log, it is 0KB. Largest process is the name of the app that uses most of the memory when It's rolled back, and it's your app in the log above! Processes shows the list of processes at the time of the flashback and also contains memory Usage. Contains the process name (first column), The process unique identifier (second name), the number of memory pages used by the process (third column). The last column is the status of each app. typically, the state of the app that has a flashback is Frontmost. Here is Rage Masters, using 28591 pages (or 114.364 MB) of Memory-too much memory! through, the maximum process and frontmost state of the application is the same, but also caused low memory flash application Process. however, It is also possible to see the maximum process and frontmost states applying different examples. For example, If the maximum process is springboard, ignore it, because the springboard process is the app that displays the home screen, appears when you double-click the home button, and so on, and it's always Active. When low memory occurs, iOS emits a low memory warning to the active app and terminates the background app. If the foreground app continues to grow memory, iOS will terminate it. to find the cause of a low memory problem, you must use instruments to profile your app. If you don't know what to do, take a look at one of our tutorials on This. :] in addition, you can take shortcuts to respond to low memory warning notifications to resolve partial flashback Issues. Back to XCOde View the RMLOLLIPOPLICKER.M File. This is the realization of eating lollipop view Controller. Look at the source code: when the user clicks the run button, the app starts a background thread, calls the Licklollipop method several times, and then updates the interface to reflect the number of lollipops Eaten. The Licklollipop method reads a long string from the property list file (PLIST) file and then adds it to the Array. This data is not important and can be recreated without compromising the user Experience. It's a good practice to use every situation that clears and rebuilds data without impacting the user experience. This makes it easy to free up memory and reduce low memory warnings. so, How do you improve the quality of your code? Implement the didreceivememorywarning method, which processes the data as follows: <strong><strong>Next step?</strong></strong>hooray, you've researched 4 flash-back cases! Your application is more complete and you have learned some important debugging Techniques.<p><p>Ios--crash Log Analysis</p></p></span>
This article is an English version of an article which is originally in the Chinese language on aliyun.com and is provided for information purposes only. This website makes no representation or warranty of any kind, either expressed or implied, as to the accuracy, completeness ownership or
reliability of the article or any translations thereof. If you have any concerns or complaints relating to the article, please send an email, providing a detailed description of the concern or
complaint, to firstname.lastname@example.org. A staff member will contact you within 5 working days. Once verified, infringing content will be removed immediately.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
and provide relevant evidence. A staff member will contact you within 5 working days.