From b6b3b5a21d80ac800a4389ae835bab8f1f391b4c Mon Sep 17 00:00:00 2001 From: Giuseppe Nucifora Date: Sun, 28 Feb 2016 20:06:46 +0100 Subject: [PATCH] - Add Profile image --- Example/Podfile.lock | 4 +- .../Pods/Local Podspecs/PNObject.podspec.json | 4 +- Example/Pods/Manifest.lock | 4 +- .../Target Support Files/PNObject/Info.plist | 2 +- .../ResourceBundle-PNObject-Info.plist | 2 +- PNObject.podspec | 2 +- Pod/Classes/PNClasses/PNUser.h | 4 + Pod/Classes/PNClasses/PNUser.m | 82 +++++++++++++------ 8 files changed, 69 insertions(+), 35 deletions(-) diff --git a/Example/Podfile.lock b/Example/Podfile.lock index bce735d..108f89a 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -40,7 +40,7 @@ PODS: - NSString-Helper (1.0.3) - nv-ios-http-status (0.0.1) - PEAR-FileManager-iOS (1.3.1) - - PNObject (0.3.10): + - PNObject (0.3.11): - AFNetworking - CodFis-Helper - FBSDKCoreKit @@ -96,7 +96,7 @@ SPEC CHECKSUMS: NSString-Helper: d4c5459e8142ee6a96b070118009f08637030c2d nv-ios-http-status: b6c2b5fc8656cc19e0d3000dadce2080b99d0e2f PEAR-FileManager-iOS: 3bc403f68a53483f5629aa822f4649e40275c4d3 - PNObject: fa282ce7a3b4258f48ccb4d0f0a2ae8e09a6b7a0 + PNObject: ad9ec93536cac8a9d777ffb849029b6b0b4c946e PureLayout: f35f5384c9c4e4479df041dbe33ad7577b71ddfb RNCryptor: 59d6483908115af5c12b884db23392024e52a5fe Specta: ac94d110b865115fe60ff2c6d7281053c6f8e8a2 diff --git a/Example/Pods/Local Podspecs/PNObject.podspec.json b/Example/Pods/Local Podspecs/PNObject.podspec.json index 7d84629..f771258 100644 --- a/Example/Pods/Local Podspecs/PNObject.podspec.json +++ b/Example/Pods/Local Podspecs/PNObject.podspec.json @@ -1,6 +1,6 @@ { "name": "PNObject", - "version": "0.3.10", + "version": "0.3.11", "summary": "PNObject is a simple replica of the more complex ParseObject", "homepage": "https://github.com/giuseppenucifora/PNObject", "license": "MIT", @@ -9,7 +9,7 @@ }, "source": { "git": "https://github.com/giuseppenucifora/PNObject.git", - "tag": "0.3.10" + "tag": "0.3.11" }, "platforms": { "ios": "7.0" diff --git a/Example/Pods/Manifest.lock b/Example/Pods/Manifest.lock index bce735d..108f89a 100644 --- a/Example/Pods/Manifest.lock +++ b/Example/Pods/Manifest.lock @@ -40,7 +40,7 @@ PODS: - NSString-Helper (1.0.3) - nv-ios-http-status (0.0.1) - PEAR-FileManager-iOS (1.3.1) - - PNObject (0.3.10): + - PNObject (0.3.11): - AFNetworking - CodFis-Helper - FBSDKCoreKit @@ -96,7 +96,7 @@ SPEC CHECKSUMS: NSString-Helper: d4c5459e8142ee6a96b070118009f08637030c2d nv-ios-http-status: b6c2b5fc8656cc19e0d3000dadce2080b99d0e2f PEAR-FileManager-iOS: 3bc403f68a53483f5629aa822f4649e40275c4d3 - PNObject: fa282ce7a3b4258f48ccb4d0f0a2ae8e09a6b7a0 + PNObject: ad9ec93536cac8a9d777ffb849029b6b0b4c946e PureLayout: f35f5384c9c4e4479df041dbe33ad7577b71ddfb RNCryptor: 59d6483908115af5c12b884db23392024e52a5fe Specta: ac94d110b865115fe60ff2c6d7281053c6f8e8a2 diff --git a/Example/Pods/Target Support Files/PNObject/Info.plist b/Example/Pods/Target Support Files/PNObject/Info.plist index 6b56a02..651f003 100644 --- a/Example/Pods/Target Support Files/PNObject/Info.plist +++ b/Example/Pods/Target Support Files/PNObject/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 0.3.10 + 0.3.11 CFBundleSignature ???? CFBundleVersion diff --git a/Example/Pods/Target Support Files/PNObject/ResourceBundle-PNObject-Info.plist b/Example/Pods/Target Support Files/PNObject/ResourceBundle-PNObject-Info.plist index 16eabf4..fc95b27 100644 --- a/Example/Pods/Target Support Files/PNObject/ResourceBundle-PNObject-Info.plist +++ b/Example/Pods/Target Support Files/PNObject/ResourceBundle-PNObject-Info.plist @@ -13,7 +13,7 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 0.3.10 + 0.3.11 CFBundleSignature ???? CFBundleVersion diff --git a/PNObject.podspec b/PNObject.podspec index d053c92..0f1f671 100644 --- a/PNObject.podspec +++ b/PNObject.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = "PNObject" -s.version = "0.3.10" +s.version = "0.3.11" s.summary = "PNObject is a simple replica of the more complex ParseObject" # This description is used to generate tags and improve search results. diff --git a/Pod/Classes/PNClasses/PNUser.h b/Pod/Classes/PNClasses/PNUser.h index 3c11625..3dcd997 100644 --- a/Pod/Classes/PNClasses/PNUser.h +++ b/Pod/Classes/PNClasses/PNUser.h @@ -101,6 +101,10 @@ */ - (BOOL) isAuthenticated; +- (UIImage* _Nonnull) userProfileImage; + +- (UIImage* _Nonnull) userProfileImage:(BOOL) forceReload; + //- (void) setPassword:(NSString * _Nonnull)password inBackGroundWithBlock:(nullable void (^)(BOOL saveStatus, id responseObject, NSError * error)) responseBlock; ///-------------------------------------- diff --git a/Pod/Classes/PNClasses/PNUser.m b/Pod/Classes/PNClasses/PNUser.m index 54d61ed..f9c6faa 100644 --- a/Pod/Classes/PNClasses/PNUser.m +++ b/Pod/Classes/PNClasses/PNUser.m @@ -86,7 +86,7 @@ static bool isFirstAccess = YES; [self autoLogin]; }); } - + return USER; } @@ -139,17 +139,17 @@ static bool isFirstAccess = YES; [self autoLoginWithBlockSuccess:^(BOOL loginSuccess) { [[self class] GETWithEndpointAction:@"user/profile" - progress:nil - success:^(NSURLSessionDataTask * _Nullable task, id _Nullable responseObject) { + progress:nil + success:^(NSURLSessionDataTask * _Nullable task, id _Nullable responseObject) { - NSLogDebug(@"%@",[responseObject objectForKey:@"user"]); + NSLogDebug(@"%@",[responseObject objectForKey:@"user"]); - [self populateObjectFromJSON:[responseObject objectForKey:@"user"]]; - [self saveLocally]; - - } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { - NSLogDebug(@"%@",error); - }]; + [self populateObjectFromJSON:[responseObject objectForKey:@"user"]]; + [self saveLocally]; + + } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { + NSLogDebug(@"%@",error); + }]; } failure:^(NSError * _Nonnull error) { NSLogDebug(@"error : %@",error); }]; @@ -159,19 +159,19 @@ static bool isFirstAccess = YES; failure:(nullable void (^)(NSError * _Nonnull error))failure { [[self class] POSTWithEndpointAction:@"registration/register" parameters:[self JSONFormObject] - progress:nil - success:^(NSURLSessionDataTask * _Nullable task, NSDictionary * _Nullable responseObject) { - NSLog(@"response %@",responseObject); - if(success){ - success(self); - [self saveLocally]; - } - } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { - NSLogDebug(@"error : %ld",[error code]); - if (failure) { - failure(error); - } - }]; + progress:nil + success:^(NSURLSessionDataTask * _Nullable task, NSDictionary * _Nullable responseObject) { + NSLog(@"response %@",responseObject); + if(success){ + success(self); + [self saveLocally]; + } + } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { + NSLogDebug(@"error : %ld",[error code]); + if (failure) { + failure(error); + } + }]; } @@ -273,7 +273,7 @@ static bool isFirstAccess = YES; [[PNObjectConfig sharedInstance] refreshTokenForUserWithEmail:email password:password withBlockSuccess:^(BOOL refreshSuccess) { if (refreshSuccess) { - + PNUser *user = [[self class] new]; PNObjcPassword *objectPassword = [PNObjcPassword new]; @@ -315,14 +315,44 @@ static bool isFirstAccess = YES; failure(error); } }]; - - + + } - (BOOL) isAuthenticated { return self.authenticated; } +- (UIImage* _Nonnull) userProfileImage { + return [self userProfileImage:NO]; +} + + +- (UIImage* _Nonnull) userProfileImage:(BOOL) forceReload { + + if (!_profileImage || forceReload) { + + if (_profileImageUrl) { + + NSError* error = nil; + NSData* data = [NSData dataWithContentsOfURL:_profileImageUrl options:NSDataReadingUncached error:&error]; + if (error) { + NSLog(@"%@", [error localizedDescription]); + return [UIImage imageNamed:@"userProfileAvatar"]; + } else { + NSLog(@"Data has loaded successfully."); + return [UIImage imageWithData:data]; + } + } + else { + return [UIImage imageNamed:@"userProfileAvatar"]; + } + } + else { + return _profileImage; + } +} + #pragma mark PNObjectSubclassing Protocol + (NSDictionary *)objcetMapping {