【问题标题】:Which version of SendGrid is compatible with AFNetworking 3.0?哪个版本的 SendGrid 与 AFNetworking 3.0 兼容?
【发布时间】:2017-06-07 15:17:51
【问题描述】:

在我的应用程序中,我通过 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'
结束

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

谢谢!

【问题讨论】:

  • 只需将SendGrid的Pod版本更新为最新版本,如pod 'SendGrid', '~> 0.3.0'
  • @PiyushPatel,我已经按照你说的方式做了。但 pod 错误仍然存​​在。
  • 只需将 Pod 版本的 SendGrid 更新为最新版本,例如 pod 'AFNetworking', '~> 2.0'
  • @sarita 试试pod 'AFNetworking' pod 'SendGrid' 不指定版本
  • @sarita 您不能使用 AFNetworking 的版本 3.0,因为 SendGrid (0.3.0) 与该版本的 AFNetworking 不兼容,所以您可以使用 AFNetworking (2.6.3)

标签: objective-c ios8 cocoapods sendgrid afnetworking-3


【解决方案1】:

自定义SendGrid有几点需要注意。

  • 您必须在没有 Pod 的情况下手动添加 sendGrid
  • 使用 Pod 添加 AFNetworking 3.0。

现在,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];
}

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

注意

那不是经过测试的代码。它只是一个例子。

【讨论】:

    猜你喜欢
    • 2021-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-29
    • 2017-10-06
    • 2016-08-13
    • 2016-01-06
    • 2018-04-14
    相关资源
    最近更新 更多