我知道可达性示例允许检测网络是否可以通过Wifi或Cell访问,但有没有办法确定单元连接是通过3G还是EDGE?
在我的'Swift'应用程序中,我有一个将照片上传到我的Amazon S3存储桶的功能.当用户连接到WiFi或LTE没有问题,但是当连接速度稍慢(例如3G)时,上传需要花费很多时间(最多一分钟),而iphone可能会损失15-20%的电池!我将照片调整到大约200-300kb,这应该不是问题.我用它的代码是:
func awsS3PhotoUploader(_ ext: String, pathToFile: String, contentType: String, automaticUpload: Bool){
let credentialsProvider = AWSCognitoCredentialsProvider(regionType:CognitoRegionType,
identityPoolId:CognitoIdentityPoolId)
let configuration = AWSServiceConfiguration(region:CognitoRegionType, credentialsProvider:credentialsProvider)
AWSServiceManager.default().defaultServiceConfiguration = configuration
let uploadRequest = AWSS3TransferManagerUploadRequest()
uploadRequest?.body = URL(string: "file://"+pathToFile)
uploadRequest?.key = ProcessInfo.processInfo.globallyUniqueString + "." + ext
uploadRequest?.bucket = S3BucketName
uploadRequest?.contentType = contentType + ext
uploadRequest?.uploadProgress = { (bytesSent, totalBytesSent, totalBytesExpectedToSend) -> Void in
DispatchQueue.main.async(execute: { () -> Void in
if totalBytesExpectedToSend > 1 {
print(totalBytesSent)
print(totalBytesExpectedToSend)
}
}) …Run Code Online (Sandbox Code Playgroud)