将附件数据字符串从Gmail API转换为数据始终在iOS上返回nil

问题描述

我一直在使用此SO帖子(iOS - download attachment from Gmail using messageId and attachmentId)作为参考

我已经能够进行API调用,获取响应数据并解析出附件数据:

            AF.request("https://www.googleapis.com/gmail/v1/users/me/messages/\(email.id)/attachments/\(email.payload.body.attachmentId)",headers: headers)
                .responseJSON
                
                { [self] response in
                  
                    do {
                        let json = try JSON(data: response.data!)
                        
                        let jsonDict = convertToDictionary(text: json.rawString()!)
                        let attachmentDataString: String? = jsonDict!["data"] as? String

在链接文章中接受答案之后,我确保格式化我的字符串,使其与base64兼容:

let formattedString = attachmentDataString!.replacingOccurrences(of: " ",with: "+",options: .literal,range: nil)

然后尝试将该字符串转换为数据:

let attachmentData = Data(base64Encoded: formattedString)

但是,该对象始终为零(我正在预先检查以确保仅在带有附件的电子邮件上运行此逻辑)。

任何帮助表示赞赏!

编辑:这是格式化之前的数据字符串:

https://gist.github.com/narner/d7805807992fa44a30e00d6480a04164

这是格式化后的数据字符串:

https://gist.github.com/narner/02c3152d1dc935985a4da8d9b7388ade

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...