IntentConfiguration (意圖配置)
一個(gè)對(duì)象,它描述使用自定義意圖定義提供用戶(hù)可配置選項(xiàng)的小部件的內(nèi)容。
宣言
struct IntentConfiguration<Intent,Content> where Intent : INIntent,Content:View
總覽
以下示例顯示了游戲小部件的配置,該小部件顯示有關(guān)所選角色的詳細(xì)信息。
struct CharacterDetailWidget:Widge {
var body:some WidgetConfiguration {
IntentConfiguration(kind:"com.mygame.character-detail",
intent:SelectCharacterIntent.self,
` provider:CharacterDetailProvider(),
) { entry in
CharacterDetailView( entry:entry)
}
.configurationDisplayName("Character Details")
.description("Displays a character's health and other details")
.supportedFamilies([.systemSmall,.systemMedium,.systemLarge])
}
}
每個(gè)小部件都有一個(gè)唯一的kind
,您選擇的字符串。在使用WidgetCenter來(lái)重新加載其時(shí)間軸時(shí),可以使用此字符串來(lái)標(biāo)識(shí)窗口小部件。
這intent是一個(gè)包含用戶(hù)可編輯參數(shù)的自定義SiriKit意向定義。
時(shí)間線(xiàn)提供者是一個(gè)確定刷新小部件的時(shí)間線(xiàn)的對(duì)象。提供更新小部件的將來(lái)日期可以使系統(tǒng)優(yōu)化刷新過(guò)程。
內(nèi)容閉包包含了WidgetKit渲染小部件所需的SwiftUI視圖。當(dāng)WidgetKit調(diào)用內(nèi)容閉包時(shí),它將傳遞一個(gè)由小部件提供程序的getSnapshot(for:in:completion:)或getTimeline(for:in:completion:)方法創(chuàng)建的時(shí)間軸條目。
修改器允許您指定小部件支持的家族,以及用戶(hù)添加或編輯小部件時(shí)顯示的詳細(xì)信息。
另外閱讀
init<Provider>(kind: String, intent: Intent.Type, provider: Provider, content: (Provider.Entry) -> Content)
*通過(guò)使用自定義意圖定義提供用戶(hù)可配置的選項(xiàng)來(lái)為窗口小部件創(chuàng)建配置。
Intent繼承INIntent并Content遵循時(shí)可用View。
init<Provider, PlaceholderContent>(kind: String, intent: Intent.Type, provider: Provider, placeholder: PlaceholderContent, content: (Provider.Entry) -> Content)
通過(guò)使用自定義意圖定義提供用戶(hù)可配置的選項(xiàng)來(lái)為窗口小部件創(chuàng)建配置。
Intent繼承INIntent并Content遵循時(shí)可用View。
var body: some WidgetConfiguration
聲明此小部件的內(nèi)容和行為。
typealias Body
- 代表此配置主體的窗口小部件配置的類(lèi)型。*
設(shè)置顯示名稱(chēng)
func configurationDisplayName(LocalizedStringKey) -> some WidgetConfiguration
設(shè)置當(dāng)用戶(hù)添加或編輯窗口小部件時(shí)為窗口小部件顯示的本地化名稱(chēng)。
func configurationDisplayName(Text) -> some WidgetConfiguration
設(shè)置當(dāng)用戶(hù)使用文本視圖的內(nèi)容添加或編輯窗口小部件時(shí)顯示的名稱(chēng)。
func configurationDisplayName<S>(S) -> some WidgetConfiguration
設(shè)置當(dāng)用戶(hù)使用指定的字符串添加或編輯窗口小部件時(shí)顯示的名稱(chēng)。
設(shè)置說(shuō)明
func description(LocalizedStringKey) -> some WidgetConfiguration
設(shè)置當(dāng)用戶(hù)添加或編輯窗口小部件時(shí)為窗口小部件顯示的本地化描述
func description(Text) -> some WidgetConfiguration
設(shè)置當(dāng)用戶(hù)使用文本視圖的內(nèi)容添加或編輯窗口小部件時(shí)顯示的描述。
func description<S>(S) -> some WidgetConfiguration
設(shè)置當(dāng)用戶(hù)使用指定的字符串添加或編輯窗口小部件時(shí)顯示的描述。
設(shè)置支持的家庭
func supportedFamilies([WidgetFamily]) -> some WidgetConfiguration
設(shè)置小部件支持的大小。
處理后臺(tái)網(wǎng)絡(luò)請(qǐng)求
func onBackgroundURLSessionEvents(matching: ((String) -> Bool)?, ((String, () -> Void) -> Void)) -> some WidgetConfiguration
添加一個(gè)動(dòng)作,當(dāng)與閉包標(biāo)識(shí)的URL會(huì)話(huà)相關(guān)的事件正在等待處理時(shí)執(zhí)行。
func onBackgroundURLSessionEvents(matching: String, ((String, () -> Void) -> Void)) -> some WidgetConfiguration
添加一個(gè)動(dòng)作,當(dāng)與具有匹配標(biāo)識(shí)符的URL會(huì)話(huà)相關(guān)的事件正在等待處理時(shí)執(zhí)行。
關(guān)聯(lián)關(guān)系
WidgetConfiguration
可配置的小部件
制作可配置的小部件
通過(guò)向您的項(xiàng)目添加自定義SiriKit意向定義,為用戶(hù)提供自定義其小部件的選項(xiàng)。
struct WidgetInfo
包含有關(guān)用戶(hù)配置的小部件的信息的結(jié)構(gòu)。