5minho / DreamRecorder

mino & bran BoostCamp Project
6 stars 0 forks source link

DataStore, Scheduler, SoundManager의 결합도를 낮추기 위한 NotificationCenter활용. #49

Closed YoonJuHo closed 6 years ago

YoonJuHo commented 6 years ago

Store, Scheduler, SoundManger는 서로 밀접한 관계를 가지는데 그 관계를 줄이기 위해 NoticiationCenter를 활용 Publishers와 Subscribers로 변화시켜 관계를 최대한 느슨하게 만드는데 목적이 있다.

YoonJuHo commented 6 years ago
  1. 알람 CRUD Controller: ListViewController에서 Store에 접근하여 CRUD한다. DataStore: Alarm을 메모리와 DB에 각 각 CRUD한다. -> post AlarmDataStoreDidXXXAlarm (Scheduler will Receive and CRUD Notification) -> post AlarmDataStoreDidChange ( ListViewController will Receive and Update tableView) Scheduler: AlarmDataStoreDidXXXAlarm를 통해 Notification을 CRUD한다. -> post AlarmSchedulerNextNotificationDateDidChange (notification의 변화는 다음에 울릴 알람시간 바뀔 수 있음) SoundManager: AlarmSchedulerNextNotificationDateDidChange를 통해 다음알람시간을 설정하고 QueuePlayer를 다시 시작시킨다.

  2. 알람 발생(Foreground 상태) UIApplication: post ApplicationWillPresentNotification, 알람음 실행화면 띄우기(실행 화면이 아닐 경우) DataStore: ApplicationWillPresentNotification를 통해 한번 알림의 경우 isActive를 비활성화 -> post AlarmDataStoreDidChange Notification: stop의 경우는 Snooze Notification 삭제, 그냥 실행은 Nothing SoundManager: 1) 백그라운드) stop의 경우는 player를 stop시키고, 그냥 실행의 경우는 지속적으로 알람음 재생 2) 서스펜디드) 해당 알람음을 재생시키기.

  3. 알람 발생(background 상태) UIApplication: post ApplicationDidReceiveResponse

  4. 알람 발생(suspended 상태)

  5. 앱 실행 Scheduler: Delivered & Duplicated Notification들을 삭제한다. -> post AlarmSchedulerNotificationDidDelivered (앱이 실행되지 않는 동안 발생한 (한번)알람들을 비활성화 시켜야함) -> post DataStore: AlarmSchedulerNotificationDidDelivered를 통해 해당 알람의 isActive를 비활성화 시킨다.

YoonJuHo commented 6 years ago
  1. 알람을 생성, 수정, 삭제가 발생했을 경우. UIApplication: 해당 UI를 업데이트(컨트롤러간 처리) DataStore: 해당 알람을 추가, 수정, 삭제

2-1. DataStore에서 추가, 수정, 삭제가 발생햇을 경우. Notification: 알람에 알맞게 UserNotification을 추가, 수정(삭제후 추가), 삭제를 해줌.

2-2. Notification에서 추가, 수정, 삭제이 일어나면 나음에 울릴 알람시간이 변경을 뜻함 SoundManager: 다음 알람시간을 업데이트 하고 지속적으로 Mute음악 재생 ** 다음 알람시간은 DataStore의 알람 객체가 변화가 없어도 지속적으로 변화가 일어나므로 Notification의 상태를 구독해야한다.