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


目录
相关文章
|
2月前
|
安全 Android开发 数据安全/隐私保护
深入探讨iOS与Android系统安全性对比分析
在移动操作系统领域,iOS和Android无疑是两大巨头。本文从技术角度出发,对这两个系统的架构、安全机制以及用户隐私保护等方面进行了详细的比较分析。通过深入探讨,我们旨在揭示两个系统在安全性方面的差异,并为用户提供一些实用的安全建议。
|
23天前
|
存储 监控 API
app开发之安卓Android+苹果ios打包所有权限对应解释列表【长期更新】-以及默认打包自动添加权限列表和简化后的基本打包权限列表以uniapp为例-优雅草央千澈
app开发之安卓Android+苹果ios打包所有权限对应解释列表【长期更新】-以及默认打包自动添加权限列表和简化后的基本打包权限列表以uniapp为例-优雅草央千澈
|
2月前
|
传感器 iOS开发 UED
探索iOS生态系统:从App Store优化到用户体验提升
本文旨在深入探讨iOS生态系统的多个方面,特别是如何通过App Store优化(ASO)和改进用户体验来提升应用的市场表现。不同于常规摘要仅概述文章内容的方式,我们将直接进入主题,首先介绍ASO的重要性及其对开发者的意义;接着分析当前iOS平台上用户行为的变化趋势以及这些变化如何影响应用程序的设计思路;最后提出几点实用建议帮助开发者更好地适应市场环境,增强自身竞争力。
|
2月前
|
安全 Android开发 数据安全/隐私保护
深入探索Android与iOS系统安全性的对比分析
在当今数字化时代,移动操作系统的安全已成为用户和开发者共同关注的重点。本文旨在通过比较Android与iOS两大主流操作系统在安全性方面的差异,揭示两者在设计理念、权限管理、应用审核机制等方面的不同之处。我们将探讨这些差异如何影响用户的安全体验以及可能带来的风险。
74 10
|
2月前
|
安全 Android开发 iOS开发
深入探讨Android与iOS系统的差异及未来发展趋势
本文旨在深入分析Android和iOS两大移动操作系统的核心技术差异、用户体验以及各自的市场表现,进一步探讨它们在未来技术革新中可能的发展方向。通过对比两者的开放性、安全性、生态系统等方面,本文揭示了两大系统在移动设备市场中的竞争态势和潜在变革。
|
2月前
|
存储 安全 算法
深入探索iOS系统安全机制:保护用户隐私的前沿技术
本文旨在探讨苹果公司在其广受欢迎的iOS操作系统中实施的先进安全措施,这些措施如何共同作用以保护用户的隐私和数据安全。我们将深入了解iOS的安全架构,包括其硬件和软件层面的创新,以及苹果如何通过持续的软件更新来应对新兴的安全威胁。此外,我们还将讨论iOS系统中的一些关键安全功能,如Face ID、加密技术和沙箱环境,以及它们如何帮助防止未经授权的访问和数据泄露。
|
2月前
|
安全 数据安全/隐私保护 Android开发
深入探索iOS系统安全机制:从基础到高级
本文旨在全面解析iOS操作系统的安全特性,从基础的权限管理到高级的加密技术,揭示苹果如何构建一个既开放又安全的移动平台。我们将通过实例和分析,探讨iOS系统如何保护用户数据免受恶意软件、网络攻击的威胁,并对比Android系统在安全性方面的差异。
|
2月前
|
安全 Android开发 iOS开发
深入探索iOS与Android系统的差异性及优化策略
在当今数字化时代,移动操作系统的竞争尤为激烈,其中iOS和Android作为市场上的两大巨头,各自拥有庞大的用户基础和独特的技术特点。本文旨在通过对比分析iOS与Android的核心差异,探讨各自的优势与局限,并提出针对性的优化策略,以期为用户提供更优质的使用体验和为开发者提供有价值的参考。
|
12天前
|
iOS开发 开发者
uniapp开发ios打包Error code = -5000 Error message: Error: certificate file(p12) import failed!报错问题如何解决
uniapp开发ios打包Error code = -5000 Error message: Error: certificate file(p12) import failed!报错问题如何解决
107 67
uniapp开发ios打包Error code = -5000 Error message: Error: certificate file(p12) import failed!报错问题如何解决
|
2月前
|
开发框架 前端开发 Android开发
安卓与iOS开发中的跨平台策略
在移动应用开发的战场上,安卓和iOS两大阵营各据一方。随着技术的演进,跨平台开发框架成为开发者的新宠,旨在实现一次编码、多平台部署的梦想。本文将探讨跨平台开发的优势与挑战,并分享实用的开发技巧,帮助开发者在安卓和iOS的世界中游刃有余。