iPhone silent mode detection

#import "AudioToolbox/AudioToolbox.h"

- (void) ifSilentModeThenMessage
{
 CFStringRef state;
 UInt32 propertySize = sizeof(CFStringRef);
 AudioSessionInitialize(NULL, NULL, NULL, NULL);
 AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &propertySize, &state);
 
 if(CFStringGetLength(state) == 0)
 { 
  UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Silent mode" 
              message:@"Please turn sound on"
                delegate:self cancelButtonTitle:@"Ok" 
             otherButtonTitles:nil];
  [alert show];
  [alert release];
 }
}
posted @ 2011-06-30 10:26  harvey.ding  阅读(310)  评论(0编辑  收藏  举报