//获取设备状态,是否插入耳机,如果插入耳机,则返回“YES" BY Leisure
+ (BOOL)isHeadphone
{
UInt32 propertySize = sizeof(CFStringRef);
CFStringRef state = nil;
AudioSessionGetProperty(kAudioSessionProperty_AudioRoute
,&propertySize,&state);
//return @"Headphone" or @"Speaker" and so on.
//根据状态判断是否为耳机状态
if ([(NSString *)state isEqualToString:@"Headphone"] ||[(NSString *)state isEqualToString:@"HeadsetInOut"])
{
return YES;
}
else {
return NO;
}
}
{
UInt32 propertySize = sizeof(CFStringRef);
CFStringRef state = nil;
AudioSessionGetProperty(kAudioSessionProperty_AudioRoute
,&propertySize,&state);
//return @"Headphone" or @"Speaker" and so on.
//根据状态判断是否为耳机状态
if ([(NSString *)state isEqualToString:@"Headphone"] ||[(NSString *)state isEqualToString:@"HeadsetInOut"])
{
return YES;
}
else {
return NO;
}
}