iOS 收到推送後,播放聲音

收到推送後,播放聲音:

首先添加頭文件

 #import <AudioToolbox/AudioToolbox.h>


<一> 自定義音效

//音效文件路徑

 NSString *path = [[NSBundlemainBundle] pathForResource:@"new_order"ofType:@"wav"];

//組裝並播放音效

 SystemSoundID soundID;

 NSURL *filePath = [NSURLfileURLWithPath:path isDirectory:NO];

 AudioServicesCreateSystemSoundID((__bridgeCFURLRef)filePath, &soundID);

 AudioServicesPlaySystemSound(soundID);


//聲音停止

 AudioServicesDisposeSystemSoundID(soundID);


<二> 系統音效

  AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);







發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章