用于禁用iOS系统声音的AVSystemController没有找到架构i386错误

时间:2014-04-06 14:38:53

标签: ios architecture avsystemcontroller

我想要保持铃声音量。 所以我使用这个链接来做到这一点 - 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)

有人请指导我出错的地方。

1 个答案:

答案 0 :(得分:2)

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

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