반응형
LinkedIn 개발자로 성장하면서 남긴 발자취들을 확인하실 수 있습니다.
Github WWDC Student Challenge 및 Cherish, Tiramisul 등 개발한 앱들의 코드를 확인하실 수 있습니다.
개인 앱 : Cherish 내 마음을 들여다보는 시간, 체리시는 디자이너와 PM과 함께 진행 중인 1인 개발 프로젝트입니다.
10년 후, 20년 후 나는 어떤 스토리 텔러가 되어 있을지 궁금하다. 내가 만약에 아직 조금 더 탐구하고 싶은 게 있고, 궁금한 게 있다면, 그게 설사 지금 당장의 내 인생에 도움이 안 되는 것 같더라도 경험해보자. 그 경험들을 온전히 즐기며 내 것으로 만들고, 내 일에 녹여내고... 그러다보면 그 점들이 모여 나란 사람을 그려내는 선이 될 테니까.

Recent Posts
Recent Comments
Total
관리 메뉴

꿈꾸는리버리

SwiftUI Widget 딱대(짐).. : Lock Screen Widget 본문

카테고리 없음

SwiftUI Widget 딱대(짐).. : Lock Screen Widget

rriver2 2025. 4. 8. 16:08
반응형

 

 ☁️ Widget 시리즈 

기본 시리즈

SwiftUI Widget 딱대.. (1/3) 위젯 기본 개념 + 구현

SwiftUI Widget 딱대.. (2/3) : 앱 내의 데이터를 widget에 띄우기

SwiftUI Widget 딱대.. (3/3) : 위젯을 눌렀을 때 다른 화면으로 뜨게 하기

SwiftUI Widget 딱대.. ( Lock Screen Widget )

 

에러 시리즈

SwiftUI Widget 딱대(짐).. : 위젯 memory 제한

SwiftUI Widget 딱대(짐).. : localization 적용

SwiftUI Widget 딱대(짐).. : 위젯에 폰트가 안 먹혀요...

[Error 해결] Embedded binary's bundle identifier is not prefixed with the parent app's bundle identifier.

SwiftUI Widget 딱대(짐).. : 딥링크가 안되는 뎁숑 ?

SwiftUI Widget 딱대(짐).. : Xcode Widget error Failed to show Widget 고치기

SwiftUI Widget 딱대(짐).. : Widget에 보여지는 순서 수정하기

SwiftUI Widget 딱대(짐).. : iOS 18 이후 Tint Widget 흰 화면 에러 해결SwiftUI Widget 딱대(짐).. : 딥링크가 안되는 뎁숑 ?


 ✈️ Lock Screen Widget 

- 이렇게 락스크린 위젯은 3가지 종류이다. 그리고 Widget을 개발했다면 코드 몇 줄만 추가하면 바로 넣을 수 있다니.. 넘 좋잖아???

- 참고로 잠금 화면 위젯은 16.0+부터 이용 가능하다.

 

 ✈️  구현 방법 

1. StaticConfiguration으로 생성하기

( Widget을 처음 만들어본다면 이 포스팅을 우선 참고해주세요 ! )

- 만약 위젯을 처음 만든다면, 위젯 생성할 때 include Configuration App Intent를 빼기.

 

- 이미 위젯을 작성했다면, StaticConfiguration으로 변경해야 한다.
( AppIntentConfiguration의 경우에는 지원을 안하는 것 같은데, 안해봐서 확실치는 않음 ... )

 

Creating accessory widgets and watch complications | Apple Developer Documentation

Support accessory widgets that appear on the Lock Screen and as complications on Apple Watch.

developer.apple.com

 

2. WidgetFamily 추가

지원하는 WidgetFamily에 .accessoryCircular, .accessoryInline, .accessoryRectangular를 추가한다.

StaticConfiguration(kind: kind, provider: DDayTimelineProvider()) { entry in
            // 내용
}
// supportedFamilies에 추가 ( 기존 위젯들도 지원하면 같이 입력 )
.supportedFamilies([.accessoryCircular, .accessoryInline, .accessoryRectangular])

 

3. View 그리기

struct OurDdayDefaultWidgetEntryView : View {
    @Environment(\.widgetFamily) private var widgetFamily
    var entry: DDayTimelineProvider.Entry
    
    var body: some View {
        switch widgetFamily {
        case .accessoryCircular:
            // View 추가
        case .accessoryInline:
            // View 추가
        case .accessoryRectangular:
            // View 추가
        }
    }
}

 

+ 약간의 꿀팁

1) ViewThatFits : iOS 16.0 부터 지원

화면이 짤리면 ( 텍스트가 길어서 뒷 내용이 ...으로 된다면 ) 이런식으로 해서 Font 크기를 조절할 수 있다.

ViewThatFits {
                VStack {
                    Text(icon)
                    Text(DdayString)
                }
                .font(.lee_18)
                VStack {
                    Text(icon)
                    Text(DdayString)
                }
                .font(.lee_15)
            }

 

2) 프리뷰

struct MyLockScreenWidget_Previews: PreviewProvider {
    static var previews: some View {
       Group {
                InlineViewForWidget(Dday: ddayCount)
                    .previewContext(WidgetPreviewContext(family: .accessoryInline))
                CircularViewForWidget(Dday: ddayCount)
                    .previewContext(WidgetPreviewContext(family: .accessoryCircular))
                    .containerBackground(for: .widget) {
                        Color.white 
                    }
                RectangularViewForWidget(Dday: ddayCount, title: title, meetingDateModel: meetingDateModel)
                    .previewContext(WidgetPreviewContext(family: .accessoryRectangular))
                    .containerBackground(for: .widget) {
                        Color.white 
                    }
        }
    }
}

 

 

 

 

Widgets | Apple Developer Documentation

A widget elevates and displays a small amount of timely, relevant information from your app or game so people can see it at a glance in additional contexts.

developer.apple.com

 

How to add and edit widgets on your iPhone - Apple Support

With widgets, you get timely information from your favorite apps at a glance on your Home Screen, Lock Screen, or Today View.

support.apple.com

 

반응형
Comments