logo
down
shadow

Adding .removeStateDidListener to deinit causes Application to Crash


Adding .removeStateDidListener to deinit causes Application to Crash

Content Index :

Adding .removeStateDidListener to deinit causes Application to Crash
Tag : ios , By : gcomstock
Date : January 12 2021, 08:33 AM

may help you . My guess is that _authHandle is already nil in the deinit. Test this if you can. Also note that you do not need to call removeObserver method for iOS 9+.

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

iOS 10 - NSKeyValueObservation crash on deinit


Tag : swift , By : user186876
Date : March 29 2020, 07:55 AM
wish of those help Updated on 2019/10/16
This seems to still happen on iOS 10.3 with Xcode 11 and Swift 5.1, I created a sample project to test it by using code from SR-5752.
// Environment: Xcode 11.1, Swift 5.1, iOS 10.3
deinit {
    if #available(iOS 11.0, *) {} else if let observer = observer {
        removeObserver(observer, forKeyPath: "foo")
    }
} 
// Environment: Xcode 11.1, Swift 5.1, iOS 10.3
deinit {
    // Also tried only either one, no luck
    self.observer?.invalidate() 
    self.observer = nil
}

Swift iOS -View Controller deinit runs when adding it to a new keyWindow


Tag : ios , By : Tink
Date : March 29 2020, 07:55 AM
I hope this helps . I got the answer from this reddit
keyWindow.rootViewController = redVC

Avoid crash when lazy var referencing self is accessed for the first time during deinit


Tag : swift , By : arbeitandy
Date : March 29 2020, 07:55 AM
I hope this helps . I am experiencing a crash related to lazy vars in Swift. The cause of the crash is straightforward to understand, but I don't know of a good way to prevent it without losing the advantages that I gain by using the lazy var. , I just created of what you said like below:
protocol Hello {
    func thisGetsCalledSometimes()
}

class MyService {

    var delegate: Hello?

    init(key: String) {
        debugPrint("Init")
    }

    func start() {
        debugPrint("Service Started")
    }

    func stop() {
        debugPrint("Service Stopped")
    }
}

class MyClass: Hello {

    lazy var service: MyService = {
        // To init and configure this service,
        // we need to reference `self`.
        let service = MyService(key: "") // Just pretend key exists :)
        service.delegate = self
        return service
    }()

    func thisGetsCalledSometimes() {
        // Calling this function causes the lazy var to
        // get initialised.
        self.service.start()
    }

    deinit {
        // If `thisGetsCalledSometimes` was NOT called,
        // this crashes because the initialising closure
        // for `service` references `self`.
        self.service.stop()
    }
}
"Init"
"Service Stopped"
import UIKit

// Stuff to create a view stack:

class ViewController: UINavigationController {
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)

        let firstController = FirstController()
        let navigationController = UINavigationController(rootViewController: firstController)
        self.present(navigationController, animated: false, completion: nil)
    }
}

class FirstController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        let button = UIButton()
        button.setTitle("Next screen", for: .normal)
        button.addTarget(self, action: #selector(onNextScreen), for: .touchUpInside)
        self.view.addSubview(button)
        button.translatesAutoresizingMaskIntoConstraints = false
        button.centerXAnchor.constraint(equalTo: self.view.centerXAnchor).isActive = true
        button.centerYAnchor.constraint(equalTo: self.view.centerYAnchor).isActive = true
    }

    @objc func onNextScreen() {
        let secondController = SecondController()
        self.navigationController?.pushViewController(secondController, animated: true)
    }
}

// The service and view controller where the crash happens:

protocol ServiceDelegate: class {
    func service(_ service: Service, didReceive value: Int)
}

class Service {
    weak var delegate: ServiceDelegate?

    func start() {
        print("Starting")
        self.delegate?.service(self, didReceive: 0)
    }

    func stop() {
        print("Stopping")
    }

    deinit {
        delegate = nil
    }
}

class SecondController: UIViewController {

    private var isServiceAvailable: Bool = false

    private lazy var service: Service = {
        let service = Service()
        service.delegate = self
        //Make the service available
        self.isServiceAvailable = true
        return service
    }()

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
//                service.start() // <- Comment/uncomment to toggle crash
    }

    deinit {
        if self.isServiceAvailable {
            self.service.stop()
        }
    }
}

extension SecondController: ServiceDelegate {
    func service(_ service: Service, didReceive value: Int) {
        print("Value: \(value)")
    }
}

AVAudioSequencer Causes Crash on Deinit/Segue: 'required condition is false: outputNode'


Tag : ios , By : mlapida
Date : March 29 2020, 07:55 AM
I wish this helpful for you This crash can be confusing, and may also output no error message whatsoever to the console if the sequencer's content hasn't been loaded yet. Very unhelpful!
The AVAudioSequencer is indeed the cause of the issue. To fix it, make the sequencer an implicitly unwrapped optional (i.e. add ! to its type) and add explicit instructions to stop & remove it during deinit, before the rest of the object is deinitialized.
class TestAudioClass {

