#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioToolbox.h>
@interface View22 : UIViewController <UITableViewDelegate, UITableViewDataSource>
{
}
@end
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row==0) {
cell.textLabel.text=@"振动";
}
else if(indexPath.row==1)
{
cell.textLabel.text=@"系统铃声";
}
return cell;
}
void SystemSoundsDemoCompleti
SystemSoundID
void
{
AudioServicesDisposeSyst
};
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
SystemSoundID soundID;
OSStatus err = kAudioServicesNoError;
if (indexPath.row == 0) {
soundID = kSystemSoundID_Vibrate;
} else {
// 查找音乐文件
NSString *cafPath =
[[NSBundle mainBundle] pathForResource:@"2" ofType:@"caf"];
NSURL *cafURL = [NSURL fileURLWithPath:cafPath];
err = AudioServicesCreateSyste
}
if (err == kAudioServicesNoError) {
err = AudioServicesAddSystemSo
(soundID,
NULL,
NULL,
SystemSoundsDemoCompleti
self
);
AudioServicesPlaySystemS
}
if (err != kAudioServicesNoError) {
CFErrorRef error = CFErrorCreate(NULL, kCFErrorDomainOSStatus, err, NULL);
NSString *errorDesc = (NSString*) CFErrorCopyDescription (error);
UIAlertView *cantPlayAlert =
[[UIAlertView alloc] initWithTitle:@"Cannot Play:"
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[cantPlayAlert show];
[cantPlayAlert release];
[errorDesc release];
CFRelease (error);
}
}