2017-01-23 89 views
0

在我的應用程序中,我通過SendGrid(0.2.0)發送電子郵件。 Sendgrid在網絡2.0上正常工作,但由於某種原因,我不得不將網絡版從2.0更新到3.0。但是現在SendGrid給出了錯誤。所以我通過一個pod更新它。哪個版本的SendGrid與AFNetworking 3.0兼容?

莢錯誤 - 分析依賴 無法滿足以下要求:

  • AFNetworking (~> 3.0)通過Podfile
  • AFNetworking (~> 2.0)要求SendGrid (0.3.0)

內容Podfile的要求:

[!] '

來源'https://github.com/CocoaPods/Specs.git '
平臺:IOS, '8.0'
目標 '項目名' 做
莢 '火力地堡/核心'
莢 '火力地堡/消息'
莢 'AFNetworking', '〜> 3.0'
莢' SendGrid','〜> 0.3.0'
end

有人可以告訴我如何解決這個問題嗎?

謝謝!

+0

只是更新Pod版本的'SendGrid'與最新版本,像'pod'SendGrid','〜> 0.3.0'' –

+0

@PiyushPatel,我已經做了同樣的方式,如你所說。但是pod錯誤仍然存​​在。 – sarita

+0

只需用最新版本更新SendGrid的波德版本,像豆莢「AFNetworking」,「〜> 2.0」 – Wos

回答

1

要定製SendGrid有一點要注意。

  • 您必須手動添加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]; 
} 

這樣你必須編輯方法。 根據您的要求做其他的更改。

注意

那不是測試代碼。它的例子。

+0

謝謝你,喲很多@Piyush Patel。 – sarita

相關問題