GrowingAnalytics
Github地址 : https://github.com/growingio/growingio-sdk-ios-autotracker
相關(guān)類
作用
- 需要App生命周期的組件译暂,無需增加繁瑣的代碼監(jiān)聽锰霜。
- 實現(xiàn)GrowingAppLifecycleDelegate的實體類之前是相互獨立的刻蚯,不存在相互調(diào)用關(guān)系互墓。
- 向后擴展恕刘,新增的組件只需要實現(xiàn)GrowingAppLifecycleDelegate即可獲取應用生命周期方法缤谎。
從代碼開始
- [1]初始化容器
- [2]注冊app生命周期事件
- [3]注入/移除訂閱者
- [4]事件觸發(fā)時,通知訂閱者抒倚。
- (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 {}
// 發(fā)送消息變更消息
- (void)dispatchApplication....{}