AudioSessionInitialize(NULL, NULL, NULL, NULL);
// <---------------------------判断设备插入或拔出----------------------------->
#if TARGET_IPHONE_SIMULATOR
#warning *** Simulator mode: audio session code works only on a device
return NO;
#else
CFStringRef route;
UInt32 propertySize=sizeof(CFStringRef);
AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &propertySize, &route);
if ((route==NULL)||(CFStringGetLength(route)==0)) {
NSLog(@"AudioRoute:SILENT,do nothing!");
}else{
NSString *routeStr=(__bridge NSString *)route;
NSLog(@"AudioRoute:%@",routeStr);
NSRange headphoneRange=[routeStr rangeOfString:@"Headphone"];
NSRange headsetRange=[routeStr rangeOfString:@"Headset"];
if ((headphoneRange.location!=NSNotFound)||(headsetRange.location!=NSNotFound)) {
NSLog(@"设备已插入");
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提醒" message:@"插入设备" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil ];
[alert show];
}else{
NSLog(@"设备已拔出");
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提醒" message:@"拔出设备" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil ];
[alert show];
}
}
#endif