11.3 C
New York
Thursday, November 21, 2024

ios – Why does my app run in Simulator, however freezes on gadget?


My app runs high-quality usually with all options. However one new button/function I added freezes the app on gadget, however works flawlessly within the simulator. I checked comparable questions on right here and located one basic answer to restart the gadget and Xcode. It did not assist, as I anticipated.

I anticipated this behaviour as that is the second time precisely this occurs. The button working in Simulator and freezing on gadget. And final time I commented out all code till I discovered one line inflicting the issue. It was the initialisation of the timer. Shifting it into the physique solved the issue.

import SwiftUI
import AVFoundation
import SwiftData
import CoreHaptics  /// For making vibrations as soon as the timer is run out


struct TimerTapasFullView: View {
    @Surroundings(.dismiss) var dismiss         /// To have the ability to dismiss the view
    
    @State var countdownTimer = 5 * 60          /// The precise seconds of the timer, being counted down/up
    @State var timerRunning = true              /// Var to set and see if timer is working
    @State var gongSound: AVAudioPlayer?        /// The Sound of the timer
    
    @State personal var hours: Int = 0           /// Vars for the picker wheel
    @State personal var minutes: Int = 0
    @State personal var seconds: Int = 0
    
    @State personal var brightnessLow = false    /// Var for saving if the brightness button was used
    
    @State personal var engine: CHHapticEngine?  /// The item creating the vibrations afterward
    @Surroundings(.scenePhase) var scenePhase   /// Var to maintain monitor of state of app, to restart HapticEngine
    
    /// Surroundings Objects
    @EnvironmentObject var userStat: StatisticsObject       /// Var to maintain monitor of seconds utilizing the Timer
    @EnvironmentObject var envObject: EnvObject             /// For getting FullDarkness, vibrateTimer
    
    /// Variables from the Tapas for setting the timer
    @State var asanas: [TapasAsana]
    @State var asana: TapasAsana
    @State var nextAsana = TapasAsana()

    let path = Bundle.major.path(forResource: "bell_basu.mp3", ofType:nil)!
    
    var physique: some View {
        /// Provoke the timer
        let timer = Timer.publish(each: 1, on: .major, in: .frequent).autoconnect()
        
        /// For calculating hours, minutes, seconds
        let fashion = Length.TimeFormatStyle(sample: .minuteSecond)
        //let formTimer = Length.seconds(countdownTimer).formatted()
        let formTimerShort = Length.seconds(countdownTimer).formatted(fashion)
        let url = URL(fileURLWithPath: path)
        
        VStack {
        ... extra code follows...

This was the road that induced this behaviour the primary time:

let timer = Timer.publish(each: 1, on: .major, in: .frequent).autoconnect()

Now I added new options, together with this line:
@State var nextAsana = TapasAsana()

I’ve so many questions on this. Does anybody have any thought why it runs flawlessly within the Simulator and in no way on gadget? This fashion I all the time examine within the Simulator and once I examine after a coding session on gadget, I don’t know which of many adjustments I made causes this freeze.

The Debugger in Xcode exhibits nothing when this occurs. Is there any option to make it present extra detailed what is going on on gadget?

Do you could have any thought why this occurs? Is any of my code defective or am I utilizing dangerous practices that consequence on this freeze?

I’d be very grateful to grasp this massive drawback, thanks for any assist.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles