美文网首页
Widget 学习 IntentConfiguration

Widget 学习 IntentConfiguration

作者: 弑神指 | 来源:发表于2020-11-10 08:50 被阅读0次

    IntentConfiguration (意图配置)

    一个对象,它描述使用自定义意图定义提供用户可配置选项的小部件的内容。

    宣言

    
    struct IntentConfiguration<Intent,Content> where Intent : INIntent,Content:View 
    
    

    总览

    以下示例显示了游戏小部件的配置,该小部件显示有关所选角色的详细信息。

    
    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])
            }
    }
    
    

    每个小部件都有一个唯一的kind,您选择的字符串。在使用WidgetCenter来重新加载其时间轴时,可以使用此字符串来标识窗口小部件。

    这intent是一个包含用户可编辑参数的自定义SiriKit意向定义。

    时间线提供者是一个确定刷新小部件的时间线的对象。提供更新小部件的将来日期可以使系统优化刷新过程。

    内容闭包包含了WidgetKit渲染小部件所需的SwiftUI视图。当WidgetKit调用内容闭包时,它将传递一个由小部件提供程序的getSnapshot(for:in:completion:)或getTimeline(for:in:completion:)方法创建的时间轴条目。

    修改器允许您指定小部件支持的家族,以及用户添加或编辑小部件时显示的详细信息。

    另外阅读

    init<Provider>(kind: String, intent: Intent.Type, provider: Provider, content: (Provider.Entry) -> Content)

    *通过使用自定义意图定义提供用户可配置的选项来为窗口小部件创建配置。
    Intent继承INIntent并Content遵循时可用View。

    init<Provider, PlaceholderContent>(kind: String, intent: Intent.Type, provider: Provider, placeholder: PlaceholderContent, content: (Provider.Entry) -> Content)

    通过使用自定义意图定义提供用户可配置的选项来为窗口小部件创建配置。
    Intent继承INIntent并Content遵循时可用View。

    var body: some WidgetConfiguration

    声明此小部件的内容和行为。

    typealias Body

    • 代表此配置主体的窗口小部件配置的类型。*

    设置显示名称

    func configurationDisplayName(LocalizedStringKey) -> some WidgetConfiguration

    设置当用户添加或编辑窗口小部件时为窗口小部件显示的本地化名称。

    func configurationDisplayName(Text) -> some WidgetConfiguration

    设置当用户使用文本视图的内容添加或编辑窗口小部件时显示的名称。

    func configurationDisplayName<S>(S) -> some WidgetConfiguration

    设置当用户使用指定的字符串添加或编辑窗口小部件时显示的名称。

    设置说明

    func description(LocalizedStringKey) -> some WidgetConfiguration

    设置当用户添加或编辑窗口小部件时为窗口小部件显示的本地化描述

    func description(Text) -> some WidgetConfiguration

    设置当用户使用文本视图的内容添加或编辑窗口小部件时显示的描述。

    func description<S>(S) -> some WidgetConfiguration

    设置当用户使用指定的字符串添加或编辑窗口小部件时显示的描述。

    设置支持的家庭

    func supportedFamilies([WidgetFamily]) -> some WidgetConfiguration

    设置小部件支持的大小。

    处理后台网络请求

    func onBackgroundURLSessionEvents(matching: ((String) -> Bool)?, ((String, () -> Void) -> Void)) -> some WidgetConfiguration
    添加一个动作,当与闭包标识的URL会话相关的事件正在等待处理时执行。

    func onBackgroundURLSessionEvents(matching: String, ((String, () -> Void) -> Void)) -> some WidgetConfiguration

    添加一个动作,当与具有匹配标识符的URL会话相关的事件正在等待处理时执行。

    关联关系

    WidgetConfiguration

    可配置的小部件

    制作可配置的小部件

    通过向您的项目添加自定义SiriKit意向定义,为用户提供自定义其小部件的选项。

    struct WidgetInfo

    包含有关用户配置的小部件的信息的结构。

    相关文章

      网友评论

          本文标题:Widget 学习 IntentConfiguration

          本文链接:https://www.haomeiwen.com/subject/tvhrbktx.html