在iOS Swift中不使用AWS SDK在Amazon S3存储桶中上传的背景图像(背景模式)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在iOS Swift中不使用AWS SDK在Amazon S3存储桶中上传的背景图像(背景模式)相关的知识,希望对你有一定的参考价值。

我有一个捕获图像/图像的应用程序,获取文档上载策略的请求被激活,并开始上传图像/图像。当用户在前台时,图像/图像上传,但是当用户在后台时,图像/图像不会上传或无法上传。所以我想在应用程序处于后台时(背景模式)上传图像/图像。

背景(背景模式)上传图像/图像的正确路径是什么?

该应用程序是用Swift 2.3编写的

任何帮助,将不胜感激

谢谢

答案

使用AWSS3TransferUtility处理后台上传

    import AWSS3

    let transferUtility = AWSS3TransferUtility.default()
    //In order to customize the header information, we use the AWSS3TransferUtilityUploadExpression class
    let expression = AWSS3TransferUtilityUploadExpression()

    //We want our file to be publicly available by default
    expression.setValue("public-read", forRequestParameter: "x-amz-acl")

    //Copy the custom Meta information into the expression
    transferUtility.uploadFile(uploadRequest.body, bucket: uploadRequest.bucket ?? "", key: uploadRequest.key ?? "", contentType: uploadRequest.contentType ?? "", expression: expression) { (task, error) in }

别忘了在你的app delegate中添加以下代码

func application(_ application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: @escaping () -> Void) {
    /*
     Store the completion handler.
     */
    AWSS3TransferUtility.interceptApplication(application, handleEventsForBackgroundURLSession: identifier, completionHandler: completionHandler)
}

以上是关于在iOS Swift中不使用AWS SDK在Amazon S3存储桶中上传的背景图像(背景模式)的主要内容,如果未能解决你的问题,请参考以下文章

导入的框架在视图控制器中不可见

iOS Swift:将 AWS SDK 与 xCode6 结合使用 - 错误消息

iOS Swift:将 AWS SDK 与 xCode6 结合使用 - 错误消息

AWS PHP SDK 2 (aws.phar) 在 xampp 中不起作用

pyspark 兼容 hadoop aws 和 aws sdk 版本 2.4.4

AWS java sdk 1.10.2 中不存在包 com.amazonaws.services.lambda.runtime