如果iOS 7 SDK,在SpringBoard.app端有一个名为lock.aiff的声音文件.声音文件的路径如下.
iPhoneSimulator7.0.sdk/System/Library/CoreServices/SpringBoard.app/lock.aiffs
这是我的代码.
NSString *path = [[NSBundle bundleWithIdentifier:@"com.apple.UIKit"] bundlePath]; NSString *frameworkPath = [path stringByDeletingLastPathComponent]; NSString *libraryPath = [frameworkPath stringByDeletingLastPathComponent]; NSString *finalePath = [libraryPath stringByAppendingString:@"/CoreServices/SpringBoard.app/lock.aiff"]; NSURL *fileURL = [NSURL fileURLWithPath:finalePath]; SystemSoundID soundID; AudioServicesCreateSystemSoundID((__bridge_retained CFURLRef)fileURL,&soundID); AudioServicesPlaySystemSound(soundID);
Value of the variable finalePath = "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk/System/Library/CoreServices/SpringBoard.app/lock.aiff"
但我无法在模拟器上播放此声音文件.另外,我无法播放SpringBoard.app中的任何声音文件.但我可以成功播放任何其他文件.例如,以下位置的声音文件播放效果很好.
iPhoneSimulator7.0.sdk/System/Library/PrivateFrameworks/AOSNotification.framework/findme_alarm_2.aiff
我的猜测是因为lock.aiffs在SpringBoard.app中,所以会引起某种问题.所以我怎样才能播放lock.aiff文件.
由于iOS应用程序的沙盒特性,您无法访问其他应用程序包中的资源.
但是,您可以播放系统声音,例如锁定声音,如下所示:
NSURL *fileURL = [NSURL URLWithString:@"/System/Library/Audio/UISounds/lock.caf"]; SystemSoundID soundID; AudioServicesCreateSystemSoundID((__bridge_retained CFURLRef)fileURL,&soundID); AudioServicesPlaySystemSound(soundID);
以下是您可以访问的iOS 7.0.2系统声音的完整列表:
/System/Library/Audio/UISounds/Modern/airdrop_invite.caf /System/Library/Audio/UISounds/Modern/calendar_alert_chord.caf /System/Library/Audio/UISounds/Modern/camera_shutter_burst.caf /System/Library/Audio/UISounds/Modern/camera_shutter_burst_begin.caf /System/Library/Audio/UISounds/Modern/camera_shutter_burst_end.caf /System/Library/Audio/UISounds/Modern/sms_alert_aurora.caf /System/Library/Audio/UISounds/Modern/sms_alert_bamboo.caf /System/Library/Audio/UISounds/Modern/sms_alert_circles.caf /System/Library/Audio/UISounds/Modern/sms_alert_complete.caf /System/Library/Audio/UISounds/Modern/sms_alert_hello.caf /System/Library/Audio/UISounds/Modern/sms_alert_input.caf /System/Library/Audio/UISounds/Modern/sms_alert_keys.caf /System/Library/Audio/UISounds/Modern/sms_alert_note.caf /System/Library/Audio/UISounds/Modern/sms_alert_popcorn.caf /System/Library/Audio/UISounds/Modern/sms_alert_synth.caf /System/Library/Audio/UISounds/New/Anticipate.caf /System/Library/Audio/UISounds/New/Bloom.caf /System/Library/Audio/UISounds/New/Calypso.caf /System/Library/Audio/UISounds/New/Choo_Choo.caf /System/Library/Audio/UISounds/New/Descent.caf /System/Library/Audio/UISounds/New/Fanfare.caf /System/Library/Audio/UISounds/New/Ladder.caf /System/Library/Audio/UISounds/New/Minuet.caf /System/Library/Audio/UISounds/New/News_Flash.caf /System/Library/Audio/UISounds/New/Noir.caf /System/Library/Audio/UISounds/New/Sherwood_Forest.caf /System/Library/Audio/UISounds/New/Spell.caf /System/Library/Audio/UISounds/New/Suspense.caf /System/Library/Audio/UISounds/New/Telegraph.caf /System/Library/Audio/UISounds/New/Tiptoes.caf /System/Library/Audio/UISounds/New/Typewriters.caf /System/Library/Audio/UISounds/New/Update.caf /System/Library/Audio/UISounds/ReceivedMessage.caf /System/Library/Audio/UISounds/RingerChanged.caf /System/Library/Audio/UISounds/SIMToolkitCallDropped.caf /System/Library/Audio/UISounds/SIMToolkitGeneralBeep.caf /System/Library/Audio/UISounds/SIMToolkitNegativeACK.caf /System/Library/Audio/UISounds/SIMToolkitPositiveACK.caf /System/Library/Audio/UISounds/SIMToolkitSMS.caf /System/Library/Audio/UISounds/SentMessage.caf /System/Library/Audio/UISounds/Swish.caf /System/Library/Audio/UISounds/Tink.caf /System/Library/Audio/UISounds/Tock.caf /System/Library/Audio/UISounds/Voicemail.caf /System/Library/Audio/UISounds/alarm.caf /System/Library/Audio/UISounds/beep-beep.caf /System/Library/Audio/UISounds/begin_record.caf /System/Library/Audio/UISounds/begin_video_record.caf /System/Library/Audio/UISounds/ct-busy.caf /System/Library/Audio/UISounds/ct-call-waiting.caf /System/Library/Audio/UISounds/ct-congestion.caf /System/Library/Audio/UISounds/ct-error.caf /System/Library/Audio/UISounds/ct-keytone2.caf /System/Library/Audio/UISounds/ct-path-ack.caf /System/Library/Audio/UISounds/dtmf-0.caf /System/Library/Audio/UISounds/dtmf-1.caf /System/Library/Audio/UISounds/dtmf-2.caf /System/Library/Audio/UISounds/dtmf-3.caf /System/Library/Audio/UISounds/dtmf-4.caf /System/Library/Audio/UISounds/dtmf-5.caf /System/Library/Audio/UISounds/dtmf-6.caf /System/Library/Audio/UISounds/dtmf-7.caf /System/Library/Audio/UISounds/dtmf-8.caf /System/Library/Audio/UISounds/dtmf-9.caf /System/Library/Audio/UISounds/dtmf-pound.caf /System/Library/Audio/UISounds/dtmf-star.caf /System/Library/Audio/UISounds/end_record.caf /System/Library/Audio/UISounds/end_video_record.caf /System/Library/Audio/UISounds/jbl_ambiguous.caf /System/Library/Audio/UISounds/jbl_begin.caf /System/Library/Audio/UISounds/jbl_cancel.caf /System/Library/Audio/UISounds/jbl_confirm.caf /System/Library/Audio/UISounds/jbl_no_match.caf /System/Library/Audio/UISounds/lock.caf /System/Library/Audio/UISounds/long_low_short_high.caf /System/Library/Audio/UISounds/low_power.caf /System/Library/Audio/UISounds/mail-sent.caf /System/Library/Audio/UISounds/middle_9_short_double_low.caf /System/Library/Audio/UISounds/new-mail.caf /System/Library/Audio/UISounds/photoShutter.caf /System/Library/Audio/UISounds/shake.caf /System/Library/Audio/UISounds/short_double_high.caf /System/Library/Audio/UISounds/short_double_low.caf /System/Library/Audio/UISounds/short_low_high.caf /System/Library/Audio/UISounds/sms-received1.caf /System/Library/Audio/UISounds/sms-received2.caf /System/Library/Audio/UISounds/sms-received3.caf /System/Library/Audio/UISounds/sms-received4.caf /System/Library/Audio/UISounds/sms-received5.caf /System/Library/Audio/UISounds/sms-received6.caf /System/Library/Audio/UISounds/sq_alarm.caf /System/Library/Audio/UISounds/sq_beep-beep.caf /System/Library/Audio/UISounds/sq_lock.caf /System/Library/Audio/UISounds/sq_tock.caf /System/Library/Audio/UISounds/tweet_sent.caf /System/Library/Audio/UISounds/unlock.caf /System/Library/Audio/UISounds/ussd.caf /System/Library/Audio/UISounds/vc~ended.caf /System/Library/Audio/UISounds/vc~invitation-accepted.caf /System/Library/Audio/UISounds/vc~ringing.caf