Preface Have you ever fixed a bug and then discovered a related bug, or fixed a bug in a way that caused another bug? However, these problems are great learning opportunities. So how do we learn as much as possible from the problems we fix? The method I use is to write a brief description of the problem, the fix, and the lessons learned. Use this method and let it help you become a better programmer. Whenever I fix a particularly tricky or interesting problem, I always spend a few minutes writing down some information about it. Here are some examples of typical records. I will share some problems and solutions below. 1. How can iOS continue downloading after the app switches to the background? NSURLSession already supports downloading after the app presses the home button. However, downloading cannot be performed after the app exits. Adding the following attributes to NSURLSession allows background downloading.
However, when the user presses the home button, the download can continue. If the user presses the home button in the background and then swipes up to kill the app, we should pause all download tasks in the appdidregiestActive method. 2. What is the problem of virtual currency in IAP in-app purchase causing the audit to fail? Sometimes we need to use virtual currency in the app. In our app, we can use virtual currency to purchase props, such as gifts in live broadcasts, props in games, etc. Apple takes a commission for virtual currency, and the commission is 30%. So the review is quite strict. First of all, the props you purchased need to be separated on the iOS and Android sides. If you play games, you will find that the game data is separated on both ends. The props purchased by users on Android phones cannot be used on iOS, because this also indirectly affects Apple's revenue. In addition, during the review period, there cannot be any activities or redemption codes that can be redeemed for items that can be purchased on the App Store, which is also not allowed by Apple, because this will also affect Apple's revenue. In addition, some students may hide ipa payment after Apple's review. Here is a reminder that Apple will scan whether there are fields related to Alipay, WeChat, etc. in your app code. Using the switch plus h5 can pass the review, but there are also risks here. The risk is that once it is discovered, the possible result is that Apple will directly block the account and the app cannot be used. 3. How to use dispatch_Group to monitor afn download completion Using dispatch_Group can only control the order of network requests, but it seems impossible to monitor whether the download is complete; but you can monitor in other ways; for example: You can set a bool identifier to YES in the success or failure callback of each network request and send a notification. Listen for notifications on the current page and judge the bool identifiers involved in all network requests in the notification method you listen for. If all are YES, it can be considered that all network requests have been completed and you can perform the operations you want. 4. How to use JSCore on the native iOS side to interact with native iOS In - (void)webViewDidFinishLoad:(UIWebView *)webView
Call this method to call the method in js. Sometimes you may not be able to call the method in js here. The reason may be that the js code and the html code are placed separately. You may not be able to get the code in js at this time. The solution is to get the entire html code first. Add the js path after the html code, and then use the webView loadHtml method to execute the data on the web page. JS calls the method in oc In - (void)webViewDidFinishLoad:(UIWebView *)webView
5. Is it better to store user information in sandbox or userdefault? First of all, NSUserDefaults is in the sandbox. Generally, users don't have many attributes, so encryption + preference or archiving can be used to save them. But now there are so many attributes, it is recommended to use archiving. When using archiving, json to model conversion, etc. are all assisted by third parties, which is very convenient. As for logging in and saving user information, there are many ways:
6. During development, I tried to use KVO to monitor uiwebview.scrollview contentSize to dynamically change the frame of uiwebview so that uiwebview just fills the contentSize. In fact, the effect will lead to an infinite loop, making scrollview.frame larger and larger. The contentSize of scrollView is closely related to bound, and bound is closely related to frame, so it is unreasonable to do so. Workaround
7. When doing a designated driver project, after the user places an order, the driver's status is pushed to the user by Jiguang. If the user prohibits the push function of the app, how should I realize my need to view the driver/order information in real time? There are two ways to solve this problem:
8. How to open Taobao in the app and jump to a specified application? For example, the coupon page Find Taobao's URLScheme and add the specified parameters to the URLScheme. If you have the Taobao app client installed on your local machine, you can jump to the specified page of Taobao. For example, the following URLScheme
How to find such URLSCheme. Write an appDemo in the simulator with the same package name as Taobao, then find a link you need, such as a coupon, click the jump button, and then
This method can be printed out. 9. How to modify the company name displayed on the app after it is launched? Solution:
How to change the company name in the developer account: Log in to Apple developer, find the agent in the developer list in people, and ask the agent to call Apple development department directly: 400-670-1855, change the company name on the developer account or write an email directly from the email address of your registered account: "I need to change the company name" to chinadev@asia.apple.com, and let Apple development department customer service handle it. 10. After iOS packaging is successful, it crashes and displays a black screen when running on iPhone? Regarding the situation where the package cannot be installed or crashes after installation, there are only two possible situations: one is a certificate error, and the other is that the current device is not in the developer's corresponding account. Let's see how to check whether the current device is in the developer's certificate. If you have a developer account, you can get it by logging into the app. But what should we do if we don't have a developer account? Let's take the following ipa package as an example. It must be a hoc or dev package. ipa is actually a compressed file, we can decompress it and get a payload folder. After decompression, click to enter the folder, then display the package contents, and you can see the file list inside We find the corresponding certificate embedded.mobileprovision, which is the signing certificate used in your ipa package. Then open the terminal on the Mac and cd to the path where the certificate is located And enter in the terminal
A file will be generated in the path corresponding to the certificate Open this file with Xcode Here are all the device numbers corresponding to your certificate. at last I find that writing down each interesting problem allows me to learn a lot more easily. In the act of writing down, I think more deeply about what happened. Also, once I write it down, I can review what happened later. Occasionally, I will also skim through the file and read only the lessons learned section to reinforce what I think are the most valuable lessons learned from the problem. That’s all for today’s sharing! If you have gained something or if you like me, you can follow me. I also welcome you to join my iOS discussion group 656315826. I will share all the problems I have recorded, and we can communicate and grow together! |
<<: How to debug Push in one click on iOS
>>: How Big Data Analytics Can Create Better Mobile App User Experiences
1. The world is in dispute, and CPs discuss ranki...
At the beginning of 2023, the Chronic Disease Man...
If you have questions about the coronavirus Espec...
B-side designers will definitely encounter such s...
The factors affecting the quotation of Heyuan Rea...
important This is preliminary documentation for a...
Apple will launch the iPhone 16 at its "It&#...
The Year of the Rabbit is approaching, and rabbit...
The 2021 Pinduoduo side job project group is offi...
Looking back at the first half of 2018, marketing...
This year's Spring Festival travel season wil...
Users' search behaviors vary, and search tend...
01. Introduction " Product Promotion " ...