Specific implementation mode
In order to make the invention's purpose, features and advantages of the invention more obvious and easy to understand, below in conjunction with this hair
Attached drawing in bright embodiment, technical scheme in the embodiment of the invention is clearly and completely described, it is clear that is retouched below
The embodiment stated is only a part of the embodiment of the present invention, and not all embodiment.Based on the embodiments of the present invention, originally
All other embodiment that field those of ordinary skill is obtained without making creative work, belongs to this hair
The range of bright protection.
The embodiment of the present invention provides a kind of high extended network framework of iOS high-performance, as shown in Figure 1 to Figure 3, the iOS high
The high extended network framework of performance includes service network network layers and facilities network network layers.
As shown in Figure 1, the cellular logic of the service network network layers includes for generating basic number of request according to Extended Protocol
According to request before logic, and the request neutron logic of class for receiving basic request data request to create as subclass.
The cellular logic of the facilities network network layers includes being asked for receiving basic request data as parent, generating network
It asks and parent logic in the request initiated, and for server to be parsed and returned according to the data that network request returns
Return parsing after request data or decision request failure request after logic.
In simple terms, the cellular logic of the service network network layers include rely on privately owned component can not multiplexing logical;Example
Such as:
Log system:Permanent reserve daily record, reporting policy related realization.Help records request error.
User information:Elemental user information management logs in state management etc..The basic parameters such as access authentication.
Equipment information management:User equipment information, server-side authentication need partial parameters.
Authentication ciphering:Encryption library is realized by part core developer, completes the logic with server synchronization authentication.
Domain name supervising:All basis domain names in entire App are managed, and handoff functionality is provided facilitates in development process and switch.
Third parties' network library such as YYModel:Operation layer needs to use third party's network library of data model translation;It is excellent
Choosing, third party's network library that the present invention uses is AFNetworking.
The cellular logic of the facilities network network layers includes the reusable logic for relying on third party's network library, specifically includes place
The request of reason basis is initiated and performance, Extended Protocol etc. rely only on the function logic of third party library AFNetworking.After so that
Base-layer network library need to only be adjusted by replacing bottom library.
As shown in Fig. 2, the service network network layers include generator definition module, resolver definition module and request pair
As inheriting generic module,
The generator definition module is for defining an Extended Protocol ' DYRequestMakerProtocol ', definition
Protocol method is as follows:
I. ' RequestMethod ', return value are to enumerate:GET methods, POST method.
II. ' RequestParams ', return value are dictionary:Required parameter.
III. ' RequestUrl ', return value are character string:Ask fullpath.
The Extended Protocol can make the object of this Extended Protocol of realization that will be asked based on complicated service parameter conversion
Data, and then network request is created according to basic request data, logical AND before original network request will be assisted according to the extension
The network request itself that view generates is kept apart by this agreement, is expanded in the case that need not adjust code to realize
Open up the prelogical purpose of network request.
Concrete implementation mode is:It is generator to define a class ' DYRequestMaker ', it then follows
' DYRequestMakerProtocol ' agreement, by calling authentication ciphering, domain name supervising library, user information, facility information etc.
Private database completes requesting method, request path, required parameter based on outside is arbitrarily passed to Parameter Switch.
The resolver definition module is for defining an Extended Protocol ' DYRequestParserProtocol ', definition
Protocol method is as follows:
‘request:parsedResponse:completion:', no return value, first parameter is request object sheet
Body, second parameter are the parameter after parsed by a upper resolver, and third parameter is that a Block is adjusted back, and works as parsing
It calls after the completion, next resolver can be passed to, by defining above-mentioned agreement, to make resolver that independent assortment be supported to insert
Partization extends.
Concrete implementation mode is:Define three classes such as ' DYErrorParser ' be error resolution device,
' DYTokenParser r ' are login state resolver, ' DYModelParser ' is model solution parser, are followed
' DYRequestParserProtocol ' agreement, and the hierarchical relationship between three resolvers is:It is mistake to log in state resolver
Misread lower layer's resolver of parser, model solution parser is the lower layer's resolver for logging in state resolver.
Whether error resolution device is wrong according to the parameter returned after request is received with server commitment logic identification server
Accidentally, if continuing lower layer's resolver (logging in state resolver) without mistake;It logs in state resolver and receives upper layer resolver (i.e.
Error resolution device) parameter passed back, and according to the server commitment logic identification parameter with the presence or absence of logging in state mistake, if
Have, call subscriber information management more new login state, otherwise continues lower layer's resolver (i.e. model solution parser);The model analyzing
Device receives the parameter that upper layer resolver (logging in state resolver) is passed back, and the dictionary that server returns is converted to data mould
Type is simultaneously dished out.
The quantity of the resolver as needed can be with sets itself, and the hierarchical relationship between resolver can also be voluntarily
Setting.
The request object inherits generic module for defining a request object derived class, the request object derived class and
It is inheritance between the network request object class of facilities network network layers, the request object derived class is subclass, and the network is asked
It is parent to seek object class, and therefore, the request object derived class is by calling network request object class class method to ask basis
Data are passed to facilities network network layers and realize network request Object Creation, and register resolver.
Concrete implementation mode is:A request object derived class ' DYRequest ' is defined, the request object is inherited
Class is inherited from the parent in basic network library i.e. network request object class ' DYNetworkRequest ' as subclass, defines class
Method ' requestWithMaker:', as shown in figure 3, passing through DYRequestMakerProtocol ' by this method realization
Agreement takes out requesting method, request path, required parameter, and calls parent method ' requestWithMethod:Url:
Params:' requesting method, request path, required parameter are passed to the establishment of facilities network network layers realization network request object;Wound
The pre-defined error resolution device of default registration, login state resolver, model solution parser, make parsing after establishing network request object
Device is stored in network request object, convenient that the number that these resolvers pass server back can be called after network request
According to being parsed.
As shown in Fig. 2, the facilities network network layers include network request object class definition module, management network request object
Class definition module.
Wherein, the network request object class definition module is for defining a network request object class, the network request
Object class realizes network request Object Creation according to the basic request data in service network network layers, and by managing network request
Object class definition module initiates network request, and will be in the readjustment attribute of incoming readjustment deposit network request abstract class.
Concrete implementation mode is:It is network request object to define a class ' DYNetworkRequest '.Define class side
Method ' requestWithMethod:Url:Params:', requesting method, request path, required parameter are passed to by this method
Facilities network network layers realize the establishment of network request object;Define object method ' sendCompletion:', pass through this method tune
Network request is initiated with the api interface of management network request object class, and the readjustment that external business layer is passed to is stored in generation
Network request object readjustment attribute in;Define object method ' resgisetParser:', it realizes the resolver of registration
It is stored in the parsing attribute of network request object.
The management network request object class definition module is for defining a management network request object class, the management
Network request object class such as initiates network request object, is adjusted back, being cancelled, being parsed at logics management, the concrete implementation mode
It is as follows:
It is management network request object to define a class ' DYNetworkRequestManager ', defines object method
‘sendRequest:', made by this method complete by the api interface of AFNetworking inside the network library of facilities network network layers
Ask basic logic to be built at whole network, to enable management network request object realize to network request object into
The logics management such as row initiation, readjustment, cancellation, parsing.Specifically as shown in figure 3, network request object ' DYNetworkRequest '
The object method of management network request object ' DYNetworkRequestManager ' is called by ' sendCompletion '
‘sendRequest:', realize the initiation of network request, and the network that the readjustment that external business layer is passed to is stored in generation is asked
In the readjustment attribute for seeking object.
When network request is completed, and the data of server return are received, the solution being stored in network request object is called
Parser parses returned data, and the readjustment for calling the external business layer being stored in network request object incoming, will solve
The data that analysis is completed further return to external business layer.
In addition, initializing an asynchronous serial queue in managing network request object class, and network request is started to send out
The process for playing the process actually initiated and data parsing is put into asynchronous serial queue and executes.Wherein, it is practical initiate by
System concurrency is initiated.
The high extended network framework of a kind of iOS high-performance of the present invention, by by network layer be divided into service network network layers and
Facilities network network layers, and by network request be logically divided into before request in logic, the request neutron logic of class, request parent logic and
Logic after request will then by logic before the request for relying on privately owned component and the setting of the request neutron logic of class in service network network layers
Logic setting is in facilities network network layers after relying on parent logic in the request of third party's network library and asking, to external any
Place realizes network request generator logic, realizes to the prelogical extension of network request, while supporting that resolver is free
Combined plug-inization extends, and is placed in sub-line journey and executes with data parsing before also being initiated network request by tandem queue, reaches
The demand of high-performance request.The high extended network framework of a kind of iOS high-performance of the present invention, layering is clear, responsibility is single, property
It can be outstanding and convenient for safeguarding.
A kind of high extended network framework of iOS high-performance is essentially described above, a kind of iOS high-performance height will be expanded below
The implementation method of the exhibition network architecture is described in detail.As shown in figure 4, the realization of the high extended network framework of iOS high-performance
Method includes the following steps:
S1, network request is logically divided into before request in logic, request to logic after logic and request, and further will
Parent logic in the request neutron logic of class, request is logically divided into request;
Logic before request and the request neutron logic of class are arranged in business for S2, setting service network network layers and facilities network network layers
Logic after parent logic in request and request is arranged in facilities network network layers network layer;
S3, in service network network layers, according to generator protocol definition one for will be from the arbitrarily incoming parameter of external business layer
Conversion is the generator class of basic request data, according at least one parsing for registering resolver of resolver protocol definition
Device class defines one and basic request data is passed to facilities network network layers realization network request Object Creation and registers asking for resolver
Seek object derived class;
S4, in facilities network network layers, define one according in service network network layers basic request data realize network request pair
It as the network request object class of establishment, and defines one and builds network request basic logic, and pass through network request basic logic
Complete the management network request object class that network request is initiated.
Wherein, it is inheritance, institute between request object derived class and the network request object class of facilities network network layers
It is subclass to state request object derived class, and the network request object class is parent, and therefore, the request object derived class passes through
It calls network request object class class method that basic request data is passed to facilities network network layers and realizes network request Object Creation, and
Register resolver.
Network request object class calls the object method of management network request object class, realizes the initiation of network request, and
In the readjustment attribute for the network request object that the readjustment that external business layer is passed to is stored in generation.
In addition, the implementation method of the high extended network framework of iOS high-performance includes step S5:
S5, an asynchronous serial queue is initialized in managing network request object class, and network request is started to initiate
The process parsed to the process and data actually initiated, which is put into asynchronous serial queue, to be executed.Wherein, practical to initiate by being
System is concurrently initiated.
Fig. 5 is the signal of the server architecture for the high extended network framework of iOS high-performance that one embodiment of the invention provides
Figure.The server, the equipment to provide the service of calculating, is often referred to, with higher computational power, be supplied to by network multiple
The computer that user uses.As shown in figure 5, the server 6 of the embodiment includes:Memory 61, processor 62 and system are total
Line 63, the memory 61 includes the program 611 run of storage thereon, it will be understood by those skilled in the art that in Fig. 5
The terminal device structure shown does not constitute the restriction to terminal device, may include components more more or fewer than diagram, or
Person combines certain components or different components arrangement.
Each component parts of terminal device is specifically introduced with reference to Fig. 5:
Memory 61 can be used for storing software program and module, and processor 62 is stored in memory 61 by operation
Software program and module, to execute various function application and the data processing of terminal.Memory 61 can include mainly depositing
Store up program area and storage data field, wherein storing program area can storage program area, the application journey needed at least one function
Sequence (such as sound-playing function, image player function etc.) etc.;Storage data field can be stored to be created according to using for terminal
Data (such as audio data, phone directory etc.) etc..It, can be in addition, memory 61 may include high-speed random access memory
Including nonvolatile memory, for example, at least a disk memory, flush memory device or other volatile solid-states
Part.
The implementation method comprising the high extended network framework of iOS high-performance runs program 611, institute on memory 61
Program 611 can be run by, which stating, can be divided into one or more module/units, and one or more of module/units are stored
It is executed in the memory 61, and by processor 62, with the transmission of completion notice and obtains notice realization process, described one
A or multiple module/units can be the series of computation machine program instruction section that can complete specific function, which is used for
Implementation procedure of the computer program 611 in the server 6 is described.For example, the computer program 611 can be by
It is divided into acquisition module, comparing module, concatenation module and sending module.
Processor 62 is the control centre of server, utilizes each of various interfaces and the entire terminal device of connection
Part by running or execute the software program and/or module that are stored in memory 61, and calls and is stored in memory
Data in 61 execute the various functions and processing data of terminal, to carry out integral monitoring to terminal.Optionally, processor
62 may include one or more processing units;Preferably, processor 62 can integrate application processor and modem processor,
Wherein, the main processing operation system of application processor, application program etc., modem processor mainly handles wireless communication.It can
With understanding, above-mentioned modem processor can not also be integrated into processor 62.
System bus 63 is for connection to each functional component of computer-internal, can with data information, address information,
Information is controlled, type can be such as pci bus, isa bus, VESA buses.The instruction of processor 62 is passed by bus
It is handed to memory 61,61 feedback data of memory is responsible for processor 62, system bus 63 between processor 62 and memory 61
Data, instruction interaction.Certain system bus 63 can also access other equipment, such as network interface, display equipment etc..
The server should include at least CPU, chipset, memory, disk system etc., other component parts are herein no longer
It repeats.
In embodiments of the present invention, the program that runs of the execution of processor 62 included by the terminal is specially:It is a kind of
The implementation method of the implementation method of the high extended network framework of iOS high-performance, the high extended network framework of iOS high-performance includes
Following steps:
S1, network request is logically divided into before request in logic, request to logic after logic and request, and further will
Parent logic in the request neutron logic of class, request is logically divided into request;
Logic before request and the request neutron logic of class are arranged in business for S2, setting service network network layers and facilities network network layers
Logic after parent logic in request and request is arranged in facilities network network layers network layer;
S3, in service network network layers, according to generator protocol definition one for will be from the arbitrarily incoming parameter of external business layer
Conversion is the generator class of basic request data, according at least one parsing for registering resolver of resolver protocol definition
Device class defines one and basic request data is passed to facilities network network layers realization network request Object Creation and registers asking for resolver
Seek object derived class;
S4, in facilities network network layers, define one according in service network network layers basic request data realize network request pair
It as the network request object class of establishment, and defines one and builds network request basic logic, and pass through network request basic logic
Complete the management network request object class that network request is initiated;
S5, an asynchronous serial queue is initialized in managing network request object class, and network request is started to initiate
The process parsed to the process and data actually initiated, which is put into asynchronous serial queue, to be executed.Wherein, practical to initiate by being
System is concurrently initiated.
It is apparent to those skilled in the art that for convenience and simplicity of description, foregoing description is
System, the specific work process of device and unit can refer to corresponding processes in the foregoing method embodiment, and details are not described herein.
In the above-described embodiments, it all emphasizes particularly on different fields to the description of each embodiment, is not described in detail or remembers in some embodiment
The part of load may refer to the associated description of other embodiments.
Those of ordinary skill in the art may realize that each embodiments described in conjunction with the examples disclosed in this document
Module, unit and/or method and step, can be come with the combination of electronic hardware or computer software and electronic hardware real
It is existing.These functions are implemented in hardware or software actually, depend on the specific application and design constraint item of technical solution
Part.Professional technician can use different methods to achieve the described function each specific application, but this
Realization should not be considered as beyond the scope of the present invention.
The above, the above embodiments are merely illustrative of the technical solutions of the present invention, rather than its limitations;Although reference
Invention is explained in detail for previous embodiment, it will be understood by those of ordinary skill in the art that:It still can be right
Technical solution recorded in foregoing embodiments is modified or equivalent replacement of some of the technical features;And this
A little modification or replacements, the spirit and model of various embodiments of the present invention technical solution that it does not separate the essence of the corresponding technical solution
It encloses.