0

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];
}

テスト後にデバイスのログを確認しました。テストを行っているときにアラートビューが実際に表示されますが、正しいURLを使用していてもAVAudioPlayerは再生されません。

[必須のバックグラウンドモード]でplistのオーディオを有効にしましたが、まだアプリを使用しています(したがって、バックグラウンドは問題になりません)。

4

1 に答える 1

0

への参照を維持していないため、thePlayer割り当てが解除されています (ARC を使用していると仮定します)。クラス@interfaceブロックに次のようなプロパティを追加する可能性があります

@property (nonatomic, strong) AVAudioPlayer *player;

そして、あなたがしている行の代わりに

self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:theUrl error:&error];

お役に立てれば!

于 2012-08-31T06:55:32.453 に答える