哪个版本的SendGrid与AFNetworking 3.0兼容?

时间:2022-09-09 18:10:47

In my app, I'm sending emails through SendGrid (0.2.0). Sendgrid was working properly with afnetworking 2.0 but due to some reason, I had to update afnetworking version from 2.0 to 3.0. But now SendGrid is giving errors.So I update it too through a pod.

在我的应用程序中,我通过SendGrid(0.2.0)发送电子邮件。 Sendgrid与afnetworking 2.0正常工作但由于某种原因,我不得不将afnetworking版本从2.0更新到3.0。但是现在SendGrid给出了错误。所以我也通过pod更新了它。

pod error - Analyzing dependencies [!] Unable to satisfy the following requirements:

pod错误 - 分析依赖项[!]无法满足以下要求:

  • AFNetworking (~> 3.0) required by Podfile
  • Podfile需要AFNetworking(〜> 3.0)
  • AFNetworking (~> 2.0) required by SendGrid (0.3.0)
  • SendGrid(0.3.0)需要AFNetworking(〜> 2.0)

content of Podfile:

Podfile的内容:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, ‘8.0’
target ‘Projectname’ do
pod 'Firebase/Core'
pod 'Firebase/Messaging'
pod 'AFNetworking', '~> 3.0’
pod 'SendGrid', '~> 0.3.0’
end

来源'https://github.com/CocoaPods/Specs.git'平台:ios,'8.0'目标'Projectname'做pod'Firebase / Core'pod'Firebase / Messaging'pod'AFNetworking','〜> 3.0' pod'SendGrid','〜> 0.3.0'结束

Can anybody tell me how to resolve this issue?

谁能告诉我如何解决这个问题?

thank you!

谢谢!

1 个解决方案

#1


1  

To Customize SendGrid there are some point to pay attention.

要自定义SendGrid,有一点需要注意。

  • You have to add sendGrid manually without Pods.
  • 您必须手动添加sendGrid而不使用Pod。
  • Add AFNetworking 3.0 using Pod.
  • 使用Pod添加AFNetworking 3.0。

Now, in SendGrid there is one method :

现在,在SendGrid中有一种方法:

- (void)sendWithWeb:(SendGridEmail *)email successBlock:(void(^)(id responseObject))successBlock failureBlock:(void(^)(NSError *error))failureBlock

That method you have to edit like as follow

您需要编辑的方法如下

- (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];
}

Like this you have to edit methods. Do editional changes as per your requirement.

像这样你必须编辑方法。根据您的要求进行有条件的更改。

Note

注意

That's not tested code. its just example.

那不是经过测试的代码。它的榜样。

#1


1  

To Customize SendGrid there are some point to pay attention.

要自定义SendGrid,有一点需要注意。

  • You have to add sendGrid manually without Pods.
  • 您必须手动添加sendGrid而不使用Pod。
  • Add AFNetworking 3.0 using Pod.
  • 使用Pod添加AFNetworking 3.0。

Now, in SendGrid there is one method :

现在,在SendGrid中有一种方法:

- (void)sendWithWeb:(SendGridEmail *)email successBlock:(void(^)(id responseObject))successBlock failureBlock:(void(^)(NSError *error))failureBlock

That method you have to edit like as follow

您需要编辑的方法如下

- (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];
}

Like this you have to edit methods. Do editional changes as per your requirement.

像这样你必须编辑方法。根据您的要求进行有条件的更改。

Note

注意

That's not tested code. its just example.

那不是经过测试的代码。它的榜样。