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