Widget not loading on iOS 17 beta, "Missing backing store for Intent" error

huangapple go评论98阅读模式
英文:

Widget not loading on iOS 17 beta, "Missing backing store for Intent" error

问题

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

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

在使用 Xcode 构建时,我收到以下错误消息:

-[INIntent _initWithIdentifier:backingStore:schema:error:] Missing backing store for Intent: {xxx-xxx-xxx 一些ID} (N/A - N/A)

该应用程序使用自定义意图,以允许在小部件上进行一些设置。
小部件和应用程序通过一个应用程序组共享数据,以避免网络请求的重复。

我无法在 Stack Overflow 上找到有关此错误的任何信息,也无法在 Apple 的 beta 发布说明中找到相关信息。还有其他人遇到了这个问题吗?

英文:

I work on an iOS app supporting iOS 15 and above, with a widget supporting iOS 16 and above.

The widget currently does not load on iOS 17 beta, for users it's just an empty box, both during snapshot preview while choosing the widget size, and after placing it on the home screen.

When building it from Xcode, I get the following error:

> -[INIntent _initWithIdentifier:backingStore:schema:error:] Missing backing store for Intent: {xxx-xxx-xxx some ID} (N/A - N/A)

The app uses a custom Intent to allow some settings on the widget.
The widget and app share data through an App Group to avoid duplication of network requests.

I could not find any information on this error on SO, nor on Apple beta release notes. Is anybody experiencing this as well?

答案1

得分: 2

你尝试过在时间轴条目中添加以下内容吗?

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

此代码是自动生成的,基本上是在小部件旋转或翻转到另一面时看到的视图。

import WidgetKit
import AppIntents

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

    // 一个可配置参数的示例。
    @Parameter(title: "Favorite Emoji", default: "😄")
    var favoriteEmoji: String
}

这对我来说在使用示例 EmojiRangers 时有效。

英文:

Have you tried to add

let configuration: ConfigurationAppIntent in the TimeLine Entry?

Example:

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

This code is generated automatically, and basically it's the view that you see when the widget turns or spins to the other side

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
}

This worked for me using the example EmojiRangers

答案2

得分: 1

我可以通过确保意图在主线程上运行来解决这个问题。iOS 17似乎允许意图代码直接在应用程序和小组件扩展中运行。

对我来说,扩展似乎崩溃了,因为它在应用程序中运行代码而不是在扩展中运行。我的一些代码有点老旧,需要在主线程上运行。但EntityQuery是在后台线程上运行的,所以我做了一些更改,现在在我的情况下它又开始工作了。

英文:

I could resolve this by making sure the intent is running on the main thread. With iOS 17 it seems the intent code can now run directly in the app and on the widget extension.

For me the extension seems to have crashed because it was running the code in the app instead of the extension.
Some parts of my code are a bit old and need to run on the main thread. The EntityQuery is running on a background thread though so I changed this and it's working again in my case.

struct DataAppEntityQuery: EntityQuery {
        func entities(for identifiers: [DataAppEntity.ID]) async throws -> [DataAppEntity] {
			let data = await retrieveData().filter { identifiers.contains($0.id) }
			return data
        }

        func suggestedEntities() async throws -> [DataAppEntity] {
			return await retrieveData()
        }
		
		func defaultResult() async -> DataAppEntity? {
			try? await suggestedEntities().first
		}
		
		
		func retrieveData() async -> [DataAppEntity] {
            //code that needs to run on the main thread in my case            

			await MainActor.run {
                //....
                return data
			}
		}
    }

huangapple
  • 本文由 发表于 2023年7月20日 18:54:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/76729150.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定