    private var audioEngine: AVAudioEngine
    private var sampler: AVAudioUnitSampler
    private var sequencer: AVAudioSequencer!

    init() {
        self.audioEngine = AVAudioEngine()
        self.sampler = AVAudioUnitSampler()
        audioEngine.attach(sampler)
        audioEngine.connect(sampler, to: audioEngine.mainMixerNode, format: nil)
        self.sequencer = AVAudioSequencer(audioEngine: audioEngine)
        if let fileURL = Bundle.main.url(forResource: "TestMusic", withExtension: "mid") {
            do {
                try sequencer.load(from: fileURL, options: AVMusicSequenceLoadOptions())
            } catch {
                print("Error loading sequencer: \(error.localizedDescription)")
            }
        }
        sequencer.prepareToPlay()
    }

    deinit {
        sequencer.stop()
        sequencer = nil
    }
}

WPF DataGrid, application crash when adding a row


Tag : wpf , By : Ruchi
Date : March 29 2020, 07:55 AM
Related Posts Related QUESTIONS :
  • Convert apple time stamp to Unix time
  • No podspec found for `React-fishhook`
  • How to test touch dialog and perform real in-app purchase?
  • Compiling Metal shaders from source on iOS 13 Simulator gives PCH error
  • conan error:I need to cross build packages for os:iOS with my Macos, but when the first package was done, it broke my cp
  • Update calendar 'start of week' from phones system calendar
  • Xcode is showing some warnings
  • How to remove the default Navigation Bar space in SwiftUI NavigiationView
  • Having trouble integrating multiple pickerviews in the same view
  • SCNNode not in SCNView hierarchy, still showing & getting touches & physics
  • How can I open my SwiftUI app and perform a function using NSUseractivity from within Siri Intent Extension?
  • NSCoding decodeObject always nil
  • Passing data in a segmented Controller?
  • Facing issue in Siri Integration with custom intents
  • ARKit3 Hardware Requirement Clarification
  • ARKit3 How to use TrueDepth camera for face tracking and face meshes of other people?
  • How to discriminate while decoding using Codable Protocol in Swift?
  • 'IPA processing failed' while distributing build in Xcode Beta
  • How to debug a crash which happened when come back from background
  • Synchronising old data with NSPersistentCloudKitContainer
  • iOS app opened from web app with url redirects to Appstore
  • How to change the color of seperator in tableView?
  • Is there a better way to watch for a key-value change?
  • How to make UIBezierPath to fill from the center
  • Why on Xcode 11, UICollectionViewCell changes size as soon as you scroll (I already set size in sizeForItem AtIndexPath:
  • How to scan non LE devices using Swift?
  • Unable to infer closure type in the current context in SwiftUI
  • What is the best way to write common code and use it entire project
  • UISegmentedControl inside UIStackView, segments text not centered - iOS 13
  • Swift & ObjC bridge - cannot find protocol declaration for "WKNavigationDelegate"
  • SwiftUI How to push to next screen when tapping on Button
  • 'NSApp' is unavailable in UIKit for Mac: How to embed Mac only framework in iOS app on macOS?
  • UserDefaults Binding with Toggle in SwiftUI
  • How to create a color with an alpha value using SwiftUI?
  • SwiftUI creates destination views before the user navigates to them
  • Streaming video from https with AVPlayer causes initial delay
  • Tap Action not working when Color is clear SwiftUI
  • SwiftUI NavigationButton: How to navigate to different destinations
  • Supported default light/dark mode colors for Color vs UIColor
  • XCUITest wait for a cell with a specific static text inside it
  • Not able to enable Development mode on iOS 13
  • How to hide the home indicator with SwiftUI?
  • How to write if condition with using label text (Int) values
  • Swift Cannot use instance member within property initializer
  • Issue while getting the frame of the keyboard
  • dynamicMemberLoookup ExpressibleByStringLiteral parameter swift
  • iOS Unity Firebase Messenger Xcode Compile Error: FIRDynamicLinks
  • Firebase Storage Image Cache not updating SWIFT
  • unhandled js exception: application main has not been registered expo TestFlight
  • App freezes on IOS when navigate to another screen - React Navigation
  • How to create haptic feedback for a Button in SwiftUI?
  • How can I achieve automatic scrolling in my text view when text comes down to the keyboard level in Swift?
  • how to get the location with the CLLocationManager every 10 secondes?
  • Calling completion handler of a function from Timer selector function Swift
  • How to make SwiftUI view fullscreen?
  • RAM, JSC, Views, UI and JS usage table appearing whenever I launch my react native app. How to remove this table?
  • Change status bar background color using UIStatusBarManager
  • Should we make tapGesture component an IBAction or IBOutlet to capture the tap event?
  • Iframe automatically goes full screen using Ionic 3.9.2 on iOS
  • How to calculate score out of 1000 given some seconds (In Double)
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com