Ensure data correctness, completeness and timeliness
Buried point
Code burial point (dead burial point)
- advantages
- Accurate buried point
- You can easily and flexibly customize events and properties
- More business attributes can be obtained
- Can meet highly customized analysis requirements
- disadvantages
- Burial cost is high
- Late maintenance difficulty
All buried point
- advantages
- Burial cost is low
- Page alignment changes do not require adjustment
- disadvantages
- Data related to services cannot be collected
- Cannot meet the refined requirements
- Collected events
- Application startup
- Page views
- Click event
Application state
- Active
- The foreground is active. An application that is running in the foreground and can receive events and
To process. It is also an iOS application at the front desk of the normal mode – UIApplicationDidBecomeActiveNotification notice to implement AppStart events all buried points, so all can trigger AppStart events. Before we solve this problem, we look at another phenomenon: whether it’s cold and move or warm start, the system have sent UIApplicationWillResignActiveNotification notice. Therefore, as long as after receiving UIApplicationDidBecomeActiveNotification notify, sentenced to break before ever received UIApplicationWillResignActiveNotification know, If no, the AppStart event is sent. If yes, the AppStart event is not triggered. This can solve the above problem
- Background
- Enter the background state. When the application is in the background and executable code. big
Most applications will be in front of the suspended briefly into this state – register to monitor UIApplicationDidEnterBackgroundNotification n notice, and then trigger AppEnd events after receiving the notice, Can achieve the effect of full buried point of AppEnd event.
- Suspended
- Suspended state. Refers to an application that enters the background without executing any code
The system automatically moves the application to this state without notifying the application before it does so. When suspended, the application remains in memory, but no code is executed. When the system runs out of memory, the system may clear the pending application without notifying the application, freeing up as many running resources as possible for the foreground application
Browse the event AppViewScreen full buried point
- The timing
- The lifecycle of the UIViewController shows that when the viewDidAppear: method is executed, the view has been rendered on the screen, that is, the page has been displayed and is waiting for the user to take the next step. So, viewDidAppear: The way we do that is we trigger page views
The best time to see events.
- technology
- Method Swizzling, as the name suggests, is a way to swap implementations of two methods. To put it simply, it uses the dynamic binding of objective-C Runtime
Feature that swaps the implementation of one method with the implementation of another.
Control click event AppClick is fully buried
- A target-action design pattern that handles click or drag events under UIKit
- Target-action, also known as target-action mode, calls a specific method on a specific object when an event occurs
- The timing
- Controls in iOS are of the UIControl class or subclasses. When the user manipulates these controls, a message is sent to the specified object Target. There is a method in the UIControl class: **- (void)sendAction:(SEL)action to:(nullable id)target forEvent:(nullable UIEvent)event;*
- technology
- If the control is manipulated by the user (such as a click), this method is first called and the event is forwarded to the application’s UIApplication object. At the same time, There is a similar instance method in UIApplication class **- (BOOL)sendAction:(SEL)action to:(nullable id)target from:(nullable id)sender forEvent:(nullable UIEvent)event;* If the Target object is not nil, the application will have the Target object call the corresponding Action method in response to the event; If the Target object is nil, the application searches the responder chain for the object that defines the method, and then executes the Action method.
- *Parameter – (BOOL)sendAction:(SEL)action to:(nullable id)target from:(nullable id)sender forEvent:(nullable UIEvent)event;
- Action: The corresponding selector for the action method, btnAction in our example.
- Target: The target object, the person in the example. If Target is nil, the application sends the message to the first responder and from the first responder up the response chain until the message is processed.
- Ender: The control that is clicked or dragged by the user, that is, the object that sends the Action message, i.e., the Button in the example.
- Event: a UIEvent object that encapsulates information about the event that was triggered.
- UITableView and UICollectionView click events
- Click on the UITableViewCell and the UICollectionViewCell. And both UITableViewCell and UICollectionViewCell are direct inheritance
From the UIView class, not the UIControl class. Therefore, neither of our previous solutions to implement full burial of the AppClick event is suitable for UITableView or UICollectionView.
- The timing
- If you want to handle clicks on a UITableView, you need to set the Delegate property of the UITableView, And implement UITableViewDelegate protocol – tableView: didSelectRowAtIndexPath: method.
- technology
- Use Method Swizzling to exchange – tableView: didSelectRowAtIndexPath: Method Swizzling for UITableView AppClick
UITableView – setDelegate: Method, and then you can get the delegate object that implements the UITableViewDelegate protocol, and after you get the delegate object, Can the exchange of the delegate object – tableView: didSelectRowAtIndexPath: method, after the trigger AppClick after exchange method
- Collect gesture click events
- When we add one or more target-actions to a gesture recognizer, when we touch the view and the system recognizes the gesture, it sends a message to all Target objects and executes the Action method. although
The gesture recognizer, like the UIControl class, uses the target-Action design pattern, but the gesture recognizer does not send messages to a UIApplication object. Therefore, we cannot use the same processing method as UIControl control, that is, through the way of responder chain to achieve the full buried point of gesture operation
- The timing
- The method of adding target-action to gesture recognizers is the same. The two most common methods are as follows.
- initWithTarget:target action:
- addTarget:action:
- technology
- The two methods are swapped separately using Method Swizzling. We implement the full burial scheme for the gesture AppClick event
Time correlation
- Introduce the systemUpTime. The system startup time, also called startup time, refers to the total number of seconds the device has been running since it was turned on (not counting device sleep) and is not affected by system time changes. Ensure that statistical events are not affected by time
Data Storage Policy
In iOS applications, there are two types of caches in terms of “where is the data cached” :
- Memory cache
- Memory cache is a cache of data in memory that can be read and used directly by a program. Since it is reading and writing memory, the reading and writing speed is extremely fast. However, memory cache
Because memory resources are more efficient, the memory applied by the application in the system will be released as the application life cycle ends. This means that if the application is forced to run by the user or crashes, the data cached in memory may be lost. Therefore, caching event data in memory is not an optimal option.
- Disk cache
- Disk caching, in which data is cached in disk space, is the opposite of memory caching. Disk cache capacity is large, but the read/write speed is lower than that of memory cache
Speak more slowly. However, the disk cache is persistent storage and is not affected by the application life cycle. In general, once data has been successfully saved on disk, the risk of loss is very low. Therefore, all things considered, disk caching is our best choice for caching event data, even though disk caching data reads and writes are slow. In iOS applications, disk caching is typically used in two ways: File caching Database caching (typically in SQLite databases)
Data Synchronization Policy
- Policy 1: Synchronize data when the number of cached events on the client exceeds a certain number (for example, 100).
- Policy 2: The client synchronizes data at a specified interval (for example, every 15 seconds)
- Policy 3: When the application enters the background, it attempts to synchronize all the data that has been cached locally
For iPhone users, it’s customary to press the Home button or swipe up HomeBar to get apps into the background. If we don’t try to synchronize the data at this point, we may lose some data, because the user puts the application in the background and doesn’t know exactly when he or she will start the application again, or even uninstall the application in the next second. Therefore, whenever an application goes into the background, we try to synchronize data to maximize data integrity. As we all know, Apple is very strict about controlling the running of apps in the background. If nothing is done, the app will only have a few seconds to process the data after it enters the background. In such a short period of time, we complete the data synchronization, is completely out of control, there may be some unforeseen consequences. Therefore, we need more background running time. At this point, you can use the UIApplication class – beginBackgroundTaskWithExpirationHandler: method, this method can make the application in the background up to 3 minutes to process the data. That’s more than enough time for us to synchronize data with the network.