Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to analyze the basic idea of iOS containerization Framework

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

In this issue, Xiaobian will bring you the basic analysis of how to carry out the iOS containerization framework. The article is rich in content and analyzed and described from a professional perspective. After reading this article, I hope you can gain something.

preface

Starting from this chapter, we will start with the architecture design scheme of Alipay client, subdivide and disassemble the specific implementation of client in "containerized framework design,""network optimization,""performance startup optimization,""automatic log collection,""RPC component design,""mobile application monitoring, diagnosis, positioning," etc., and lead you to further understand the iteration and optimization process of Alipay client architecture.

The following will introduce the basic ideas of Alipay iOS containerization framework design.

Overview of containerization implementation

In the introduction of mPaaS, we have already shared the Practice of Modular and Decoupled Development in Ant Financial Services mPaaS: separating the business into relatively independent modules through the containerized development framework, and striving for high cohesion and low coupling between modules, so we have realized flexible plug-in development and divided the business into thousands of independent projects.

mPaaS iOS framework originated from Alipay client, in order to achieve this kind of low coupling between thousands of projects and related dependent calls, mPaaS framework directly took over the life cycle of the App, responsible for the entire App launch hosting, App life cycle management, handling and distribution of UIApplication proxy events.

The mPaaS framework provides a containerized environment in which business developers use microapplications and services to develop specific business requirements.

Micro-applications and services are concepts defined within the mPaaS framework, primarily for partitioning between business modules. The mPaaS framework divides different business modules into microapplications and services according to whether there is a UI interface as a standard. A microapplication is a business module with a user interface during APP runtime; a service is a lightweight abstract service provided by the business during APP runtime. In the mPaaS framework, the lifecycle management of microapplications and services is performed through the framework context.

Application Lifecycle Management

By modifying the implementation of the main.m function, the mPaaS framework uses the ClientDelegate class to take over the various APP lifecycles in UIApplicationDelegate. After the mPaaS framework is connected, ClientDelegate completely replaces the role of AppDelegate in general engineering, thus realizing that the entire application lifecycle is managed by the framework.

In order to facilitate users to obtain APP lifecycle to develop custom functions, mPaaS framework provides DTFrameworkInterface class which implements the equivalent access mode of all proxy methods in UIApplicationDelegate.

Just overwrite the corresponding method in the Category of the DTFrameworkInterface.

For example, the following common UIApplicationDelegate proxy method:

The corresponding methods are provided in the DTFrameworkInterface:

Since mPaaS framework has some initialization logic to implement, the beforeDidFinishLaunchingWithOptions and afterDidFinishLaunchingWithOptions methods are additionally provided in DTFrameworkInterface, which is convenient for users to execute their own initialization code at a time determined by APP startup.

DTFrameworkInterface in afterDidFinis

LaunchingWithOptions starts BootLoader before executing the initialization logic of the mPaaS framework. In embedded operating systems, the role of BootLoader is to initialize the hardware device so that the correct environment is prepared for the final call to the operating system kernel. Similarly, in the mPaaS framework, BootLoader is used to initialize the entire mPaaS framework environment, and the default implementation is to execute the following process in turn:

Creating a window

Creating a Primary NavigationController

Run services that can be run only once and need to be started first

Start all other non-lazyload services

StartSpecify service groupings that need to be started automatically in the ServicesMap "[AUTOSTART]" array

Display main Window

Launch Launcher microapp and display home page

This completes the initialization of the mPaaS framework and the display of the home page.

Three key concepts will be described in detail later: microapplications, services, and framework context.

micro-app

Micro-application is an independent business module with UI interface, among which the most special micro-application is Launcher micro-application. Launcher is the first micro-application opened after APP startup, which is generally used to create App homepage. In the mPaaS framework, microapplications are highly independent and not interdependent.

Microapps are registered via plist configuration. When configuring the microapp, you need to specify the class name corresponding to delegate, the description of the microapp, and the name used when opening the microapp. In this way, the framework context can open the specified micro-application through the name of the micro-application.

To facilitate business development, each microapp also has a lifecycle. The life cycle of micro-apps is modeled after the life cycle of iOS apps. Each microapp needs to implement its own DTMicroApplicationDelegate agent, which is similar to the Appdelegate class implemented in iOS apps.

For specific business development, microapplication development is like a complete APP, each microapplication is responsible for controlling the page stack within its own application and performing corresponding operations according to the life cycle of the microapplication. In the mPaaS framework, all microapps run in containers provided by the mPaaS framework, which do not need to focus on the APP lifecycle. For some special business scenarios, mPaaS supports the creation of multiple instances of microapps.

service

Services differ from microapps in that they do not have a UI and are executed in the background. Once a service is started, it exists throughout the life cycle of the client, so services are generally used to provide general services to microapplications, such as performing certain functions or obtaining data.

A common service is the user login status service, through which each microapplication can obtain user login status and user information.

Services are also registered via plist configuration. When registering a service, you need to provide the unique identifier name of the service and the corresponding implementation class name. The framework creates instances of service implementation classes at service creation time using Objective-C runtime mechanisms. lazyLoading is used to control whether the class is loaded late. In the case of delayed loading, the service is not instantiated when the framework starts, but only when it is used. If it is a non-lazy load, the service is started when the framework starts.

Due to the particularity of services, ServicesMap is also provided in mPaaS to register classes in batches.[AUTOSTART] in ServicesMap is used to indicate which groups of services need to be started first when the App is started.

This hierarchical startup service feature can effectively control the startup time of the APP, thus providing a good user experience.

Each service needs to implement a service interface:

After adding services, the structure of the entire App is shown below. Back-end services serve as a bridge between microapplications.

Context

Through the previous introduction, we have already had an in-depth understanding of micro-applications and services. In the mPaaS framework, the framework context assumes the role of a scheduler, responsible for scheduling and communication management of various micro-applications and services, thus realizing the opening of each micro-application, page stack pushing and closing other micro-application modules that do not affect the APP.

The framework context object Context can be obtained through the DTContext * DTContextGet() function provided by the mPaaS framework.

A simplified Context class implementation is as follows:

For business developers, the framework context can be used to obtain the main window, start a specified micro-application, obtain a service, and dynamically register and de-register services, thus realizing the connection between businesses.

The above is the basic idea analysis of how to carry out the iOS containerization framework shared by Xiaobian for everyone. If there are similar doubts, please refer to the above analysis for understanding. If you want to know more about it, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report