我想用 AVAudioPlayer 播放声音文件,但我的调整让我进入安全模式。
这是我的代码:
#import <SpringBoard/SpringBoard.h>
#import <AVFoundation/AVAudioPlayer.h>
%hook SpringBoard
- (void)applicationDidFinishLaunching:(id)application {
NSString *settingsPath = @"/var/mobile/Library/Preferences/com.ziph0n.vibrateonstart.plist";
NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:settingsPath];
BOOL enabled = [[prefs objectForKey:@"enabled"] boolValue];
BOOL sound = [[prefs objectForKey:@"sound"] boolValue];
if (enabled) {
if (sound) {
%orig;
SystemSoundID mBeep;
NSString* path = [[NSBundle mainBundle] pathForResource:@"beep-beep" ofType:@"caf"];;
NSURL* url = [NSURL fileURLWithPath:path]; AudioServicesCreateSystemSoundID((__bridge CFURLRef)url, &mBeep);
AudioServicesPlaySystemSound(mBeep);
}
}
}
%end
我的音频文件位于 Ressources 文件夹中