CN115495327A - Method for realizing countdown on iOS system - Google Patents

Method for realizing countdown on iOS system Download PDF

Info

Publication number
CN115495327A
CN115495327A CN202211139016.1A CN202211139016A CN115495327A CN 115495327 A CN115495327 A CN 115495327A CN 202211139016 A CN202211139016 A CN 202211139016A CN 115495327 A CN115495327 A CN 115495327A
Authority
CN
China
Prior art keywords
countdown
application program
time
ios system
background
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211139016.1A
Other languages
Chinese (zh)
Inventor
颜进旭
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
4399 NETWORK CO LTD
Original Assignee
4399 NETWORK CO LTD
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 4399 NETWORK CO LTD filed Critical 4399 NETWORK CO LTD
Priority to CN202211139016.1A priority Critical patent/CN115495327A/en
Publication of CN115495327A publication Critical patent/CN115495327A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/34Recording or statistical evaluation of computer activity, e.g. of down time, of input/output operation ; Recording or statistical evaluation of user activity, e.g. usability assessment
    • G06F11/3409Recording or statistical evaluation of computer activity, e.g. of down time, of input/output operation ; Recording or statistical evaluation of user activity, e.g. usability assessment for performance assessment
    • G06F11/3419Recording or statistical evaluation of computer activity, e.g. of down time, of input/output operation ; Recording or statistical evaluation of user activity, e.g. usability assessment for performance assessment by assessing time
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/3003Monitoring arrangements specially adapted to the computing system or computing system component being monitored
    • G06F11/302Monitoring arrangements specially adapted to the computing system or computing system component being monitored where the computing system component is a software system
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/3051Monitoring arrangements for monitoring the configuration of the computing system or of the computing system component, e.g. monitoring the presence of processing resources, peripherals, I/O links, software programs
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/448Execution paradigms, e.g. implementations of programming paradigms
    • G06F9/4482Procedural
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4843Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
    • G06F9/485Task life-cycle, e.g. stopping, restarting, resuming execution

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Software Systems (AREA)
  • Quality & Reliability (AREA)
  • Computing Systems (AREA)
  • Computer Hardware Design (AREA)
  • Mathematical Physics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The invention provides a method for realizing countdown on an iOS system, which comprises the following steps: when the countdown page of the application program starts the countdown function, a timer is synchronously started to start countdown and a monitoring module monitors; if the application program is monitored to enter the background from the foreground, the timer is paused, and the current running time upTime1 of the iOS system is obtained; and if the application program enters the foreground from the background, acquiring the current running time upTime2 of the iOS system, subtracting the current running time upTime2 of the iOS system from the current running time upTime1 of the iOS system to obtain the retention time of the background of the application program, and correcting the countdown residual time. The invention corrects the countdown remaining time by calculating the staying time of the application program in the background, and solves the problem of inaccurate timing caused by the hanging of the timer after the application program enters the background; the algorithm is simple, the effect is good, and the adaptable service scene is wide.

Description

