| Lift freeq's AV media plane out of sleek 90f8b89 nandi 20d ago | 1 | // |
| 2 | // AppDelegate.m |
| 3 | // cpal-ios-example |
| 4 | // |
| 5 | // Created by Michael Hills on 2/10/20. |
| 6 | // |
| 7 | |
| 8 | #import "AppDelegate.h" |
| 9 | @import AVFoundation; |
| 10 | |
| 11 | void rust_ios_main(void); |
| 12 | |
| 13 | |
| 14 | @interface AppDelegate () |
| 15 | |
| 16 | @end |
| 17 | |
| 18 | @implementation AppDelegate |
| 19 | |
| 20 | |
| 21 | |
| 22 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { |
| 23 | // Override point for customization after application launch. |
| 24 | |
| 25 | // It is necessary to access the sharedInstance so that calls to AudioSessionGetProperty |
| 26 | // will work. |
| 27 | AVAudioSession *session = AVAudioSession.sharedInstance; |
| 28 | // Setting up the category is not necessary, but generally advised. |
| 29 | // Since this demo records and plays, lets use AVAudioSessionCategoryPlayAndRecord. |
| 30 | // Also default to speaker as defaulting to the phone earpiece would be unusual. |
| 31 | // Allowing bluetooth should direct audio to your bluetooth headset. |
| 32 | NSError *categoryError = nil; |
| 33 | BOOL isSetCategorySuccess = [session setCategory:AVAudioSessionCategoryPlayAndRecord |
| 34 | withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker | AVAudioSessionCategoryOptionAllowBluetooth |
| 35 | error:&categoryError]; |
| 36 | if (isSetCategorySuccess) { |
| 37 | NSError *activateError = nil; |
| 38 | BOOL isActivateSuccess = [session setActive:YES error:&activateError]; |
| 39 | |
| 40 | if (isActivateSuccess) { |
| 41 | NSLog(@"Calling rust_ios_main()"); |
| 42 | rust_ios_main(); |
| 43 | } else { |
| 44 | NSLog(@"Failed to activate audio session: %@", activateError); |
| 45 | } |
| 46 | } else { |
| 47 | NSLog(@"Failed to set category: %@", categoryError); |
| 48 | } |
| 49 | |
| 50 | return YES; |
| 51 | } |
| 52 | |
| 53 | @end |