在我的应用中,我通过SendGrid(0.2.0)发送电子邮件。 Sendgrid与afnetworking 2.0正常工作但由于某种原因,我不得不将afnetworking版本从2.0更新到3.0。但是现在SendGrid正在给出错误。所以我也通过pod更新它。
pod错误 - 分析依赖项 [!]无法满足以下要求:
AFNetworking (~> 3.0)
要求Podfile
AFNetworking (~> 2.0)
SendGrid (0.3.0)
Podfile的内容:
来源'https://github.com/CocoaPods/Specs.git'
平台:ios,'8.0'
目标'项目名'做
pod'Firebase / Core'
pod'Firebase / Messaging'
pod'AFNetworking','〜> 3.0’
pod'SendGrid','〜> 0.3.0’
端
有人可以告诉我如何解决这个问题吗?
谢谢你!答案 0 :(得分:1)
要自定义SendGrid
,有一点需要注意。
sendGrid
。现在,在SendGrid
中有一种方法:
- (void)sendWithWeb:(SendGridEmail *)email successBlock:(void(^)(id responseObject))successBlock failureBlock:(void(^)(NSError *error))failureBlock
您需要编辑的方法,如下所示
- (void)sendWithWeb:(SendGridEmail *)email successBlock:(void(^)(id responseObject))successBlock failureBlock:(void(^)(NSError *error))failureBlock
{
NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST"
URLString:self.baseURL
parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
for (int i = 0; i < email.imgs.count; i++)
{
UIImage *img = [email.imgs objectAtIndex:i];
NSString *filename = [NSString stringWithFormat:@"image%d.png", i];
NSString *name = [NSString stringWithFormat:@"files[image%d.png]", i];
NSLog(@"name: %@, Filename: %@", name, filename);
NSData *imageData = UIImagePNGRepresentation(img);
[formData appendPartWithFileData:imageData name:name fileName:filename mimeType:@"image/png"];
}
}
error:nil];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
NSURLSessionUploadTask *uploadTask;
uploadTask = [manager
uploadTaskWithStreamedRequest:request
progress:^(NSProgress * _Nonnull uploadProgress) {
// This is not called back on the main queue.
// You are responsible for dispatching to the main queue for UI updates
dispatch_async(dispatch_get_main_queue(), ^{
//Update the progress view
});
}
completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
if (error) {
NSLog(@"Error: %@", error);
failureBlock(error);
} else {
NSLog(@"%@ %@", response, responseObject);
successBlock(responseObject);
}
}];
[uploadTask resume];
}
像这样你必须编辑方法。 根据您的要求进行有条件的更改。
注意强>
那不是经过测试的代码。这只是一个例子。