Method for realizing countdown on iOS system
Technical Field
The invention belongs to the technical field of mobile terminals, and particularly relates to a method for realizing countdown on an iOS system.
Background
With the rapid development of the mobile internet technology, various types of application software are increasing. In the process of developing the application software APP, countdown is often needed, for example, in the process of logging in and registering the application software by a user, countdown of a verification code is obtained; the order payment countdown in the e-commerce or take-away APP, the commodity second killing countdown, the commodity limited purchase countdown and the like, and therefore various operation activities often need to use the countdown. However, due to the mechanism of the iOS system, when the application software in the foreground is backed up to the background, the application software will enter a Suspend state after running for a short time in the background state, at this time, the application software will not execute any code any more, the timer will be suspended, and the timer will resume running after the application software returns to the foreground state, thereby causing inaccurate countdown time and affecting the corresponding countdown service function.
To solve the above problems, the currently used methods include the following two methods:
1. when the application enters the background, the UIapplication's-beginBackgrountTaskWithExpirationHandler: creating a background task for the application requires an additional background runtime. This method has the following disadvantages: the extra running time of the background obtained by the method is very limited, about 30 seconds, and after the extra running time exceeds the time allowed by the system, the system still stops running the program, and the requirement of countdown for a long time cannot be met.
2. Playing a section of soundless music in a background circulation manner for simulating the background running authority of the audio application to keep the program running in the background for a long time. This method has the following disadvantages: the method has certain risk that the shelf-on audit of App Store market is rejected; and when the user switches to use other audio applications to play music, the system also stops playing background music, so that the program loses background running permission and the problem of inaccurate countdown still occurs.
Disclosure of Invention
Aiming at the defects in the prior art, the invention provides a method for realizing countdown on an iOS system, which can effectively solve the problems.
The technical scheme adopted by the invention is as follows:
the invention provides a method for realizing countdown on an iOS system, which comprises the following steps:
step 1, registering a monitoring event that an application program enters a foreground from a background and a monitoring event that the application program enters the background from a foreground in a countdown page of the application program for each application program with a countdown function configured in an iOS system;
step 2, when the countdown page of the application program starts a countdown function, a timer is synchronously started to start countdown and a monitoring module monitors;
therefore, in the process of counting down by the timer, the application program is in a foreground running state at the moment, the monitoring module monitors whether a monitoring event that the application program enters a background from the foreground occurs, and if the monitoring event does not occur, when the counting down is finished by the timer, the step 3 is executed; if a monitoring event that the application program enters the background from the foreground is monitored, the following operation A1 and operation A2 are synchronously executed:
operation A1: pausing the timer to obtain countdown remaining time remaintime1 obtained by current timing;
operation A2: acquiring the current running time upTime1 of the iOS system;
then, the monitoring module monitors whether a monitoring event that the application program enters the foreground from the background occurs, and if the monitoring event that the application program enters the foreground from the background is monitored, the following operation B1 is executed:
operation B1: acquiring the current running time upTime2 of the iOS system; subtracting the current running time upTime2 of the iOS system from the current running time upTime1 of the iOS system to obtain the background stay time staytime of the application program; subtracting the countdown residual time remaintime1 from the application program background staying time staytime to obtain the latest countdown residual time remaintime2, correcting the timer by adopting the latest countdown residual time remaintime2 as the countdown residual time, recovering the timer, continuing to count down and time, and meanwhile, continuing to monitor by adopting the monitoring module, namely: returning to the step 2;
and step 3, stopping the monitoring module.
Preferably, the following method is adopted to obtain the current running time upTime1 of the iOS system:
calling a syscltl () function to obtain a Unix timestamp when the iOS system kernel is started, and marking as a timestamp boottime;
calling a gettimeoffday () function to obtain a current Unix timestamp of an iOS system kernel, and recording the current Unix timestamp as a timestamp now;
and subtracting the timestamp now from the timestamp boottime to obtain the current running time upTime1 of the iOS system.
The method for realizing countdown on the iOS system provided by the invention has the following advantages that:
the invention corrects the countdown remaining time by calculating the staying time of the application program in the background, and solves the problem of inaccurate timing caused by the hanging of the timer after the application program enters the background; the algorithm is simple, the effect is good, and the adaptable service scene is wide.
Drawings
Fig. 1 is a schematic flowchart of a method for implementing countdown on an iOS system according to the present invention.
Detailed Description
In order to make the technical problems, technical solutions and advantageous effects solved by the present invention more clearly apparent, the present invention is further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
The invention provides a method for realizing countdown on an iOS system, which is characterized in that when countdown is used on the iOS system, when an application program enters a background from a foreground and enters a foreground from the background, the current system running time is respectively recorded, the time difference between two records is calculated to obtain the staying time of the application program on the background, then the current countdown remaining time is subtracted from the staying time of the background to obtain the correct countdown remaining time, and therefore, the problem of inaccurate timing caused by the fact that the application program enters the background and is suspended by the system is corrected.
Referring to fig. 1, the present invention provides a method for implementing countdown on an iOS system, comprising the steps of:
step 1, registering a monitoring event of the application program entering a foreground from a background and a monitoring event of the application program entering the background from a foreground in a countdown page of the application program for each application program with a countdown function configured in an iOS system;
step 2, when the countdown page of the application program starts a countdown function, a timer is synchronously started to start countdown and a monitoring module monitors;
that is, in the present invention, the start action of the timer and the start action of the monitoring module are controlled in a linkage manner, and when the timer is started, the monitoring module is started at the same time.
Therefore, in the process of counting down by the timer, the application program is in a foreground running state at the moment, the monitoring module monitors whether a monitoring event that the application program enters a background from the foreground occurs, and if the monitoring event does not occur, when the counting down is finished by the timer, the step 3 is executed; if a monitoring event that the application program enters the background from the foreground is monitored, the following operation A1 and operation A2 are synchronously executed:
operation A1: pausing the timer to obtain countdown remaining time remaintime1 obtained by current timing;
operation A2: acquiring the current running time upTime1 of the iOS system;
then, the monitoring module monitors whether a monitoring event that the application program enters the foreground from the background occurs, and if the monitoring event that the application program enters the foreground from the background is monitored, the following operation B1 is executed:
operation B1: acquiring the current running time upTime2 of the iOS system; subtracting the current running time upTime2 of the iOS system from the current running time upTime1 of the iOS system to obtain the background stay time staytime of the application program; subtracting the countdown remaining time remaintime1 from the background staying time staytime of the application program to obtain the latest countdown remaining time remaintime2, correcting the timer by adopting the latest countdown remaining time remaintime2 as the countdown remaining time, recovering the timer, continuing to perform countdown operation, and meanwhile, continuing to monitor by adopting the monitoring module, namely: returning to the step 2;
and step 3, stopping the monitoring module.
In the invention, for accurately obtaining the current running time upTime1 and upTime2 of the iOS system, taking the current running time upTime1 of the iOS system as an example, the current running time upTime1 of the iOS system can be obtained by adopting the following modes:
calling a syscltl () function to obtain a Unix timestamp when the iOS system kernel is started, and recording the Unix timestamp as a timestamp boottime;
calling a gettimeoffday () function to obtain a current Unix timestamp of an iOS system kernel, and recording the current Unix timestamp as a timestamp now;
and subtracting the timestamp now from the timestamp boottime to obtain the current running time upTime1 of the iOS system.
The principle for obtaining the current running time upTime2 of the iOS system is the same as that of the current running time upTime1 of the iOS system, and is not described herein again.
The reason for obtaining the current running time of the iOS system by adopting the method is as follows:
since the NSDate is time controlled by the handset system, that is, when the user modifies the time display of the device, the output of the time acquired by the NSDate will also change. The time obtained by NSDate is not reliable because the user may modify the system time to change its value, which may affect the calculation of the application background sleep time; an absolute, always increasing linear time value needs to be found to record the background dwell time.
There is a layer of core system in the iOS system architecture called Darwin. While the kernel of Darwin is XNU (XNU is an acronym for X is Not Unix). XUN is a hybrid core, combining the components of the Mach core and FreeBSD. The FreeBSD layer ensures the UNIX property of the Darwin system, and therefore, standard UNIX functions can be called in the iOS system to obtain detailed information of the operating system about hardware and kernel, such as memory size, kernel boot time, and the like. Therefore, the present invention queries the kernel boot time by calling the syscll () function, gettimeoffset () function to obtain the current time. The values obtained by the two functions gettimeoffday () and sysctl () are Unix timestamps (the Unix timestamps (Unix time) are time representation modes used by Unix or Unix-like systems, and are total seconds from 0 min 0 s to the present from 1 month, 1 day, 0 h and 1970 of UTC), so that the two values can be subtracted to obtain a difference value, the difference value is used as the number of seconds passed by the current device since the system kernel is started, namely the system running time is a lost time instead of a certain time point, and therefore, the influence of a user on system date change and device dormancy behavior is avoided, and the program background residence time can be accurately calculated through the value.
The invention provides a method for realizing countdown on an iOS system, which has the following advantages:
(1) The remaining time of countdown is corrected by calculating the staying time of the application program in the background, so that the problem of inaccurate timing caused by hanging a timer after the application program enters the background is solved; the algorithm is simple, the effect is good, and the adaptable service scene is wide.
(2) The application program background stay time is calculated by using the running time of the system, so that the influence of the user on the calculation of the program background stay time caused by modifying the system time is avoided; the accuracy of calculating the retention time of the background is ensured.
(3) And an API method conforming to an App Store auditing mechanism is used, so that the problem that auditing is rejected when the App Store is put on shelf is avoided.
The foregoing is only a preferred embodiment of the present invention, and it should be noted that, for those skilled in the art, various modifications and improvements can be made without departing from the principle of the present invention, and such modifications and improvements should also be considered within the scope of the present invention.

