사용자 정의하려면 SendGrid
에주의를 기울여야합니다.
- 포드가 없으면 수동으로
sendGrid
을 추가해야합니다.
- 포드를 사용하여 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];
}
를 따를 때처럼 편집 할 수있다. 요구 사항에 따라 편집이 변경됩니다.
코드를 테스트하지 주
. 그것의 예입니다.
최신 버전의'SendGrid'의 Pod 버전을'Pod '처럼 sendGrid', '~> 0.3.0'' –
@PiyushPatel과 같이 업데이트했습니다. 그러나 포드 오류가 계속 발생합니다. – sarita
최신 버전의 SendGrid의 Pod 버전을 'AFNetworking', '~ 2.0' – Wos