- Add Upload Avatar
This commit is contained in:
1 parent
538b944026
commit
f570c107c9
14 files changed
+1105
-953
No files matched your search
@@ -108,6 +108,10 @@
|
||||
* <#Description#>
|
||||
*/
|
||||
@property (strong, nonatomic, nullable) NSString * lastName;
|
||||
/**
|
||||
* <#Description#>
|
||||
*/
|
||||
@property (nonatomic, strong, nullable) NSURL * profileImageUrl;
|
||||
/**
|
||||
* <#Description#>
|
||||
*/
|
||||
|
||||
@@ -301,7 +301,7 @@ static bool isFirstAccess = YES;
|
||||
@"userId":@"uuid",
|
||||
@"firstName":@"first_name",
|
||||
@"lastName":@"last_name",
|
||||
@"profileImage":@"profile_image",
|
||||
@"profileImageUrl":@"profile_image",
|
||||
@"sex":@"sex",
|
||||
@"birthDate":@"birth_year",
|
||||
@"phone":@"phone",
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
//
|
||||
|
||||
#import "PNObject.h"
|
||||
#import "PNObjectFormData.h"
|
||||
|
||||
@interface PNObject (PNObjectConnection)
|
||||
|
||||
@@ -22,6 +23,13 @@
|
||||
success:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSDictionary * _Nullable responseObject))success
|
||||
failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error))failure;
|
||||
|
||||
+ (void) POSTWithEndpointAction:(NSString * _Nonnull) endPoint
|
||||
formData:(NSArray * _Nullable) postFormData
|
||||
parameters:(NSDictionary * _Nullable) parameters
|
||||
progress:(nullable void (^)(NSProgress * _Nonnull uploadProgress)) uploadProgress
|
||||
success:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSDictionary * _Nullable responseObject))success
|
||||
failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error))failure;
|
||||
|
||||
+ (id _Nonnull) parseObjectFromResponse:(id _Nullable) response;
|
||||
|
||||
@end
|
||||
@@ -82,6 +82,42 @@
|
||||
}
|
||||
}
|
||||
|
||||
+ (void) POSTWithEndpointAction:(NSString * _Nonnull) endPoint
|
||||
formData:(NSArray * _Nullable) postFormData
|
||||
parameters:(NSDictionary * _Nullable) parameters
|
||||
progress:(nullable void (^)(NSProgress * _Nonnull uploadProgress)) uploadProgress
|
||||
success:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSDictionary * _Nullable responseObject))success
|
||||
failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error))failure {
|
||||
|
||||
if ([[PNObjectConfig sharedInstance] currentOauthCredential] && ![[[PNObjectConfig sharedInstance] currentOauthCredential] isExpired]) {
|
||||
|
||||
[[[PNObjectConfig sharedInstance] manager] POST:[[[PNObjectConfig sharedInstance] baseUrl] stringByAppendingFormat:@"%@",endPoint]
|
||||
parameters:parameters
|
||||
constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
|
||||
if (postFormData) {
|
||||
for (PNObjectFormData *postData in postFormData) {
|
||||
|
||||
[formData appendPartWithFileData:[postData formData] name:[postData name] fileName:[postData fileName] mimeType:[postData mimeType]];
|
||||
}
|
||||
}
|
||||
}
|
||||
progress:uploadProgress
|
||||
success:success
|
||||
failure:failure];
|
||||
}
|
||||
else {
|
||||
[[PNObjectConfig sharedInstance] refreshTokenForClientCredentialWithBlockSuccess:^(BOOL refreshSuccess) {
|
||||
|
||||
[self POSTWithEndpointAction:endPoint parameters:parameters progress:uploadProgress success:success failure:failure];
|
||||
} failure:^(NSError * _Nonnull error) {
|
||||
|
||||
if (failure) {
|
||||
failure(nil,error);
|
||||
}
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#pragma mark Private Methods
|
||||
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
//
|
||||
// PNObjectFormData.h
|
||||
// Pods
|
||||
//
|
||||
// Created by Giuseppe Nucifora on 16/02/16.
|
||||
//
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface PNObjectFormData : NSObject
|
||||
|
||||
@property (nonatomic, strong, nonnull) NSData *formData;
|
||||
@property (nonatomic, strong, nonnull) NSString * name;
|
||||
@property (nonatomic, strong, nonnull) NSString * fileName;
|
||||
@property (nonatomic, strong, nonnull) NSString * mimeType;
|
||||
|
||||
/**
|
||||
* <#Description#>
|
||||
*
|
||||
* @param formData <#formData description#>
|
||||
* @param name <#name description#>
|
||||
* @param fileName <#fileName description#>
|
||||
* @param mimeType <#mimeType description#>
|
||||
*
|
||||
* @return <#return value description#>
|
||||
*/
|
||||
+ (instancetype _Nonnull) formDataFromNSData:(NSData * _Nonnull) formData name:(NSString * _Nonnull) name fileName:(NSString * _Nonnull) fileName mimeType:(NSString * _Nonnull) mimeType;
|
||||
/**
|
||||
* <#Description#>
|
||||
*
|
||||
* @param image <#image description#>
|
||||
* @param name <#name description#>
|
||||
* @param fileName <#fileName description#>
|
||||
* @param mimeType <#mimeType description#>
|
||||
*
|
||||
* @return <#return value description#>
|
||||
*/
|
||||
+ (instancetype _Nonnull) formDataFromUIImage:(UIImage * _Nonnull) image name:(NSString * _Nonnull) name fileName:(NSString * _Nonnull) fileName mimeType:(NSString * _Nonnull) mimeType;
|
||||
/**
|
||||
* <#Description#>
|
||||
*
|
||||
* @param image <#image description#>
|
||||
* @param compression <#compression description#>
|
||||
* @param name <#name description#>
|
||||
* @param fileName <#fileName description#>
|
||||
* @param mimeType <#mimeType description#>
|
||||
*
|
||||
* @return <#return value description#>
|
||||
*/
|
||||
+ (instancetype _Nonnull) formDataFromUIImage:(UIImage * _Nonnull) image compression:(CGFloat) compression name:(NSString * _Nonnull) name fileName:(NSString * _Nonnull) fileName mimeType:(NSString * _Nonnull) mimeType;
|
||||
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,40 @@
|
||||
//
|
||||
// PNObjectFormData.m
|
||||
// Pods
|
||||
//
|
||||
// Created by Giuseppe Nucifora on 16/02/16.
|
||||
//
|
||||
//
|
||||
|
||||
#import "PNObjectFormData.h"
|
||||
|
||||
@implementation PNObjectFormData
|
||||
|
||||
+ (instancetype _Nonnull) formDataFromNSData:(NSData * _Nonnull) formData name:(NSString * _Nonnull) name fileName:(NSString * _Nonnull) fileName mimeType:(NSString * _Nonnull) mimeType {
|
||||
PNObjectFormData * responseData = [PNObjectFormData new];
|
||||
|
||||
[responseData setFormData:formData];
|
||||
[responseData setName:name];
|
||||
[responseData setFileName:fileName];
|
||||
[responseData setMimeType:mimeType];
|
||||
|
||||
return responseData;
|
||||
}
|
||||
|
||||
+ (instancetype _Nonnull) formDataFromUIImage:(UIImage * _Nonnull) image name:(NSString * _Nonnull) name fileName:(NSString * _Nonnull) fileName mimeType:(NSString * _Nonnull) mimeType {
|
||||
return [self formDataFromUIImage:image compression:1 name:name fileName:fileName mimeType:mimeType];
|
||||
}
|
||||
|
||||
+ (instancetype _Nonnull) formDataFromUIImage:(UIImage * _Nonnull) image compression:(CGFloat) compression name:(NSString * _Nonnull) name fileName:(NSString * _Nonnull) fileName mimeType:(NSString * _Nonnull) mimeType {
|
||||
PNObjectFormData * responseData = [PNObjectFormData new];
|
||||
|
||||
[responseData setFormData:UIImageJPEGRepresentation(image, compression)];
|
||||
[responseData setName:name];
|
||||
[responseData setFileName:fileName];
|
||||
[responseData setMimeType:mimeType];
|
||||
|
||||
return responseData;
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user