iOS系统声音列表

简介:

iOS系统声音列表

 

效果

 

说明

1. 点击cell就能发出声音

2. 只需要给出声音编号,就可以,非常简单易用

 

源码

https://github.com/YouXianMing/SystemSound


//
//  SystemSound.h
//  SystemSound
//
//  Created by YouXianMing on 15/8/24.
//  Copyright (c) 2015年 YouXianMing. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "SoundInfomation.h"

@interface SystemSound : NSObject

/**
 *  获取系统消息列表
 */
+ (void)accessSystemSoundsList;

/**
 *  系统声音的列表
 *
 *  @return SoundInfomation对象数组
 */
+ (NSArray *)systemSounds;

/**
 *  播放声音
 *
 *  @param sound 声音
 */
+ (void)playWithSound:(SoundInfomation *)sound;

/**
 *  根据声音ID号播放声音
 *
 *  @param soundID 声音ID号码
 */
+ (void)playWithSoundID:(UInt32)soundID;

@end


//
//  SystemSound.m
//  SystemSound
//
//  Created by YouXianMing on 15/8/24.
//  Copyright (c) 2015年 YouXianMing. All rights reserved.
//

#import "SystemSound.h"
#import <AudioToolbox/AudioToolbox.h>

static NSMutableArray *_systemSounds = nil;

@implementation SystemSound

+ (void)accessSystemSoundsList {

    static dispatch_once_t predicate;
    
    dispatch_once(&predicate, ^{
        
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            
            NSMutableArray *audioFileList = [NSMutableArray array];
            _systemSounds                 = [NSMutableArray array];
            
            // 读取文件系统
            NSFileManager *fileManager  = [[NSFileManager alloc] init];
            NSURL         *directoryURL = [NSURL URLWithString:@"/System/Library/Audio/UISounds"];
            NSArray       *keys         = [NSArray arrayWithObject:NSURLIsDirectoryKey];
            
            NSDirectoryEnumerator *enumerator = [fileManager enumeratorAtURL:directoryURL
                                                  includingPropertiesForKeys:keys
                                                                     options:0
                                                                errorHandler:^(NSURL *url, NSError *error) {
                                                                    return YES;
                                                                }];
            
            for (NSURL *url in enumerator) {
                
                NSError  *error;
                NSNumber *isDirectory = nil;
                if (! [url getResourceValue:&isDirectory forKey:NSURLIsDirectoryKey error:&error]) {
                    
                } else if (![isDirectory boolValue]) {
                    
                    [audioFileList addObject:url];
                    
                    SystemSoundID soundID;
                    AudioServicesCreateSystemSoundID((__bridge_retained CFURLRef)url, &soundID);
                    
                    SoundInfomation *sound = [[SoundInfomation alloc] init];
                    sound.soundID   = soundID;
                    sound.soundUrl  = url;
                    sound.soundName = url.lastPathComponent;
                    
                    [_systemSounds addObject:sound];
                }
            }
            
            // 读取文件
            NSString *path = [[NSBundle mainBundle] pathForResource:@"SystemSoundList" ofType:nil];
            NSData   *data = [[NSData alloc] initWithContentsOfFile:path];
            
            NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
            NSArray  *array  = [string componentsSeparatedByString:@"\n"];
            
            for (int i = 0; i < array.count; i++) {
                
                NSString *tmp = array[i];
                
                NSArray         *soundInfo = [tmp componentsSeparatedByString:@"\t"];
                SoundInfomation *sound     = [[SoundInfomation alloc] init];
                
                sound.soundID   = (unsigned int)[soundInfo[0] integerValue];
                sound.soundName = soundInfo[1];
                [_systemSounds addObject:sound];
            }
        });
    });
}

+ (NSArray *)systemSounds {

    return _systemSounds;
}

+ (void)playWithSound:(SoundInfomation *)sound {

    AudioServicesPlaySystemSound(sound.soundID);
}

+ (void)playWithSoundID:(UInt32)soundID {
    
    AudioServicesPlaySystemSound(soundID);
}

@end


//
//  SoundInfomation.h
//  SystemSound
//
//  Created by YouXianMing on 15/8/24.
//  Copyright (c) 2015年 YouXianMing. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface SoundInfomation : NSObject

/**
 *  系统声音编号(必须有)
 */
@property (nonatomic)         UInt32    soundID;

/**
 *  系统声音地址
 */
@property (nonatomic, strong) NSURL    *soundUrl;

/**
 *  声音的名字
 */
@property (nonatomic, strong) NSString *soundName;


@end


//
//  SoundInfomation.m
//  SystemSound
//
//  Created by YouXianMing on 15/8/24.
//  Copyright (c) 2015年 YouXianMing. All rights reserved.
//

