gpt4 book ai didi

ios - 禁用 iOS 系统声音的 AVSystemController 未找到架构 i386 错误

转载 作者:行者123 更新时间:2023-11-28 22:11:06 25 4
gpt4 key购买 nike

我想让铃声静音。所以我使用这个链接来做到这一点 - How to disable iOS System Sounds但是如果我使用代码:

- (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:)]];

因为返回的值为nil。

如果我导入框架等然后使用此代码

[[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)

有人请指导我哪里出错了。

最佳答案

您所要做的就是在第一个方法中添加以下几行。由于您使用的是私有(private)框架 (Celestial),因此您必须在运行时导入它。

NSBundle *bundle = [NSBundle bundleWithPath:@"/System/Library/PrivateFrameworks/Celestial.framework"];
BOOL success = [bundle load];

关于ios - 禁用 iOS 系统声音的 AVSystemController 未找到架构 i386 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22895485/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com