GithubHelp home page GithubHelp logo

SwiftUI lifecycle about cookbook HOT 5 CLOSED

audiokit avatar audiokit commented on August 22, 2024
SwiftUI lifecycle

from cookbook.

Comments (5)

aure avatar aure commented on August 22, 2024 1

You should be able to do this on your main ContentView() onAppear block.

from cookbook.

genedelisa avatar genedelisa commented on August 22, 2024 1
import SwiftUI
import AVFoundation

@main
struct AVApp: App {
    
    #if os(macOS)
    @NSApplicationDelegateAdaptor(macOSNSAppDelegate.self) var appDelegate: NSAppDelegate
    #endif
    
    #if os(iOS)
    @UIApplicationDelegateAdaptor(iOSAppDelegate.self) var appDelegate
    #endif
    
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
    
}

#if os(iOS)
class iOSAppDelegate: UIResponder, UIApplicationDelegate {
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        
        do {
            try AVAudioSession.sharedInstance().setPreferredIOBufferDuration(1) // whatever
            try AVAudioSession.sharedInstance().setCategory(.playAndRecord,
                                                            options: [.defaultToSpeaker, .mixWithOthers])
            try AVAudioSession.sharedInstance().setActive(true)
        } catch let err {
            print(err)
        }
        return true
    }
}
#endif

#if os(macOS)
class macOSNSAppDelegate: NSObject, NSApplicationDelegate {
}
#endif

from cookbook.

aure avatar aure commented on August 22, 2024 1

Really depends on your application. It used to be that we wholeheartedly recommended one Conductor app for technical reasons, but now I just think it keeps things simpler.

from cookbook.

aure avatar aure commented on August 22, 2024

Thanks for the pointers @genedelisa

from cookbook.

transat avatar transat commented on August 22, 2024

Another quick question: in general is it preferable to initialise a Conductor class here and share it everywhere in the app or to have individual Conductors for each view, as per the Cookbook examples?

from cookbook.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.