#import "SoundInfomation.h"

@implementation SoundInfomation

@end


new-mail.caf    MailReceived
   mail-sent.caf    MailSent
   Voicemail.caf    VoicemailReceived
   ReceivedMessage.caf    SMSReceived
   SentMessage.caf    SMSSent
   alarm.caf    CalendarAlert
   low_power.caf    LowPower
   sms-received1.caf    SMSReceived_Alert
   sms-received2.caf    SMSReceived_Alert
   sms-received3.caf    SMSReceived_Alert
   sms-received4.caf    SMSReceived_Alert
   -    SMSReceived_Vibrate
   sms-received1.caf    SMSReceived_Alert
   sms-received5.caf    SMSReceived_Alert
   sms-received6.caf    SMSReceived_Alert
   Voicemail.caf    -
   tweet_sent.caf    SMSSent
   Anticipate.caf    SMSReceived_Alert
   Bloom.caf    SMSReceived_Alert
   Calypso.caf    SMSReceived_Alert
   Choo_Choo.caf    SMSReceived_Alert
   Descent.caf    SMSReceived_Alert
   Fanfare.caf    SMSReceived_Alert
   Ladder.caf    SMSReceived_Alert
   Minuet.caf    SMSReceived_Alert
   News_Flash.caf    SMSReceived_Alert
   Noir.caf    SMSReceived_Alert
   Sherwood_Forest.caf    SMSReceived_Alert
   Spell.caf    SMSReceived_Alert
   Suspense.caf    SMSReceived_Alert
   Telegraph.caf    SMSReceived_Alert
   Tiptoes.caf    SMSReceived_Alert
   Typewriters.caf    SMSReceived_Alert
   Update.caf    SMSReceived_Alert
   ussd.caf    USSDAlert
   SIMToolkitCallDropped.caf    SIMToolkitTone
   SIMToolkitGeneralBeep.caf    SIMToolkitTone
   SIMToolkitNegativeACK.caf    SIMToolkitTone
   SIMToolkitPositiveACK.caf    SIMToolkitTone
   SIMToolkitSMS.caf    SIMToolkitTone
   Tink.caf    PINKeyPressed
   ct-busy.caf    AudioToneBusy
   ct-congestion.caf    AudioToneCongestion
   ct-path-ack.caf    AudioTonePathAcknowledge
   ct-error.caf    AudioToneError
   ct-call-waiting.caf    AudioToneCallWaiting
   ct-keytone2.caf    AudioToneKey2
   lock.caf    ScreenLocked
   unlock.caf    ScreenUnlocked
   -    FailedUnlock
   Tink.caf    KeyPressed
   Tock.caf    KeyPressed
   Tock.caf    KeyPressed
   beep-beep.caf    ConnectedToPower
   RingerChanged.caf    RingerSwitchIndication
   photoShutter.caf    CameraShutter
   shake.caf    ShakeToShuffle
   jbl_begin.caf    JBL_Begin
   jbl_confirm.caf    JBL_Confirm
   jbl_cancel.caf    JBL_Cancel
   begin_record.caf    BeginRecording
   end_record.caf    EndRecording
   jbl_ambiguous.caf    JBL_Ambiguous
   jbl_no_match.caf    JBL_NoMatch
   begin_video_record.caf    BeginVideoRecording
   end_video_record.caf    EndVideoRecording
   vc~invitation-accepted.caf    VCInvitationAccepted
   vc~ringing.caf    VCRinging
   vc~ended.caf    VCEnded
   ct-call-waiting.caf    VCCallWaiting
   vc~ringing.caf    VCCallUpgrade
   dtmf-0.caf    TouchTone
   dtmf-1.caf    TouchTone
   dtmf-2.caf    TouchTone
   dtmf-3.caf    TouchTone
   dtmf-4.caf    TouchTone
   dtmf-5.caf    TouchTone
   dtmf-6.caf    TouchTone
   dtmf-7.caf    TouchTone
   dtmf-8.caf    TouchTone
   dtmf-9.caf    TouchTone
   dtmf-star.caf    TouchTone
   dtmf-pound.caf    TouchTone
   long_low_short_high.caf    Headset_StartCall
   short_double_high.caf    Headset_Redial
   short_low_high.caf    Headset_AnswerCall
   short_double_low.caf    Headset_EndCall
   short_double_low.caf    Headset_CallWaitingActions
   middle_9_short_double_low.caf    Headset_TransitionEnd
   Voicemail.caf    SystemSoundPreview
   ReceivedMessage.caf    SystemSoundPreview
   new-mail.caf    SystemSoundPreview
   mail-sent.caf    SystemSoundPreview
   alarm.caf    SystemSoundPreview
   lock.caf    SystemSoundPreview
   Tock.caf    KeyPressClickPreview
   sms-received1.caf    SMSReceived_Selection
   sms-received2.caf    SMSReceived_Selection
   sms-received3.caf    SMSReceived_Selection
   sms-received4.caf    SMSReceived_Selection
   -    SMSReceived_Vibrate
   sms-received1.caf    SMSReceived_Selection
   sms-received5.caf    SMSReceived_Selection
   sms-received6.caf    SMSReceived_Selection
   Voicemail.caf    SystemSoundPreview
   Anticipate.caf    SMSReceived_Selection
   Bloom.caf    SMSReceived_Selection
   Calypso.caf    SMSReceived_Selection
   Choo_Choo.caf    SMSReceived_Selection
   Descent.caf    SMSReceived_Selection
   Fanfare.caf    SMSReceived_Selection
   Ladder.caf    SMSReceived_Selection
   Minuet.caf    SMSReceived_Selection
   News_Flash.caf    SMSReceived_Selection
   Noir.caf    SMSReceived_Selection
   Sherwood_Forest.caf    SMSReceived_Selection
   Spell.caf    SMSReceived_Selection
   Suspense.caf    SMSReceived_Selection
   Telegraph.caf    SMSReceived_Selection
   Tiptoes.caf    SMSReceived_Selection
   Typewriters.caf    SMSReceived_Selection
   Update.caf    SMSReceived_Selection
   -    RingerVibeChanged
   -    SilentVibeChanged
   -    Vibrate


