Modular Development and Management of JD iOS Application
This article outlines JD's iOS modular development strategy, covering background, goals, code decoupling, custom routing protocols, AppDelegate hooking, Cocoapods management, the iBiu system, configuration tables, automation scripts, CI integration, and practical deployment steps.
Since its first release in February 2011, JD's iOS client has grown to a large, multi‑person team and a complex codebase, prompting the need for a modular development approach.
The primary business goals are parallel integration of multiple services and cross‑departmental output, while technical goals include reducing code decay, speeding up compilation, managing module ownership, enforcing coding standards, decreasing bugs, and enabling independent development, debugging, and automated builds.
Modules are decoupled by avoiding hard‑coded references and communicating through custom protocols. Two module types are defined: base (can be depended on) and business (cannot depend on each other).
A custom router, JDRouter , is introduced to handle lightweight inter‑module communication. Example URI:
router://JDBClass/getString?name=StevenRouter input method signature:
+(id)getDataWithString:(NSString *)name {
NSString *str = [NSString stringWithFormat:@"HI, %@", name];
return str;
}Output is standardized via a macro:
#define JDROUTER_EXTERN_METHOD(m,i,p,c) + (id)routerHandle_##m##_##i:(NSDictionary*)arg callback:(Completion)callbackAppDelegate responsibilities are hooked into a dedicated module, allowing each module to implement its own didFinishLaunchingWithOptions ‑like method. Example registration:
+ (void)load {
NSArray *modules = @[@"MainModule"];
NSString *url = @"router://AppDelegateModule/setDidFinishLaunchingModules";
[JDRouter openURL:url arg:modules error:nil completion:nil];
NSString *urlrun = @"router://AppDelegateModule/run";
[JDRouter openURL:urlrun arg:nil error:nil completion:nil];
}Modules are packaged as independent CocoaPods, stored in a private GitLab repository, with binary distribution for security‑sensitive components. A private pod template and custom gem handle podspec generation and binary switching.
The iBiu system automates module registration, review, creation, GitLab integration, permission assignment, and visual management. It provides a configuration table (JSON) that records module versions, owners, and dependencies, enabling one‑click composition of applications from multiple modules.
Key workflow steps include:
Creating a pod library via pod lib create $lib_name --template-url=${TEMPLATE_URL}
Automating module generation on an iBiu server backed by Jenkins and a Mac build node.
Synchronizing configuration tables to avoid merge conflicts.
Integrating modules into apps through the iBiu visual tool, handling source vs. binary permissions.
Generating per‑version configuration tables for CI builds and release pipelines.
Managing JDRouter interfaces centrally for easy discovery.
Adapting existing CI pipelines to invoke iBiu APIs for module installation and packaging.
Overall, the article presents a comprehensive solution for scaling JD's iOS codebase through modularization, automated tooling, and centralized management.
JD Retail Technology
Official platform of JD Retail Technology, delivering insightful R&D news and a deep look into the lives and work of technologists.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.