我从我们制作的应用程序中获取此代码,该应用程序已经存储(并且仍然可以正常运行)。 但是当我尝试在新的应用程序中运行它时,我得到一个SIGABRT。
这是我用来通过DependencyService在Xamarin.Forms中重现崩溃的示例类。创建录像机后,error属性保持为空。
public class RedordDependencies : IRecordDependencies
{
NSObject[] values = new NSObject[] {
NSNumber.FromFloat (44100.0f), //Sample Rate
NSNumber.FromInt32 ((int)AudioToolbox.AudioFormatType.LinearPCM), //AVFormat
NSNumber.FromInt32 (2), //Channels
NSNumber.FromInt32 (16), //PCMBitDepth
NSNumber.FromBoolean (false), //IsBigEndianKey
NSNumber.FromBoolean (false) //IsFloatKey
};
NSObject[] keys = new NSObject[] {
AVAudioSettings.AVSampleRateKey,
AVAudioSettings.AVFormatIDKey,
AVAudioSettings.AVNumberOfChannelsKey,
AVAudioSettings.AVLinearPCMBitDepthKey,
AVAudioSettings.AVLinearPCMIsBigEndianKey,
AVAudioSettings.AVLinearPCMIsFloatKey
};
AVAudioRecorder recorder;
NSError error;
NSDictionary settings;
public RedordDep()
{
settings = NSDictionary.FromObjectsAndKeys(values, keys);
}
public string Prepare()
{
NSUrl path = NSUrl.FromString(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), DateTime.Now.Ticks.ToString() + ".wav"));
recorder = AVAudioRecorder.Create(path, new AudioSettings(settings), out error);
bool prepared = recorder.PrepareToRecord();
return path.Path;
}
}
编辑: 我发现在使用AVFoundation时其他情况也会发生这种情况。 在我的情况下,它发生在我尝试初始化录像机和录音机时。
答案 0 :(得分:0)
研究完之后 Stacktrace 我发现它与iOS 10中引入的安全选项有关。我只需添加我需要的使用说明密钥。 " NSCameraUsageDescription"和" NSMicrophoneUsageDescription"