我想静音铃声音量。所以我使用这个链接来做到这一点 -如何禁用 iOS 系统声音 但是如果我使用代码:
- (void) setSystemVolumeLevelTo:(float)newVolumeLevel
{
Class avSystemControllerClass = NSClassFromString(@"AVSystemController");
id avSystemControllerInstance = [avSystemControllerClass performSelector:@selector(sharedAVSystemController)];
NSString *soundCategory = @"Ringtone";
NSInvocation *volumeInvocation = [NSInvocation invocationWithMethodSignature:
[avSystemControllerClass instanceMethodSignatureForSelector:
@selector(setVolumeTo:forCategory:)]];
[volumeInvocation setTarget:avSystemControllerInstance];
[volumeInvocation setSelector:@selector(setVolumeTo:forCategory:)];
[volumeInvocation setArgument:&newVolumeLevel atIndex:2];
[volumeInvocation setArgument:&soundCategory atIndex:3];
[volumeInvocation invoke];
}
它崩溃了
NSInvocation *volumeInvocation = [NSInvocation invocationWithMethodSignature:
[avSystemControllerClass instanceMethodSignatureForSelector:
@selector(setVolumeTo:forCategory:)]];
因为返回的值为零。
如果我导入框架等然后使用此代码
[[AVSystemController sharedAVSystemController] setVolumeTo:0.0 forCategory:@"Ringtone"];
它没有运行给我以下错误:
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_AVSystemController", referenced from:
objc-class-ref in SettingsViewController.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
有人请指导我哪里出错了。