使用系統默認聲音、震動

#import <UIKit/UIKit.h>  
#import <AudioToolbox/AudioToolbox.h>  
  
@interface MsgPlaySound : NSObject  
{  
    SystemSoundID sound;//系統聲音的id 取值範圍爲:1000-2000  
}  
- (id)initSystemShake;//系統 震動  
- (id)initSystemSoundWithName:(NSString *)soundName SoundType:(NSString *)soundType;//初始化系統聲音  
- (void)play;//播放  
@end
#import "MsgPlaySound.h"  
  
@implementation MsgPlaySound  
  
- (id)initSystemShake  
{  
    self = [super init];  
    if (self) {  
        sound = kSystemSoundID_Vibrate;//震動  
    }  
    return self;  
}  
  
- (id)initSystemSoundWithName:(NSString *)soundName SoundType:(NSString *)soundType  
{  
    self = [super init];  
    if (self) {  
        NSString *path = [NSString stringWithFormat:@"/System/Library/Audio/UISounds/%@.%@",soundName,soundType];  
        //[[NSBundle bundleWithIdentifier:@"com.apple.UIKit" ]pathForResource:soundName ofType:soundType];//獲得蘋果框架資源UIKit.framework ,從中取出所要播放的系統聲音的路徑  
        //[[NSBundle mainBundle] URLForResource: @"tap" withExtension: @"aif"];  獲取自定義的聲音  
        if (path) {  
            OSStatus error = AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path],&sound);  
              
            if (error != kAudioServicesNoError) {//獲取的聲音的時候,出現錯誤  
                sound = nil;  
            }  
        }  
    }  
    return self;  
}  
  
- (void)play  
{  
    AudioServicesPlaySystemSound(sound);  
}
1.聲音格式是MP3或m4r的須要轉成caf格式(可先轉成aif , aiff,而後修改後綴)
2.路徑在/System/Library/Audio/UISounds 裏,須要更改的能夠根據如下列表進行替換
3詳細列表:
信息 
ReceivedMessage.caf--收到信息,僅在短信界面打開時播放。 
sms-received1.caf-------三全音 
sms-received2.caf-------管鐘琴 
sms-received3.caf-------玻璃 
sms-received4.caf-------圓號 
sms-received5.caf-------鈴聲 
sms-received6.caf-------電子樂 
SentMessage.caf--------發送信息 

郵件 
mail-sent.caf----發送郵件 
new-mail.caf-----收到新郵件 

電話 
dtmf-0.caf----------撥號面板0按鍵 
dtmf-1.caf----------撥號面板1按鍵 
dtmf-2.caf----------撥號面板2按鍵 
dtmf-3.caf----------撥號面板3按鍵 
dtmf-4.caf----------撥號面板4按鍵 
dtmf-5.caf----------撥號面板5按鍵 
dtmf-6.caf----------撥號面板6按鍵 
dtmf-7.caf----------撥號面板7按鍵 
dtmf-8.caf----------撥號面板8按鍵 
dtmf-9.caf----------撥號面板9按鍵 
dtmf-pound.caf---撥號面板#按鍵 
dtmf-star.caf------撥號面板*按鍵 
Voicemail.caf-----新語音郵件 

輸入設備聲音提示 
Tock.caf-----------------------點擊鍵盤 
begin_record.caf-----------開始錄音 
begin_video_record.caf--開始錄像 
photoShutter.caf------------快門聲 
end_record.caf--------------結束錄音 
end_video_record.caf-----結束錄像 

其餘 
beep-beep.caf--充電、註銷及鏈接電腦 
lock.caf------------鎖定手機 
shake.caf---------「這個還沒搞清楚」 
unlock.caf--------滑動解鎖 
low_power.caf--低電量提示 

語音控制 
jbl_ambiguous.caf--找到多個匹配 
jbl_begin.caf------等待用戶的輸入 
jbl_cancel.caf-----取消 
jbl_confirm.caf----執行 
jbl_no_match.caf---沒有找到匹配 

日曆 
alarm.caf--日曆提醒 

iPod Touch 1G 
sq_alarm.caf 
sq_beep-beep.caf 
sq_lock.caf 
sq_tock.caf
相關文章
相關標籤/搜索