iOS 17 beta 上的小部件未加载,“缺少 Intent 的后备存储”错误

Bri*_*ait 8 widget ios swift customintents ios17

我正在开发一个支持 iOS 15 及更高版本的 iOS 应用程序,以及一个支持 iOS 16 及更高版本的小部件。

该小部件目前无法在 iOS 17 Beta 上加载,对于用户来说,无论是在选择小部件大小时的快照预览期间,还是将其放置在主屏幕上之后,它都只是一个空框。

当从 Xcode 构建它时,我收到以下错误:

-[INIntent _initWithIdentifier:backingStore:schema:error:] 缺少 Intent 的后备存储:{xxx-xxx-xxx 某些 ID}(不适用 - 不适用)

该应用程序使用自定义 Intent 来允许小部件上的某些设置。小部件和应用程序通过应用程序组共享数据,以避免重复的网络请求。

我在 SO 上找不到有关此错误的任何信息,在 Apple beta 发行说明上也找不到。有人也遇到过这种情况吗?

Sop*_*icz 3

您是否尝试过添加

let configuration: ConfigurationAppIntent在时间线条目中?

例子:

struct SimpleEntry: TimelineEntry {
     let date: Date
     let configuration: ConfigurationAppIntent
     let character: CharacterDetail
 }


func placeholder(in context: Context) -> SimpleEntry {
    SimpleEntry(date: Date(), configuration: ConfigurationAppIntent(), character: .panda)
}

func snapshot(for configuration: ConfigurationAppIntent, in context: Context) async -> SimpleEntry {
    SimpleEntry(date: Date(), configuration: ConfigurationAppIntent(), character: .panda)
}
Run Code Online (Sandbox Code Playgroud)

该代码是自动生成的,基本上它就是当小部件转动或旋转到另一侧时您看到的视图

import WidgetKit
import AppIntents

struct ConfigurationAppIntent: WidgetConfigurationIntent {
    static var title: LocalizedStringResource = "Configuration"
    static var description = IntentDescription("This is an example widget.")

    // An example configurable parameter.
    @Parameter(title: "Favorite Emoji", default: "")
    var favoriteEmoji: String
}
Run Code Online (Sandbox Code Playgroud)

这对我使用示例 EmojiRangers 有用