Claims (2)

1. A method for implementing countdown on an iOS system, comprising the steps of:
step 1, registering a monitoring event that an application program enters a foreground from a background and a monitoring event that the application program enters the background from a foreground in a countdown page of the application program for each application program with a countdown function configured in an iOS system;
step 2, when the countdown page of the application program starts a countdown function, a timer is synchronously started to start countdown and a monitoring module monitors;
therefore, in the process of counting down by the timer, the application program is in a foreground running state at the moment, the monitoring module monitors whether a monitoring event that the application program enters a background from the foreground occurs, and if the monitoring event does not occur, when the counting down is finished by the timer, the step 3 is executed; if a monitoring event that the application program enters the background from the foreground is monitored, the following operation A1 and operation A2 are synchronously executed:
operation A1: pausing the timer to obtain countdown remaining time remaintime1 obtained by current timing;
operation A2: acquiring the current running time upTime1 of the iOS system;
then, the monitoring module monitors whether a monitoring event that the application program enters the foreground from the background occurs, and if the monitoring event that the application program enters the foreground from the background is monitored, the following operation B1 is executed:
operation B1: acquiring the current running time upTime2 of the iOS system; subtracting the current running time upTime2 of the iOS system from the current running time upTime1 of the iOS system to obtain the background stay time staytime of the application program; subtracting the countdown residual time remaintime1 from the application program background staying time staytime to obtain the latest countdown residual time remaintime2, correcting the timer by adopting the latest countdown residual time remaintime2 as the countdown residual time, recovering the timer, continuing to count down and time, and meanwhile, continuing to monitor by adopting the monitoring module, namely: returning to the step 2;
and step 3, stopping the monitoring module.
2. The method for implementing countdown on the iOS system of claim 1, wherein the following method is used to obtain the current running time upTime1 of the iOS system:
calling a syscltl () function to obtain a Unix timestamp when the iOS system kernel is started, and recording the Unix timestamp as a timestamp boottime;
calling a gettimeoffday () function to obtain a current Unix timestamp of an iOS system kernel, and recording the current Unix timestamp as a timestamp now;
and subtracting the timestamp now from the timestamp boottime to obtain the current running time upTime1 of the iOS system.
CN202211139016.1A 2022-09-19 2022-09-19 Method for realizing countdown on iOS system Pending CN115495327A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211139016.1A CN115495327A (en) 2022-09-19 2022-09-19 Method for realizing countdown on iOS system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211139016.1A CN115495327A (en) 2022-09-19 2022-09-19 Method for realizing countdown on iOS system

