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


目录
相关文章
|
29天前
|
搜索推荐 Android开发 iOS开发
安卓与iOS系统的用户界面设计对比分析
本文通过对安卓和iOS两大操作系统的用户界面设计进行对比分析,探讨它们在设计理念、交互方式、视觉风格等方面的差异及各自特点,旨在帮助读者更好地理解和评估不同系统的用户体验。
20 1
|
2月前
|
搜索推荐 Android开发 iOS开发
探析安卓与iOS系统的优劣
【2月更文挑战第7天】安卓与iOS是当今手机市场上最主流的两款操作系统,各有优劣。本文将从用户体验、开放程度、生态系统等方面对两者进行深入探析,以期帮助读者更好地了解它们的特点。
|
2月前
|
Android开发 数据安全/隐私保护 iOS开发
安卓与iOS系统的发展趋势与比较分析
【2月更文挑战第6天】 在移动互联网时代,安卓和iOS系统作为两大主流移动操作系统,各自呈现出不同的发展趋势。本文将从技术角度出发,对安卓和iOS系统的发展方向、特点及未来趋势进行比较分析,以期为读者提供更深入的了解和思考。
35 4
|
5月前
|
JSON 小程序 Android开发
小程序列表左滑效果在IOS呈上下滑动影响样式
小程序列表左滑效果在IOS呈上下滑动影响样式
97 0
|
1月前
|
机器学习/深度学习 测试技术 API
iOS系统下轻松构建自动化数据收集流程
iOS系统下轻松构建自动化数据收集流程
26 0
|
1月前
|
搜索推荐 安全 Android开发
安卓与iOS系统的用户体验比较
【2月更文挑战第11天】 在当今移动设备市场上,安卓和iOS系统一直是两大主流操作系统。本文将从用户界面设计、应用生态、系统定制性等方面对安卓和iOS系统进行比较分析,旨在探讨两者的优势和劣势,为用户选择合适的操作系统提供参考。
|
2月前
|
人工智能 vr&ar Android开发
探索安卓与iOS系统的发展趋势
【2月更文挑战第9天】 过去,人们对于安卓和iOS系统的争论主要集中在性能、用户体验和生态系统的比较上。然而,随着移动互联网的快速发展,两大操作系统在人工智能、物联网、安全性等方面的发展趋势也备受关注。本文将探讨安卓与iOS系统在技术发展方面的差异以及未来的发展趋势。
|
2月前
|
搜索推荐 Android开发 iOS开发
探讨安卓与iOS系统的用户体验差异
【2月更文挑战第7天】 在当今移动互联网时代,安卓和iOS系统是最受欢迎的手机操作系统。本文将从用户界面设计、应用生态系统、定制性能等方面探讨安卓与iOS系统的用户体验差异,为读者提供更深入的了解。
|
2月前
|
安全 开发工具 Android开发
安卓与iOS系统的优缺点比较
【2月更文挑战第6天】 安卓和iOS是目前市场上最流行的两种操作系统。虽然它们都拥有自己的独特之处,但它们也有一些共同之处。本文将探讨这两种操作系统的优缺点,并对它们进行比较。
|
2月前
|
搜索推荐 安全 Android开发
探索安卓与iOS系统的差异与共通之道
【2月更文挑战第4天】安卓与iOS作为当前主流的移动操作系统,各自拥有独特的特性和功能。本文将深入探讨安卓和iOS系统的差异,并提出一些共通之道,帮助读者更好地了解和应用这两个系统。