Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is this Objective C code in swift?

I have found a solution to my problem, but the code is in Objective C. Please could someone tell me what this is in swift?

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

Thanks.

like image 751
D-A UK Avatar asked Mar 07 '26 02:03

D-A UK


1 Answers

Try this :

do {
       try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
       try AVAudioSession.sharedInstance().setActive(true)
       UIApplication.shared.beginReceivingRemoteControlEvents()

   }catch{
        print("error")
   }

And further, if you need to convert any code from Objective C to Swift you can convert by using the following Link.

https://objectivec2swift.com

like image 137
Nikunj Kumbhani Avatar answered Mar 09 '26 22:03

Nikunj Kumbhani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!