微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Swift:如何修复info.plist中的错误AWS S3权限

如何解决Swift:如何修复info.plist中的错误AWS S3权限

根据本教程,我能够成功构建一个录音机来本地记录和保存文件https://blckbirds.com/post/voice-recorder-app-in-swiftui-1/

它能够在本地保存音频文件,但我想将文件保存到AWS S3存储桶,因此我根据本教程添加了AWS传输代码

https://www.swiftdevcenter.com/upload-image-video-audio-and-any-type-of-files-to-aws-s3-bucket-swift/

// Upload recording to AWS S3
        AWSS3Manager.shared.uploadAudio(audioUrl: audioFilename,progress: {[weak self] (progress) in
                

            }) { [weak self] (uploadedFileUrl,error) in
                
                 if let finalPath = uploadedFileUrl as? String {
                   
                    print("file uploaded to \(finalPath)")
                } else {
                    print("\(String(describing: error?.localizedDescription))")
                }
        }

我的音频录制和AWS传输最终结果如下

func startRecording() {
     let recordingSession = AVAudioSession.sharedInstance()
     
     do {
         try recordingSession.setCategory(.playAndRecord,mode: .default)
         try recordingSession.setActive(true)
     } catch {
         print("Failed to set up recording session")
     }
     
     let documentPath = FileManager.default.urls(for: .documentDirectory,in: .userDomainMask)[0]
     let audioFilename = documentPath.appendingPathComponent("\(Date().toString(dateFormat: "dd-MM-YY_'at'_HH:mm:ss")).m4a")
     
     let settings = [
         AVFormatIDKey: Int(kAudioFormatMPEG4AAC),AVSampleRateKey: 12000,AVNumberOfChannelsKey: 1,AVEncoderAudioQualityKey: AVAudioQuality.high.rawValue
     ]
     
     do {
         audioRecorder = try AVAudioRecorder(url: audioFilename,settings: settings)
         audioRecorder.record()

         recording = true
        
        // Upload recording to AWS S3
        AWSS3Manager.shared.uploadAudio(audioUrl: audioFilename,error) in
                
                 if let finalPath = uploadedFileUrl as? String {
                   
                    print("file uploaded to \(finalPath)")
                } else {
                    print("\(String(describing: error?.localizedDescription))")
                }
        }

     } catch {
         print("Could not start recording")
     }
 }

添加S3传输后,我开始出现错误

错误:无法从文件:/Users/name/Desktop/app/Info.plist中读取属性列表:操作无法完成。 (XCBUtil.PropertyListConversionError错误1。)(在项目“应用”中的目标“应用”中)

我能够将错误源缩小到我的info.plist权限。是这里

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
    <key>NSExceptionDomains</key>
    <dict>
        <key>amazonaws.com</key>
        <dict>
            <key>NSThirdPartyExceptionMinimumTLsversion</key>
            <string>TLSv1.0</string>
            <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
            <false/>
            <key>NSIncludesSubdomains</key>
            <true/>
        </dict>
        <key>amazonaws.com.cn</key>
        <dict>
            <key>NSThirdPartyExceptionMinimumTLsversion</key>
            <string>TLSv1.0</string>
            <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
            <false/>
            <key>NSIncludesSubdomains</key>
            <true/>
        </dict>
    </dict>
</dict>
<key>AWS</key>
<dict>
    <key>CredentialsProvider</key>
    <dict>
        <key>CognitoIdentity</key>
        <dict>
            <key>Default</key>
            <dict>
                <key>PoolId</key>
                <string>xxxxx-xxxx-xxx-xxx-xxx</string>
                <key>Region</key>
                <string>.USEast1</string> //your region here
            </dict>
        </dict>
    </dict>
    <key>S3TransferManager</key>
    <dict>
        <key>Default</key>
        <dict>
            <key>Region</key>
            <string>ap-south-1</string>
        </dict>
    </dict>
</dict>

出什么问题了,我该如何解决错误

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。