title: iOS play audio through iPhone receiver (phone speaker)
body: <p>I am currently working on an application which should play Audio files through the iPhone receiver. I know it was easily possible before iOS 6/7, but those methods are deprecated now. </p>
  
  <p>So does anybody know how it works on iOS 7? </p>
  
  <p>This is my code, which does not work: </p>
  
  <pre><code>    _audioSession = [AVAudioSession sharedInstance];
      [_audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
      [_audioSession overrideOutputAudioPort:AVAudioSessionPortBuiltInReceiver error:nil];
  
      NSString *ringtone =  [[NSUserDefaults standardUserDefaults] stringForKey:@"ringtone"];
      ringtone = [ringtone stringByReplacingOccurrencesOfString:@".m4r" withString:@""];
      NSString *path;
      path = [[NSBundle mainBundle] pathForResource:@"abto_ringbacktone" ofType:@"wav"];
  
  
      NSError *error;
      _player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL URLWithString:path] error:&amp;error];
      if (error) {
          NSLog(@"Error: %@",error.localizedDescription);
      }
  
  }
  
  [_player setNumberOfLoops:10];
  [_player prepareToPlay];
  [_player play];
  [_player setVolume:0.1];
  </code></pre>