2017-05-13 15 views
0

我有播放声音的应用程序。他们在iPad Air 10.3.1上运行良好,但不在我的iPhone 7 10.3.1上运行。我尝试了不同的音频格式,iPhone 7上没有播放任何内容。有没有在plist中输入一些内容或者我需要在iPhone 7上播放声音?声音不能在iPhone 7上播放iOS 10

ViewController.h

@property (strong,nonatomic) AVAudioPlayer *player; 

ViewController.m

- (void)viewDidAppear:(BOOL)animated { 
    NSError *err; 
    NSURL *url = [[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:@"sound" ofType:@"wav"]]; 
    player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&err]; 
    if (err) NSLog(@"error"); 
    player.volume = 1.0; 
    player.delegate = self; 
    [player prepareToPlay]; 
    [player play]; 
    NSLog(@"sound should have played"); 
} 

回答

1

我加了这一点,现在的作品。不知道为什么它之前在其他设备上工作。

AVAudioSession *session = [AVAudioSession sharedInstance]; 
[session setCategory:AVAudioSessionCategoryPlayback error:nil];