Lynx Service provides Lynx Engine with host-specific capabilities, including image, log, and FetchAPI capabilities.
Different hosts have specific requirements for their own image, log, and network libraries, so Lynx Engine opens up autonomous access capabilities for such scenarios through the LynxService API.
Lynx Engine and Lynx Service adopt a dependency-separation design. In terms of the dependency relationship, Lynx Service depends on the LynxService API provided by Lynx Engine to implement itself, while Lynx Engine does not depend on LynxService. At runtime, Lynx Engine will search for the registered Lynx Service through the service lookup mechanism and call it via the LynxService API.
The LynxService API is provided by Lynx Engine and is designed to specify the capabilities of LynxService. Lynx Service needs to correctly implement itself in accordance with the requirements of the LynxService API to ensure that Lynx Engine can properly use this basic capability.
If there are custom requirements, you can also quickly implement and register relevant content according to your own needs. The following will take log service as an example to introduce how to implement and register a custom Lynx Service:
Use the LynxServiceRegister to achieve automatic registration.
Implement serviceBizID and serviceScope. These two methods have no practical significance and will be removed later.
Implement serviceType. It is required to return the type implemented by this Service. See LynxService.h for details.
(Recommended) Implement sharedInstance to make it a singleton class. Based on the current Lynx Service design, only one instance of a certain type of Service will be used globally. It is recommended to implement it as a singleton class.
Implement all the interfaces required by LynxServiceLogProtocol.
YourLogService.mm
#import "YourLogService.h"[[maybe_unused]] void logWrite(unsigned int level, const char *tag, const char *format) { if (format == NULL) { return; } NSLog(@"[%s] %s", tag == NULL ? "" : tag, format);}// Use the LynxServiceRegister macro to achieve automatic registration@LynxServiceRegister(LynxLogService);// Implement LynxLogService@implementation LynxLogService// Irrelevant property, will be removed later+ (NSString*)serviceBizID { return DEFAULT_LYNX_SERVICE;}// Irrelevant property, will be removed later+ (LynxServiceScope)serviceScope { return LynxServiceScopeDefault;}// Return the corresponding service type for runtime lookup+ (NSUInteger)serviceType { return kLynxServiceLog;}// Recommended: Implement as a singleton+ (instancetype)sharedInstance { static dispatch_once_t onceToken; static YourLogService *logService; dispatch_once(&onceToken, ^{ logService = [[YourLogService alloc] init]; }); return logService;}// Implement all the interfaces required by LynxServiceLogProtocol- (void *)getWriteFunction { return (void *)logWrite;}@end
Implement ILynxLogService:
YourLogService.kt
object YourLogService : ILynxLogService { private var logOutputChannel: LogOutputChannelType = LogOutputChannelType.Platform override fun logByPlatform( level: Int, tag: String, msg: String, ) { // Implemention } override fun isLogOutputByPlatform(): Boolean = logOutputChannel == LogOutputChannelType.Platform override fun getDefaultWriteFunction(): Long = 0 override fun switchLogToSystem(enableSystemLog: Boolean) {} override fun getLogToSystemStatus(): Boolean = false}
Lynx Service has an automatic registration mechanism in iOS. In the implementation stage, the LynxServiceRegister macro has been used to complete the quick automatic registration.
If you use your own implementation of Lynx Service, please delete the default implementation provided by Lynx.
Podfile
pod 'LynxService', '3.4.1', :subspecs => [ 'Image',- 'Log', 'Http', ]
Replace the implementation of log service in LynxServiceCenter in the integration documentation with your implementation.
Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License, and code samples are licensed under the Apache License 2.0.