Awalz / SwiftyCam

A Snapchat Inspired iOS Camera Framework written in Swift
BSD 2-Clause "Simplified" License
2.08k stars 326 forks source link

'setCategory(_:with:)' is unavailable in Swift 4.2 and xcode 10 #187

Closed vishalkalola1 closed 5 years ago

vishalkalola1 commented 6 years ago

//try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playAndRecord, with: [.duckOthers, .defaultToSpeaker])

without this method audio not record.

isandeepj commented 6 years ago

Hello, Vishal

Please add this line for swift 4.2 in your projects.

if #available(iOS 10.0, *) {
                try AVAudioSession.sharedInstance().setCategory(.playAndRecord, mode: .default, options: [.duckOthers, .defaultToSpeaker])
            } else {
                try AVAudioSessionPatch.setSession(AVAudioSession.sharedInstance(), category: .playAndRecord, with: [.defaultToSpeaker, .duckOthers])
            }

Make AVAudioSessionPatch objective-c file.

Add this code the in AVAudioSessionPatch.h

+ (BOOL)setSession:(AVAudioSession *)session category:(AVAudioSessionCategory)category withOptions:(AVAudioSessionCategoryOptions)options error:(__autoreleasing NSError **)outError;

And in AVAudioSessionPatch.m

+ (BOOL)setSession:(AVAudioSession *)session category:(AVAudioSessionCategory)category withOptions:(AVAudioSessionCategoryOptions)options error:(__autoreleasing NSError **)outError {
    return [session setCategory:category withOptions:options error:outError];
}

import the #import "AVAudioSessionPatch.h" in your project Bridging-Header files.

Thanks