I don't know how to rewrite the recording process from Objective-C to Swift.

Asked 2 years ago, Updated 2 years ago, 31 views

I am currently recording audio, but I do not understand the following rewriting.
If there is anyone who can tell me, I would appreciate your guidance.

// Is your model compatible with recording?
if([audioSession inputIsAvailable]) {
    AudioSession setCategory:AVAudioSessionCategoryPlayAndRecord error: & error;
}
if error {
    NSLog(@"audioSession: %@%d%@", error domain , error code , [error userInfo] description);
}

swift

2022-09-30 19:21

1 Answers

How about like this?
(Verified by Xcode 7.0.1)

let audioSession=AVAudioSession.sharedInstance()

// InputIsAvailable is deprecated, so use inputAvailable
if audioSession.inputAvailable {

    // NSError handling changed to do/try/catch on Swift2
    do{
        tryaudioSession.setCategory (AVAudioSessionCategoryPlayAndRecord)

    } catchleterr{

        // Swift2 uses print instead of NSLog
        print("audioSession:\(err)")
    }
}


2022-09-30 19:21

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.