App crashes after showing Music Subscription offer sheet

Hi all,

I ma displaying the Music Subscription offer sheet in my app. Shortly after the sheet is presented, when the user dismisses the offer, the app crashes with error:

Fatal error: CloudServiceSetupView.makeUIViewController() was called with an unexpected presentation state: idle.

2021-11-30 11:56:28.974626-0800 AppName[16276:4525658] _MusicKit_SwiftUI/CloudServiceSetupView.swift:31: Fatal error: CloudServiceSetupView.makeUIViewController() was called with an unexpected presentation state: idle.

What am I doing wrong?

Related Ticket for Apple Engineers: FB9789040

Answered by ashinthetray in 696809022

SOLVED:

Issue turned out be because I had the subscription offer sheet attached to each item in a forEach loop. Once I moved it out, the app stopped crashing.

Hello @ashinthetray,

Thanks for reaching out to us about this issue.

I don't think we've ever encountered this crash internally in our testing of the music subscription offer sheet.

It would really help us to see a little bit more about your code that uses the music subscription offer API.

Would you be able to attach some code for us to look at to your feedback ticket?

Thank you very much in advance for any additional information you can provide.

Best regards,

Accepted Answer

SOLVED:

Issue turned out be because I had the subscription offer sheet attached to each item in a forEach loop. Once I moved it out, the app stopped crashing.

Hello @ashinthetray,

Thank you very much for following up with additional debugging information.

I'm also very glad to hear you found a solution to this.

This makes a lot of sense. I actually consulted with the SwiftUI team to understand this better, and they told me that the only way this kind of behavior could happen is if the identity of the view changed.

And the music subscription offer modifier is indeed designed to be applied at a higher level of the SwiftUI view hierarchy, and not multiple times in dynamic lists of content.

Best regards,

App crashes after showing Music Subscription offer sheet
 
 
Q