GrowingAnalytics源码阅读-初始化GrowingAppLifecycle实现

GrowingAnalytics

Github地址 : https://github.com/growingio/growingio-sdk-ios-autotracker

相关类

  • GrowingAppLifecycle

作用

  1. 需要App生命周期的组件,无需增加繁琐的代码监听。
  2. 实现GrowingAppLifecycleDelegate的实体类之前是相互独立的,不存在相互调用关系。
  3. 向后扩展,新增的组件只需要实现GrowingAppLifecycleDelegate即可获取应用生命周期方法。

从代码开始

  • [1]初始化容器
  • [2]注册app生命周期事件
  • [3]注入/移除订阅者
  • [4]事件触发时,通知订阅者。
- (instancetype)init {
    self = [super init];
    if (self) {
        _appLifecycleDelegates = [NSPointerArray pointerArrayWithOptions:NSPointerFunctionsWeakMemory];
        _delegateLock = [[NSLock alloc] init];
    }
    return self;
}
//添加观察者
- (void)setupAppStateNotification {
    if (enable && 13.0) {
              UISceneWillDeactivateNotification,
              UISceneDidActivateNotification,
              UISceneWillEnterForegroundNotification,
              UISceneDidEnterBackgroundNotification
    } else {
              UIApplicationDidBecomeActiveNotification,
               UIApplicationWillEnterForegroundNotification,
               UIApplicationWillResignActiveNotification,
               UIApplicationDidEnterBackgroundNotification
    }
}
//增加,移除订阅者
- (void)addAppLifecycleDelegate:(id)delegate {}
- (void)removeAppLifecycleDelegate:(id)delegate {}
// 发送消息变更消息
- (void)dispatchApplication....{}

你可能感兴趣的:(GrowingAnalytics源码阅读-初始化GrowingAppLifecycle实现)