Mobile Development 10 min read

Dynamic Domain Name Implementation in Mobile Apps

The article explains how to implement dynamic domain name switching in mobile apps across iOS, Android, Flutter, and H5 by using a configuration center and native network interception techniques such as NSURLProtocol, OkHttp instrumentation, texture bridging, and frontend configuration to resolve regional DNS issues and enable extended features like request statistics and custom responses.

Youzan Coder
Youzan Coder
Youzan Coder
Dynamic Domain Name Implementation in Mobile Apps

This article describes how to implement dynamic domain name switching in mobile applications to handle DNS resolution issues in certain regions. The solution combines a configuration center platform with native network interception techniques.

iOS Implementation: Uses NSURLProtocol, an abstract class provided by Apple for handling protocol-specific URL data. By creating a custom subclass and registering it with registerClass: , developers can intercept all HTTP/HTTPS requests. Key methods include canInitWithRequest: to determine which requests to intercept, canonicalRequestForRequest: for request customization, and startLoading / stopLoading for managing the request lifecycle. For third-party libraries like AFNetworking and Alamofire, Method Swizzle is used to replace protocolClasses in NSURLSessionConfiguration.

Android Implementation: Uses OkHttp and HttpUrlConnection/HttpsUrlConnection interception through bytecode instrumentation. The approach involves intercepting OkHttpClient configuration and URLConnection parameters to dynamically replace domain names.

Flutter Implementation: Uses external textures (TextureLayer) to bridge Flutter with native image loading. By leveraging PixelBuffer as the data carrier between Native and Flutter, image loading is delegated to native libraries like SDWebImage, enabling dynamic domain name support for images while regular network requests use Flutter plugins that call native libraries.

H5 Implementation: Uses frontend configuration to dynamically switch domains when domain access anomalies are detected, combined with the configuration center for unified network request management.

The solution can also be extended to: statistics network interface failure rates, redirect network requests, add common headers to requests, and return custom responses.

FlutterMobile DevelopmentCross‑PlatformiOSandroidOkHttpDynamic Domainnetwork interceptionNSURLProtocol
Youzan Coder
Written by

Youzan Coder

Official Youzan tech channel, delivering technical insights and occasional daily updates from the Youzan tech team.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.