Picture resource identification method and related device
By automatically filtering and comparing image resource files and code files in iOS projects, useless image resources are identified, which solves the problem of useless image resources occupying space and extending compilation time in iOS projects, and achieves efficient and accurate resource identification.
Patent Information
- Application Number
- CN202510047263.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-13
- Publication Date
- 2025-02-18
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Due to business logic adjustment, interface reconstruction or functional module deletion in iOS projects, some image resources are no longer used, but they still occupy space and extend the compilation time. The existing manual recognition methods are inefficient and difficult to accurately identify.
By responding to the image resource identification trigger command, the file names that meet the preset image resource file extension requirements are filtered out from the directory structure of the iOS project, and the reference relationship is determined from the code file, and the comparison is made to identify useless image resources.
It realizes automatic recognition of useless image resources in iOS projects. Compared with manual recognition, it is short time, high efficiency, and can achieve accurate recognition.
Smart Images

Figure CN119474029A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of picture recognition, and more particularly to a picture resource recognition method and related devices. Background Art
[0002] Currently, in iOS clients, some image resources need to be introduced into iOS projects, such as icons in apps. However, some image resources may no longer be used due to business logic adjustments, interface reconstruction, or functional module deletion, but they still remain in the iOS project. These useless image resources not only increase the size of the iOS project, causing the project code repository to occupy more space, but also increase the compilation time of the iOS project, thereby reducing development efficiency.
[0003] Existing solutions usually use manual methods to identify useless image resources in iOS projects so that they can be cleaned up later. Manual identification is not only time-consuming and inefficient, but also difficult to accurately identify useless image resources. Summary of the invention
[0004] In view of this, the present invention discloses a picture resource identification method and related devices to realize automatic identification of useless picture resources.
[0005] A method for identifying image resources, comprising:
[0006] In response to the image resource identification trigger instruction, all first image resource file names that meet the preset image resource file extension requirement are screened out from the resource file names under the directory structure of the iOS project to obtain a first array, wherein the preset image resource file extension requirement is the image resource file extension corresponding to the image resource file used in the iOS project;
[0007] Determine, from each code file under the directory structure of the iOS project, a second image resource file name that has a reference relationship with the code file, and obtain a second array;
[0008] Compare each of the first image resource file names in the first array with each of the second image resource file names in the second array, find the target image resource file name that exists in the first array but not in the second array, and determine the image resources corresponding to all of the target image resource file names as identified useless image resources.
[0009] Optionally, in response to the image resource identification trigger instruction, all first image resource file names that meet the preset image resource file extension requirements are screened out from the resource file names under the directory structure of the iOS project to obtain a first array, including:
[0010] In response to the image resource recognition trigger instruction, in the first sub-thread, starting from the root directory of the iOS project, the entire directory structure is traversed recursively;
[0011] Detect the resource file names in each directory and each subdirectory in the traversed directory structure, and filter out all first image resource file names that meet the preset image resource file extension requirements;
[0012] All the first picture resource file names obtained by screening are formed into the first array.
[0013] Optionally, determining, from each code file under the directory structure of the iOS project, a second image resource file name having a reference relationship with the code file to obtain a second array includes:
[0014] In the second child thread, start from the root directory of the iOS project and recursively traverse the entire directory structure;
[0015] Determine a target code string that references a second image resource file name from each code file in the traversed directory structure;
[0016] The second image resource file names referenced by each of the target code character strings are aggregated to obtain the second array.
[0017] Optionally, determining the target code string referencing the second image resource file name from each code file in the traversed directory structure includes:
[0018] A preset regular expression is used as a string matching algorithm to determine the target code string that references the second image resource file name from each of the code files.
[0019] Optionally, the image resource recognition trigger instruction is generated using a scheduled task library of a Python script.
[0020] Optionally, it also includes:
[0021] Aggregate all the identified target image resource file names into a third array;
[0022] The third array is converted into a preset file report and exported.
[0023] Optionally, it also includes:
[0024] The preset file report is sent as an email attachment using a Python script.
[0025] A device for identifying image resources, comprising:
[0026] A resource detection module, configured to respond to a picture resource identification trigger instruction, filter out all first picture resource file names that meet a preset picture resource file extension requirement from the resource file names under the directory structure of the iOS project, and obtain a first array, wherein the preset picture resource file extension requirement is a picture resource file extension corresponding to the picture resource file used in the iOS project;
[0027] A code scanning module, used to determine, from each code file under the directory structure of the iOS project, a second image resource file name that has a reference relationship with the code file, and obtain a second array;
[0028] A difference comparison module is used to compare each of the first image resource file names in the first array with each of the second image resource file names in the second array, find the target image resource file names that exist in the first array but not in the second array, and determine the image resources corresponding to all the target image resource file names as identified useless image resources.
[0029] A computer storage medium stores at least one instruction, and when the at least one instruction is executed by a processor, the above-mentioned image resource identification method is implemented.
[0030] An electronic device, comprising: a memory and a processor;
[0031] The memory is used to store at least one instruction;
[0032] The processor is used to execute the at least one instruction to implement the above-mentioned image resource identification method.
[0033] It can be seen from the above technical scheme that the present invention discloses a method and related device for identifying image resources. In response to an image resource identification trigger instruction, all first image resource file names that meet the preset image resource file extension requirements are screened out from the resource file names under the directory structure of the iOS project to obtain a first array. From each code file under the directory structure of the iOS project, the second image resource file name that has a reference relationship with the code file is determined to obtain a second array. Each first image resource file name in the first array is compared with each second image resource file name in the second array to find the target image resource file name that exists in the first array but not in the second array, and the image resources corresponding to all the target image resource file names are determined as the identified useless image resources. This application compares the first image resource file name corresponding to the image resource file used in the iOS project with the second image resource file name corresponding to the image resource file used in the code file in the iOS project to find the useless image resources in the iOS project, thereby realizing the automatic identification of useless image resources in the iOS project. Compared with manual identification, this application not only takes less time and has higher efficiency, but also can realize the accurate identification of useless image resources. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the disclosed drawings without paying creative work.
[0035] Figure 1 A flow chart of a method for identifying image resources disclosed in an embodiment of the present invention;
[0036] Figure 2 A flow chart of a method for confirming a first array disclosed in an embodiment of the present invention;
[0037] Figure 3 A flow chart of a method for confirming a second array disclosed in an embodiment of the present invention;
[0038] Figure 4 A flowchart of another method for identifying image resources disclosed in an embodiment of the present invention;
[0039] Figure 5 A schematic diagram of the structure of a picture resource identification device disclosed in an embodiment of the present invention;
[0040] Figure 6 The present invention is a schematic diagram of the structure of an electronic device disclosed in an embodiment of the present invention. DETAILED DESCRIPTION
[0041] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0042] The embodiment of the present invention discloses a method and related device for identifying image resources. In response to an image resource identification trigger instruction, all first image resource file names that meet the preset image resource file extension requirements are screened out from the resource file names under the directory structure of the iOS project to obtain a first array. From the various code files under the directory structure of the iOS project, the second image resource file names that have a reference relationship with the code files are determined to obtain a second array. The various first image resource file names in the first array are compared with the various second image resource file names in the second array to find the target image resource file names that exist in the first array but not in the second array, and the image resources corresponding to all the target image resource file names are determined as the identified useless image resources. The present application compares the first image resource file name corresponding to the image resource file used in the iOS project with the second image resource file name corresponding to the image resource file used in the code file in the iOS project to find the useless image resources in the iOS project, thereby realizing the automatic identification of useless image resources in the iOS project. Compared with manual identification, the present application not only takes less time and has higher efficiency, but also can realize the accurate identification of useless image resources.
[0043] See also Figure 1 , a flow chart of a method for identifying image resources disclosed in an embodiment of the present invention, the method may include:
[0044] Step S101, in response to a picture resource identification trigger instruction, all first picture resource file names that meet a preset picture resource file extension requirement are screened out from the resource file names under the directory structure of the iOS project to obtain a first array.
[0045] Among them, the image resource recognition trigger instruction can be generated by using the scheduled task library of Python script.
[0046] Preferably, the scheduled task library may be APScheduler, which is called Advanced Python Scheduler in Chinese. APScheduler is a Python library specifically used for scheduling tasks so that they can be executed at predetermined time intervals or at specific time points.
[0047] A Python script is a program script written in the Python programming language. In this application, it is used to implement automated task processes, including triggering the image resource recognition process according to the set execution time interval of the scheduled task (for example, 2 a.m. every day) or the preset trigger condition (for example, 5 a.m. every Monday).
[0048] In actual applications, a core detection tool ResourcesScanner module can be set up to perform comprehensive scanning and analysis of image resource files in iOS projects to identify useless image resources.
[0049] When the set time of the scheduled task is reached, the Python script calls and starts the ResourcesScanner module to realize the identification process of useless image resources in the iOS project. At the same time, it can record the identification trigger time and related task information to facilitate subsequent log recording and analysis.
[0050] In actual applications, the image resource identification process can be executed in a Mac terminal, and the command line tool set name defined for running in the Mac terminal is: AutoResourceClear.
[0051] The format of setting a scheduled task to send a picture resource recognition trigger instruction is as follows:
[0052] AutoResourceClear config scan-path / Users / username / MyiOSProjectschedule [--interval <interval>] [--time <specific time>]
[0053] scan-path specifies the project path to be scanned, and schedule sets the execution time.
[0054] There are two ways to set the schedule, refer to the following examples:
[0055] auto-resource-clear config scan-path / Users / username / MyiOSProjectschedule --interval 24h, which means setting the scheduled task to execute the image resource recognition process every 24 hours.
[0056] auto-resource-clear config scan-path / Users / username / MyiOSProjectschedule --time "03:00" means that the image resource recognition process is set to be executed at 3 am every day.
[0057] In this embodiment, the preset image resource file extension is required to be the image resource file extension corresponding to the image resource file used in the iOS project, such as png, jpg, webp, imageset, and gif types. That is, this embodiment is to filter out the image resource file names corresponding to the image resource files used in the iOS project. The image resource files used in the iOS project, such as the APP icons or startup images on the mobile terminal.
[0058] The directory structure of an iOS project refers to the layout of project files and organization during the development of an iOS application.
[0059] Step S102: Determine, from each code file under the directory structure of the iOS project, a second image resource file name that has a reference relationship with the code file, and obtain a second array.
[0060] In this embodiment, the second image resource file name that has a reference relationship with the code file is the image resource file name corresponding to the image resource file used in the code file.
[0061] Step S103: compare each of the first image resource file names in the first array with each of the second image resource file names in the second array, find the target image resource file name that exists in the first array but does not exist in the second array, and determine the image resources corresponding to all of the target image resource file names as identified useless image resources.
[0062] In the process of comparing each first image resource file name in the first array with each second image resource file name in the second array, it is necessary to fully consider the size sensitivity of the image resource file name and possible differences in file extensions (for example, the extension may be omitted in the code reference but actually points to a file in a specific format) and other complex factors, and find the target image resource file name that only exists in the first array A but not in the second array B. That is, the image resource corresponding to the target image resource file name only exists in the resource file used in the iOS project corresponding to the first array A, and does not exist in the code file corresponding to the second array B, that is, the image resource corresponding to the target image resource file name is not used in the code file, such as an icon. At this time, it is determined that the image resource corresponding to the target image resource file name is actually a useless image resource, which needs to be cleaned up later.
[0063] In summary, the present application discloses a method for identifying image resources. In response to an image resource identification trigger instruction, all first image resource file names that meet the preset image resource file extension requirements are screened out from the resource file names under the directory structure of the iOS project to obtain a first array. From each code file under the directory structure of the iOS project, the second image resource file name that has a reference relationship with the code file is determined to obtain a second array. Each first image resource file name in the first array is compared with each second image resource file name in the second array to find the target image resource file name that exists in the first array but not in the second array, and the image resources corresponding to all the target image resource file names are determined as the identified useless image resources. The present application compares the first image resource file name corresponding to the image resource file used in the iOS project with the second image resource file name corresponding to the image resource file used in the code file in the iOS project to find the useless image resources in the iOS project, thereby realizing the automatic identification of useless image resources in the iOS project. Compared with manual identification, the present application not only takes less time and has higher efficiency, but also can realize the accurate identification of useless image resources.
[0064] In one embodiment, see Figure 2 , a flowchart of a method for confirming a first array disclosed in an embodiment of the present application, that is, step S101 may specifically include:
[0065] Step S201, in response to the image resource recognition trigger instruction, in the first sub-thread, starting from the root directory of the iOS project, traverse the entire directory structure in a recursive manner.
[0066] In practical applications, the determination process of the first array may be started in an independent sub-thread to avoid affecting UI (User Interface) refresh.
[0067] Before traversing the entire directory structure of the iOS project, a recursive traversal function may be defined. In the first subthread, starting from the root directory of the iOS project, the entire directory structure of the iOS project is gradually traversed recursively based on the recursive traversal function.
[0068] Step S202: Check the resource file names in each directory and each subdirectory in the traversed directory structure, and filter out all first image resource file names that meet the preset image resource file extension requirements.
[0069] The entire directory structure of the iOS project contains multiple directories, each directory may contain multiple subdirectories. This application traverses the resource files under each directory and each subdirectory in the directory structure, filters them according to the preset image resource file extension requirements, obtains the first image resource file name that meets the preset image resource file extension requirements, and saves them in the first array in order.
[0070] Image resource file extensions that meet the preset image resource file extension requirements include but are not limited to png, jpg, webp, imageset, and gif types.
[0071] Step S203: All the first picture resource file names obtained by screening are formed into a first array.
[0072] Based on the above discussion, it can be seen that this embodiment actually filters out the picture resource file names corresponding to the picture resource files used in the iOS project from the various picture resource files corresponding to the entire directory structure of the iOS project.
[0073] In one embodiment, see Figure 3 , a flowchart of a method for confirming a second array disclosed in an embodiment of the present application, that is, step S102 may specifically include:
[0074] Step S301: In the second sub-thread, starting from the root directory of the iOS project, traverse the entire directory structure recursively.
[0075] It should be noted that the “second” in the second sub-thread and the “first” in the first sub-thread are only used to distinguish the two sub-threads, and do not indicate any actual relationship or order between the first sub-thread and the second sub-thread.
[0076] In order to ensure that the normal display of the UI is not disturbed, this embodiment starts from the root directory of the iOS project and recursively traverses the entire directory structure of the iOS project based on a preset recursive traversal function to locate the code files. The types of the located code files include but are not limited to .h, .m, .swift, .xib, .storeboard, .cpp, .html, .js and other file types.
[0077] Step S302: Determine a target code string that references a second image resource file name from each code file in the traversed directory structure.
[0078] Herein, a preset regular expression may be used as a string matching algorithm to determine a target code string that references the second image resource file name from each code file.
[0079] Specifically, when locating the code file under the directory structure, the code file is first read, and the preset regular expression is used as the string matching algorithm, taking into full account various possible image resource reference methods in different languages (such as Objective-C, Swift, etc.) in the iOS code. For example, for the statement that loads the image resource in the .m file, regular expressions such as @"@"(.?)"", @"imageNamed:@"(.+)"" or (imageNamed|contentOfFile):@"(.)" are used for matching, accurately extracting the image resource file names actually referenced in the code, and storing these file names one by one in the second array to determine the actual usage of resources at the code level.
[0080] Step S303: Aggregate the second image resource file names referenced by the target code character strings to obtain the second array.
[0081] Based on the above discussion, it can be seen that this embodiment actually filters out the picture resource file names corresponding to the picture resource files used by the code files in the iOS project from the various picture resource files corresponding to the entire directory structure of the iOS project.
[0082] In one embodiment, see Figure 4 , another picture resource identification method flow chart disclosed in an embodiment of the present invention, in Figure 1 Based on the embodiment shown, the following may also be included:
[0083] Step S104: Aggregate all the identified target image resource file names into a third array.
[0084] After the resource detection process shown in step S102 and the code scanning process shown in step S103 are completed, in an independent third sub-thread, the differences of each first image resource file name in the first array and each second image resource file name in the second array are compared to find the target image resource file name that exists in the first array but not in the second array. The image resource file corresponding to the target image resource file name is also the useless image resource in the iOS project.
[0085] Step S105: convert the third array into a preset file report and export it.
[0086] Preferably, the preset file report may be a plist file report, which records relevant information of useless image resources to facilitate subsequent developers to view and analyze.
[0087] The "plist" in the plist file report is the abbreviation of Property List. Property List file is a file used to store serialized objects and is commonly used in iOS development. In this embodiment, the third array is preferentially converted into a plist file report and exported.
[0088] In one embodiment, after step S105, the following steps may also be included:
[0089] Step S106: Use the Python script to send the preset file report as an email attachment.
[0090] In actual applications, this application gives priority to using the Python script scheduled task function to automatically trigger the ResourcesScanner module to execute the image resource identification process every day. After the image resource identification is completed, the plist file report is sent as an email attachment to the development team email group through the Python script, so that the development team members can know the useless image resources in time and take corresponding measures to ensure the good management of iOS project resources and project performance, and improve the efficiency of iOS project development.
[0091] In this embodiment, after generating the preset file report, the email sending library (such as smtplib library) of the Python script is used to prepare for email sending. First, read the key information in the system configuration file, including the mail server address, port number, sender email address, sender email password, and development team email group address. Then create an email object, reasonably set the email subject (such as "iOS project useless image resource file detection results-[date]") and the body content (briefly describe the detection situation and attachment content), and add the preset file report as an email attachment to the email object. Finally, through the connection and authentication with the mail server, send the email according to the SMTP protocol. It should be noted that it is necessary to properly handle possible network anomalies, mail server connection failures, etc. during the sending process to ensure that the email can be successfully sent to the development team's email group, and record the email sending log (including sending time, recipient address, email subject, etc.) to facilitate subsequent query and tracing.
[0092] Preferably, the smtplib library can be used to read key information in the system configuration file, create an email object and set the subject and body, add a preset file report as an attachment, connect to the authenticated mail server, and use the SMTP (Simple Mail Transfer Protocol) protocol to send the email.
[0093] Corresponding to the above method embodiment, the present application also discloses a picture resource identification device.
[0094] See also Figure 5 , a schematic diagram of the structure of a picture resource identification device disclosed in an embodiment of the present application, the device may include:
[0095] The resource detection module 401 is used to respond to the image resource identification trigger instruction, filter out all first image resource file names that meet the preset image resource file extension requirements from the resource file names under the directory structure of the iOS project, and obtain a first array.
[0096] Among them, the image resource recognition trigger instruction can be generated by using the scheduled task library of Python script.
[0097] In actual applications, a core detection tool ResourcesScanner module can be set to perform a comprehensive scan and analysis of image resource files in iOS projects to identify useless image resources.
[0098] The ResourcesScanner module includes key components such as FileDetection (resource detection module), CodeScanner (code scanning module) and DiffManager (difference comparison module) to identify useless image resources.
[0099] When the set time of the scheduled task is reached, the Python script calls and starts the ResourcesScanner module to realize the identification process of useless image resources in the iOS project. At the same time, it can record the identification trigger time and related task information to facilitate subsequent log recording and analysis.
[0100] Among them, the preset image resource file extension is required to be the image resource file extension corresponding to the image resource file used in the iOS project.
[0101] The code scanning module 402 is used to determine the second image resource file name that has a reference relationship with the code file from each code file under the directory structure of the iOS project, and obtain a second array.
[0102] In this embodiment, the second image resource file name that has a reference relationship with the code file is the image resource file name corresponding to the image resource file used in the code file.
[0103] The difference comparison module 403 is used to compare each of the first image resource file names in the first array with each of the second image resource file names in the second array, find the target image resource file name that exists in the first array but does not exist in the second array, and determine the image resources corresponding to all the target image resource file names as identified useless image resources.
[0104] In the process of comparing each first image resource file name in the first array with each second image resource file name in the second array, it is necessary to fully consider the size sensitivity of the image resource file name and possible differences in file extensions (for example, the extension may be omitted in the code reference but actually points to a file in a specific format) and other complex factors, and find the target image resource file name that only exists in the first array A but not in the second array B. That is, the image resource corresponding to the target image resource file name only exists in the resource file used in the iOS project corresponding to the first array A, and does not exist in the code file corresponding to the second array B, that is, the image resource corresponding to the target image resource file name is not used in the code file, such as an icon. At this time, it is determined that the image resource corresponding to the target image resource file name is actually a useless image resource, which needs to be cleaned up later.
[0105] In summary, the present application discloses a picture resource identification device, which responds to a picture resource identification trigger instruction, selects all first picture resource file names that meet the preset picture resource file extension requirements from the resource file names under the directory structure of the iOS project to obtain a first array, determines the second picture resource file names that have a reference relationship with the code files from the various code files under the directory structure of the iOS project to obtain a second array, compares each first picture resource file name in the first array with each second picture resource file name in the second array, finds the target picture resource file name that exists in the first array but does not exist in the second array, and determines the picture resources corresponding to all the target picture resource file names as the identified useless picture resources. The present application compares the first picture resource file name corresponding to the picture resource file used in the iOS project with the second picture resource file name corresponding to the picture resource file used in the code file in the iOS project, finds the useless picture resources in the iOS project, and realizes the automatic identification of useless picture resources in the iOS project. Compared with manual identification, the present application not only takes less time and has higher efficiency, but also can realize the accurate identification of useless picture resources.
[0106] In one embodiment, the resource detection module 401 may be specifically used for:
[0107] In response to the image resource recognition trigger instruction, in the first sub-thread, starting from the root directory of the iOS project, the entire directory structure is traversed recursively;
[0108] Detect the resource file names in each directory and each subdirectory in the traversed directory structure, and filter out all first image resource file names that meet the preset image resource file extension requirements;
[0109] All the first picture resource file names obtained by screening are formed into the first array.
[0110] In one embodiment, the code scanning module 402 may be specifically used for:
[0111] In the second child thread, start from the root directory of the iOS project and recursively traverse the entire directory structure;
[0112] Determine a target code string that references a second image resource file name from each code file in the traversed directory structure;
[0113] The second image resource file names referenced by each of the target code character strings are aggregated to obtain the second array.
[0114] In one embodiment, the code scanning module 402 may also be used to:
[0115] A preset regular expression is used as a string matching algorithm to determine the target code string that references the second image resource file name from each of the code files.
[0116] In one embodiment, the image resource identification device may further include:
[0117] A summarizing module, used for summarizing all the identified target image resource file names into a third array;
[0118] The report export module is used to convert the third array into a preset file report and export it.
[0119] Preferably, the preset file report may be a plist file report.
[0120] In one embodiment, the image resource identification device may further include:
[0121] The mail sending module is used to send the preset file report as an email attachment using a Python script.
[0122] It should be noted that for the specific working principles of each component in the device embodiment, please refer to the corresponding part of the method embodiment, which will not be repeated here.
[0123] Corresponding to the above embodiment, the present application further discloses a computer storage medium, which stores at least one instruction, and when the at least one instruction is executed by a processor, the steps shown in the embodiment of the image resource identification method are implemented.
[0124] Computer storage media may be tangible media that may contain or store programs for use by or in conjunction with an instruction execution system, device, or apparatus. Computer storage media may be machine-readable signal media or machine-readable storage media. Computer storage media may include, but are not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media may include electrical connections based on one or more lines, portable computer disks, hard disks, random access memories (RAM), read-only memories (ROM), erasable programmable read-only memories (EPROM or flash memory), optical fibers, portable compact disk read-only memories (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0125] Corresponding to the above embodiment, Figure 6 As shown, the present invention also provides an electronic device, which may include: a processor 1 and a memory 2;
[0126] The processor 1 and the memory 2 communicate with each other via a communication bus 3;
[0127] Processor 1, configured to execute at least one instruction;
[0128] Memory 2, used to store at least one instruction;
[0129] The processor 1 may be a central processing unit (CPU), or an application specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present invention.
[0130] The memory 2 may include a high-speed RAM memory, and may also include a non-volatile memory (non-volatile memory), such as at least one disk memory.
[0131] The processor executes at least one instruction to implement the steps shown in the embodiment of the image resource identification method.
[0132] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0133] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0134] The above description of the disclosed embodiments enables one skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for identifying image resources, characterized in that: include: In response to the image resource identification trigger instruction, all first image resource file names that meet the preset image resource file extension requirement are screened out from the resource file names under the directory structure of the iOS project to obtain a first array, wherein the preset image resource file extension requirement is the image resource file extension corresponding to the image resource file used in the iOS project; Determine, from each code file under the directory structure of the iOS project, a second image resource file name that has a reference relationship with the code file, and obtain a second array; Compare each of the first image resource file names in the first array with each of the second image resource file names in the second array, find the target image resource file name that exists in the first array but not in the second array, and determine the image resources corresponding to all of the target image resource file names as identified useless image resources.
2. The image resource identification method according to claim 1, characterized in that: In response to the image resource identification trigger instruction, all first image resource file names that meet the preset image resource file extension requirements are screened out from the resource file names under the directory structure of the iOS project to obtain a first array, including: In response to the image resource recognition trigger instruction, in the first sub-thread, starting from the root directory of the iOS project, the entire directory structure is traversed recursively; Detect the resource file names in each directory and each subdirectory in the traversed directory structure, and filter out all first image resource file names that meet the preset image resource file extension requirements; All the first picture resource file names obtained by screening are formed into the first array.
3. The image resource identification method according to claim 1, characterized in that: The second image resource file name having a reference relationship with the code file is determined from each code file under the directory structure of the iOS project to obtain a second array, including: In the second child thread, start from the root directory of the iOS project and recursively traverse the entire directory structure; Determine a target code string that references a second image resource file name from each code file in the traversed directory structure; The second image resource file names referenced by each of the target code character strings are aggregated to obtain the second array.
4. The image resource identification method according to claim 3, characterized in that: Determining the target code string that references the second image resource file name from each code file under the traversed directory structure includes: A preset regular expression is used as a string matching algorithm to determine the target code string that references the second image resource file name from each of the code files.
5. The image resource identification method according to claim 1, characterized in that: The image resource recognition trigger instruction is generated using a scheduled task library of a Python script.
6. The image resource identification method according to claim 1, characterized in that: Also includes: Aggregate all the identified target image resource file names into a third array; The third array is converted into a preset file report and exported.
7. The image resource identification method according to claim 6, characterized in that: Also includes: The preset file report is sent as an email attachment using a Python script.
8. A device for identifying image resources, characterized in that: include: A resource detection module, configured to respond to a picture resource identification trigger instruction, filter out all first picture resource file names that meet a preset picture resource file extension requirement from the resource file names under the directory structure of the iOS project, and obtain a first array, wherein the preset picture resource file extension requirement is a picture resource file extension corresponding to the picture resource file used in the iOS project; A code scanning module, used to determine, from each code file under the directory structure of the iOS project, a second image resource file name that has a reference relationship with the code file, and obtain a second array; A difference comparison module is used to compare each of the first image resource file names in the first array with each of the second image resource file names in the second array, find the target image resource file names that exist in the first array but not in the second array, and determine the image resources corresponding to all the target image resource file names as identified useless image resources.
9. A computer storage medium, characterized in that: The computer storage medium stores at least one instruction, and when the at least one instruction is executed by the processor, the image resource identification method according to any one of claims 1 to 7 is implemented.
10. An electronic device, characterized in that: The electronic device comprises: a memory and a processor; The memory is used to store at least one instruction; The processor is used to execute the at least one instruction to implement the image resource identification method as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Method and device for removing useless picture resources in APK (Android Package)
CN106708565A
Method and device for determining useless pictures, electronic equipment and storage medium
CN111221992A
Method for reducing volume of IPA packet
CN112114867A
Redundant resource deletion method and device and computer readable storage medium
CN115145572A
Method and system for screening useless picture resources at front end
CN115268928A
Cited By
Redundant file deletion method and system, electronic equipment and storage medium
CN121349981A