IPhone 系统声音API(短音 震动)
IPhone
#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioToolbox.h>
@interface SoundViewController : UIViewController {
}
-(IBAction) buttonPressed;
@end
#import “SoundViewController.h”
@implementation SoundViewController
– (void)didReceiveMemoryWarning {
// Releases the view if it doesn’t have a superview.
// Release any cached data, images, etc that aren’t in use.
}
– (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
– (void)dealloc {
}
-(IBAction) buttonPressed {
NSString *path = [[NSBundle mainBundle] pathForResource:@”懒猪起床” ofType:@”caf”];
NSURL *url = [NSURL fileURLWithPath:path];
SystemSoundID outSystemSoundID;
AudioServicesCreateSystemSoundID((__bridge CFURLRef)url,&outSystemSoundID);
//播放声音
AudioServicesPlaySystemSound(outSystemSoundID);
//播放震动
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
@end