我问这样的问题是因为 UIAlertView 会消失。只是不是 AVAudioPlayer。这是我的代码:
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
NSLog(@"MapViewController - didEnterRegion");
LocationReminder *theLocationReminder = [self.locationReminders objectForKey:region.identifier];
NSError *error;
NSURL *theUrl = [NSURL URLWithString:theLocationReminder.audioURI];
NSLog(@"theUrl = %@",theUrl);
AVAudioPlayer *thePlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:theUrl error:&error];
NSLog(@"thePlayer.url = %@",thePlayer.url);
[thePlayer play];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"entered region..." message:@"You have Entered the Location." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
alert.tag = 2;
[alert show];
}
我在测试后检查了设备上的日志,虽然在我四处走动测试时确实显示了警报视图,但 AVAudioPlayer 不会播放,即使它具有正确的 URL。
我应该提到,虽然我在所需背景模式下的 plist 中启用了音频,但我仍然在应用程序中(因此背景不会成为问题)。