目录
相关文章
|
16天前
|
IDE Android开发 iOS开发
探索安卓与iOS系统的技术差异:开发者的视角
本文深入分析了安卓(Android)与苹果iOS两大移动操作系统在技术架构、开发环境、用户体验和市场策略方面的主要差异。通过对比这两种系统的不同特点,旨在为移动应用开发者提供有价值的见解,帮助他们在不同平台上做出更明智的开发决策。
|
1月前
|
开发工具 Swift 数据安全/隐私保护
移动应用开发之旅:从零到一的iOS系统探索
【9月更文挑战第16天】在数字时代的浪潮中,移动应用成为连接用户与数字世界的桥梁。本文将带你走进iOS移动操作系统的世界,了解其架构、设计理念以及开发环境。我们将通过Swift语言的简单示例,展示如何构建一个基本的iOS应用,并探讨移动应用开发的未来趋势。无论你是编程新手还是资深开发者,这篇文章都将为你提供宝贵的见解和知识。
|
1月前
|
监控 Android开发 iOS开发
深入探索安卓与iOS的系统架构差异:理解两大移动平台的技术根基在移动技术日新月异的今天,安卓和iOS作为市场上最为流行的两个操作系统,各自拥有独特的技术特性和庞大的用户基础。本文将深入探讨这两个平台的系统架构差异,揭示它们如何支撑起各自的生态系统,并影响着全球数亿用户的使用体验。
本文通过对比分析安卓和iOS的系统架构,揭示了这两个平台在设计理念、安全性、用户体验和技术生态上的根本区别。不同于常规的技术综述,本文以深入浅出的方式,带领读者理解这些差异是如何影响应用开发、用户选择和市场趋势的。通过梳理历史脉络和未来展望,本文旨在为开发者、用户以及行业分析师提供有价值的见解,帮助大家更好地把握移动技术发展的脉络。
60 6
|
2月前
|
存储 安全 编译器
我给 iOS 系统打了个补丁——修复 iOS 16 系统键盘重大 Crash
我给 iOS 系统打了个补丁——修复 iOS 16 系统键盘重大 Crash
我给 iOS 系统打了个补丁——修复 iOS 16 系统键盘重大 Crash
|
2月前
|
人工智能 自然语言处理 云计算
iOS迎来AI升级:揭秘Apple全新“智能”系统
iOS迎来AI升级:揭秘Apple全新“智能”系统
iOS迎来AI升级:揭秘Apple全新“智能”系统
|
2月前
|
iOS开发 开发者
iOS 16 系统键盘修复问题之汇编层面模拟两次返回操作的实现如何解决
iOS 16 系统键盘修复问题之汇编层面模拟两次返回操作的实现如何解决
|
2月前
|
安全 Android开发 iOS开发
安卓与iOS的终极对决:哪个系统更适合你?
在智能手机的世界里,安卓和iOS两大操作系统如同两座巍峨的山峰,各自拥有庞大的用户群体。本文将深入浅出地探讨这两个系统的优缺点,并帮助你找到最适合自己的那一款。让我们一起揭开这场技术盛宴的序幕吧!
|
iOS开发
iOS调用系统通讯录
iOS调用系统通讯录
220 0
iOS调用系统通讯录