WidgetKit小组件在iOS 17上没有显示出来。

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

WidgetKit Widgets not showing up on iOS 17

问题

我有一组在Xcode 14和iOS 16上都能完美运行的小部件,无论是在模拟器还是设备上。但是在Xcode 15 beta(4)上,这些小部件在iOS 17模拟器上突然不再显示,感觉我已经尝试了一切。

在任何iOS 16或15模拟器上使用新的Xcode 15 beta构建都能正常工作,并且可以使用这些小部件。但在iOS 17.0上它们就不见了。

当我添加一个新的小部件扩展时,它会立刻显示在iOS 17模拟器上。我已经逐行比较了所有的构建设置,但没有找到任何区别。

我还尝试将SiriKit Intent更新为AppIntent,但没有成功。

有人遇到了同样的问题吗?或者有没有任何线索我可能忽略了什么?

英文:

I have a set of Widgets that work flawlessly on Xcode 14 and iOS 16, both on Simulator and Device. With Xcode 15 beta (4), these widgets simply don't show up anymore on the iOS 17 Simulator, and I feel like I've tried everything.

Building with the new Xcode 15 beta on any iOS 16 or 15 simulator works fine and the widgets are available. They're just gone on iOS 17.0.

When I add a new widget extension it shows up immediately on the iOS 17 simulator. I've compared every single line on the Build Settings but couldn't find any difference there.

I have also updated the SiriKit Intent to an AppIntent with no success.

Anyone experiencing the same issue? Or any clue on what I could have missed?

答案1

得分: 0

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

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

此外,似乎在我的情况下模拟器使用的内存比真实设备多得多。这使得在模拟器上进行测试有点无用,因为它会耗尽内存并导致小部件失败,而设备只使用约13 MB。

英文:

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

Also it seems that in my case the simulator uses way more memory than the real device. This makes testing on the simulator a bit useless because it runs out of memory and fails the widget where the device only uses some 13 MB.

huangapple
  • 本文由 发表于 2023年7月13日 19:04:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/76678652.html
匿名

发表评论

匿名网友

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

确定