A fix for AudioSessionInitialize Deprecated?

前端 未结 5 1176
半阙折子戏
半阙折子戏 2021-02-05 07:31

Apple did not post any alternative code for this on the Apple Developer site.

5条回答
  •  我寻月下人不归
    2021-02-05 08:20

    The equivalent code to

    // C way
    UInt32 category = kAudioSessionCategory_MediaPlayback ;
    OSStatus result = AudioSessionSetProperty(
      kAudioSessionProperty_AudioCategory, sizeof(category), &category ) ;
    
    if( result ) // handle the error
    

    Is

    // Objective-C way
    NSError *nsError;
    [[AVAudioSession sharedInstance]
      setCategory:AVAudioSessionCategoryPlayback error:&nsError];
    
    if( nsError != nil )  // handle the error
    

提交回复
热议问题