turn from: http://blog.csdn.net/like7xiaoben/article/details/9001806
To import a frame:
Code:
[CPP] View plain copy #import <UIKit/UIKit.h> #import <AudioToolbox/AudioToolbox.h> @interface Msgpla Ysound:nsobject {Systemsoundid sound;//system sound ID range is: 1000-2000}-(ID) initsystemshake;//System vibration-(ID) init Systemsoundwithname: (NSString *) soundname soundtype: (NSString *) soundtype;//Initialize system sound-(void) play;//playback @end
[cpp] View plain copy #import "MsgPlaySound.h" @implementation msgplaysound - (ID) initsystemshake { self = [super init]; if (self) { sound = ksystemsoundid_vibrate;//Vibration } return self; } - (ID) initsystemsoundwithname: (nsstring *) Soundname soundtype: (nsstring *) SoundType { self = [super init]; if (self) { nsstring * path = [nsstring stringwithformat:@ "/system/library/audio/uisounds/%@.%@", SoundName,soundType]; &nbsP //[[nsbundle bundlewithidentifier:@ "Com.apple.UIKit" ]pathforresource:soundname oftype:soundtype];//get the Apple Framework resource uikit.framework , remove the path of the system sound to play //[[NSBundle mainBundle] URLForResource: @ "tap" withextension: @ "AIF"]; get custom sound if (path) { osstatus error = audioservicescreatesystemsoundid ((CFURLREF) [NSURL Fileurlwithpath:path],&sound); if (Error != kaudioservicesnoerror) {//Get the sound when the error occurred sound = nil; } &