Publications (1)

Publication Number Publication Date
CN115495327A true CN115495327A (en) 2022-12-20

Family

ID=84469788

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211139016.1A Pending CN115495327A (en) 2022-09-19 2022-09-19 Method for realizing countdown on iOS system

Country Status (1)

Country Link
CN (1) CN115495327A (en)

Similar Documents

Publication Publication Date Title
US7453910B1 (en) Synchronization of independent clocks
CN110795311B (en) Event playback method and device
CN110019502B (en) Synchronization method between primary database and backup database, database system and device
WO2017209508A1 (en) Electronic device and file data journaling method of electronic device
US11615443B2 (en) System and method to selectively update supplemental content rendered in placement regions of a rendered page
US10108474B2 (en) Trace capture of successfully completed transactions for trace debugging of failed transactions
CN109976966A (en) A kind of application program launching time counting method, apparatus and system
CN106775620B (en) Timing method and device
CN113865620B (en) Time synchronization method and device for AR navigation simulation
CN111339158A (en) Method and device for processing information, electronic equipment and storage medium
CN115495327A (en) Method for realizing countdown on iOS system
CN106856496B (en) Data processing method and device
CN108243029B (en) Method for restoring generation time of log, client and server
CN112732370B (en) Business process adjustment method and device
CN106534075A (en) Updated content processing method and device
US10496467B1 (en) Monitoring software computations of arbitrary length and duration
US20100268993A1 (en) Disablement of an exception generating operation of a client system
CN112435029B (en) Service processing method and device based on block chain and electronic equipment
CN110689429B (en) Method, device and system for storing certificate transaction data
CN106375354B (en) Data processing method and device
EP4340373A1 (en) Video processing method and apparatus, and device and storage medium
CN111858175A (en) Method and equipment for backing up cloud platform data based on mobile storage device
US11714737B2 (en) Time clock quality determination
CN114040143B (en) Method, system and equipment for IPTV service management
CN112699015B (en) Log output method, device, server and computer readable storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination