ios

[ios - Swift] App 상태 변경에 따른 Widget 초기화

POKY_0908 2021. 2. 4. 16:01

 

 

 

앱 상태 변경에 따라 위젯의 타임라인을 다시 설정해 줘야할 때가 있다.

 

이 때 앱에서 WidgetKit에게 아래와 같은 방법으로 타임라인을 다시 요청하도록 할 수 있다.

 

WidgetCenter.shared.getCurrentConfigurations { (result) in
    switch result {
    case .success(let widgets):
        for info in widgets {
            /// 특정 위젯 타임라인 로드
            WidgetCenter.shared.reloadTimelines(ofKind: info.kind)
            print(info.family, info.kind) // 위젯의 크기, 식별자
        }
        break
    case .failure(let error):
        print("Fail")
        break
    default:
        break
    }
}