backgroundPreferenceValue does not work after distributed through App Connect

Hi, I'm new to software development and facing a problem that don't know how to solve.

I have a piece of code using .backgroundPreferenceValue and .anchorPreference modifiers to monitor a button's position while dragging. It works perfectly on preview, simulator, and my own device if I download it through a cable connected to my computer. However, today I distributed it to TestFlight and found out it broke. I repeated the process serval times but the result is still the same. Has anybody run into the same type of problem before? Desperately need help. Many many thanks!

You don't provide really useful information.

 

and found out it broke.

  • Does it crash ?
  • Do you get a crashlog ?
  • What do you get ?
  • What did you expect ?

 

  • What iOS versions on simulator ? On your device ?
  • What versions "break" in TestFlight ?
  • Is it SwiftUI ?

You should also post the relevant part of code.

After some searching, I found the problem is somehow related with Optimization Level. If I run this on simulator with Scheme - Run - Build Configuration set to Debug, it works just fine. If Run - Build Configuration set to Release, the bug appears, but if I configure Build Settings - Optimization Level to none, it works again. But with the same “Release, Optimization Level none”settings submitted to App Connect, the bug still persists.

Here is an example: Put a red circle at the bottom of the screen. When dragged up, this circle gradually fades until it reaches the top and turns to completely transparent. In order to make sure this process is linear, I need to know the exact y position of this circle. So I set .anchorPreference to the CircleView to monitor the bounds of this circle, and .backgroundPreferenceValue to the ParentView to update the observable instance which stores the bounds information of this circle.

Under Debug Mode, it works just fine, the circle fades as it goes up. However, under release mode with optimization on, and in distributed version, this circle can be dragged, but the color remains the same, unchanged. No crash, no crashlog.

backgroundPreferenceValue does not work after distributed through App Connect
 
 
Q