diff --git a/Example/PNObject/PNObjectAppDelegate.m b/Example/PNObject/PNObjectAppDelegate.m index 108d441..6b212cf 100644 --- a/Example/PNObject/PNObjectAppDelegate.m +++ b/Example/PNObject/PNObjectAppDelegate.m @@ -36,9 +36,9 @@ EnvironmentProduction : @"http://packman.ppreview.it/app_stage.php/api/v1/" } withOauth:YES]; [[PNObjectConfig sharedInstance] setHTTPHeaderValue:@"application/x-www-form-urlencoded" forKey:@"Content-Type"]; - [[PNObjectConfig sharedInstance] setClientID:@"1_pqjo2w5k7j4g8skco408oc048w8so0ws840gcg8k8gwsgk0g4" clientSecret:@"10w0vg2v6eggooc4wks4w4s0wkwok0wkck0w888so0o80g88w8" forEnv:Stage]; + [[PNObjectConfig sharedInstance] setClientID:@"1_pqjo2w5k7j4g8skco408oc048w8so0ws840gcg8k8gwsgk0g4" clientSecret:@"10w0vg2v6eggooc4wks4w4s0wkwok0wkck0w888so0o80g88w8" forEnv:EnvironmentProduction]; #ifdef DEBUG - [[PNObjectConfig sharedInstance] setEnvironment:Stage]; + [[PNObjectConfig sharedInstance] setEnvironment:EnvironmentStage]; #endif diff --git a/Example/PNObject/PNObjectViewController.m b/Example/PNObject/PNObjectViewController.m index 4bafbd3..4b2f121 100644 --- a/Example/PNObject/PNObjectViewController.m +++ b/Example/PNObject/PNObjectViewController.m @@ -106,15 +106,15 @@ [password setPassword:@"asdasdasd"]; [password setConfirmPassword:@"asdasdasd"]; - User *user = [User currentUser]; + User *user = [User new]; [user setFirstName:@"Giuseppe"]; [user setLastName:@"Nuficora"]; - [user setEmail:@"packman@giuseppenucifora.com"]; + [user setEmail:@"packman5@giuseppenucifora.com"]; [user setPassword:password]; - [user setHasAcceptedNewsletter:NO]; + [user setHasAcceptedNewsletter:YES]; [user setHasAcceptedPrivacy:YES]; - [user saveLocally]; + //[user saveLocally]; NSLog(@"%@",[user JSONFormObject]); //NSLog(@"%@",[user JSONObjectMap]); diff --git a/PNObject.podspec b/PNObject.podspec index 58aa2f3..bdfccbb 100644 --- a/PNObject.podspec +++ b/PNObject.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = "PNObject" -s.version = "0.3.7" +s.version = "0.3.8" 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/PNInstallation.m b/Pod/Classes/PNClasses/PNInstallation.m index de6fa04..9b46a96 100644 --- a/Pod/Classes/PNClasses/PNInstallation.m +++ b/Pod/Classes/PNClasses/PNInstallation.m @@ -19,7 +19,7 @@ @implementation PNInstallation -static PNInstallation *SINGLETON = nil; +static PNInstallation *INSTALLATION = nil; static bool isFirstAccess = YES; @@ -61,10 +61,10 @@ static bool isFirstAccess = YES; dispatch_once(&onceToken, ^{ isFirstAccess = NO; - SINGLETON = [[super allocWithZone:NULL] init]; + INSTALLATION = [[super allocWithZone:NULL] init]; }); - return SINGLETON; + return INSTALLATION; } - (void)setDeviceTokenFromData:(NSData *)deviceTokenData { @@ -85,8 +85,8 @@ static bool isFirstAccess = YES; - (id) init { - if(SINGLETON){ - return SINGLETON; + if(INSTALLATION){ + return INSTALLATION; } if (isFirstAccess) { [self doesNotRecognizeSelector:_cmd]; diff --git a/Pod/Classes/PNClasses/PNUser.h b/Pod/Classes/PNClasses/PNUser.h index e3f4319..b7425e4 100644 --- a/Pod/Classes/PNClasses/PNUser.h +++ b/Pod/Classes/PNClasses/PNUser.h @@ -136,6 +136,10 @@ * <#Description#> */ @property (nonatomic) BOOL hasVerifiedEmail; +/** + * <#Description#> + */ +@property (nonatomic) BOOL hasVerifiedPhone; /** * <#Description#> */ diff --git a/Pod/Classes/PNClasses/PNUser.m b/Pod/Classes/PNClasses/PNUser.m index 229e34e..042367b 100644 --- a/Pod/Classes/PNClasses/PNUser.m +++ b/Pod/Classes/PNClasses/PNUser.m @@ -28,7 +28,7 @@ @synthesize password = _password; -static PNUser *SINGLETON = nil; +static id USER = nil; static bool isFirstAccess = YES; @@ -39,15 +39,15 @@ static bool isFirstAccess = YES; dispatch_once(&onceToken, ^{ isFirstAccess = NO; - SINGLETON = [[super allocWithZone:NULL] initForCurrentUser]; + USER = [[super allocWithZone:NULL] initForCurrentUser]; }); - return SINGLETON; + return USER; } + (instancetype)resetUser { - [SINGLETON autoRemoveLocally]; - SINGLETON = nil; + [USER autoRemoveLocally]; + USER = nil; return [self currentUser]; } @@ -65,8 +65,8 @@ static bool isFirstAccess = YES; - (instancetype) initForCurrentUser { - if(SINGLETON){ - return SINGLETON; + if(USER){ + return USER; } if (isFirstAccess) { [self doesNotRecognizeSelector:_cmd]; @@ -75,19 +75,17 @@ static bool isFirstAccess = YES; NSDictionary *savedUser = [[PNObjectModel sharedInstance] fetchObjectsWithClass:[self class]]; if (savedUser) { - SINGLETON = [super initWithJSON:savedUser]; - } - else { - SINGLETON = [super init]; + USER = [super initWithJSON:savedUser]; } - if (SINGLETON) { + if (USER) { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ [self autoLogin]; }); } - return SINGLETON; + + return USER; } - (void) setEmail:(NSString *)email { @@ -156,7 +154,7 @@ static bool isFirstAccess = YES; [self POSTWithEndpointAction:@"registration/register" parameters:[self JSONFormObject] progress:nil - success:^(NSURLSessionDataTask * _Nullable task, PNObject * _Nullable responseObject) { + success:^(NSURLSessionDataTask * _Nullable task, NSDictionary * _Nullable responseObject) { NSLog(@"response %@",responseObject); if(success){ success(self); @@ -294,8 +292,7 @@ static bool isFirstAccess = YES; + (NSDictionary *)objcetMapping { NSDictionary *mapping = @{ - @"userId":@"id", - @"userUUID":@"uuid", + @"userId":@"uuid", @"firstName":@"firstName", @"lastName":@"lastName", @"profileImage":@"profileImage", @@ -306,6 +303,7 @@ static bool isFirstAccess = YES; @"hasAcceptedPrivacy":@"hasAcceptedPrivacy", @"hasAcceptedNewsletter":@"hasAcceptedNewsletter", @"hasVerifiedEmail":@"hasVerifiedEmail", + @"hasVerifiedPhone":@"has_verified_phone", @"emailVerifiedDate":@"emailVerifiedDate", @"email":@"email", @"username":@"username", diff --git a/Pod/Classes/PNObject+PNObjectConnection.h b/Pod/Classes/PNObject+PNObjectConnection.h index ec28bda..0dc08a2 100644 --- a/Pod/Classes/PNObject+PNObjectConnection.h +++ b/Pod/Classes/PNObject+PNObjectConnection.h @@ -13,13 +13,15 @@ - (void) GETWithEndpointAction:(NSString * _Nonnull) endPoint progress:(nullable void (^)(NSProgress * _Nonnull downloadProgress)) downloadProgress - success:(nullable void (^)(NSURLSessionDataTask * _Nullable task, id _Nullable responseObject))success + 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 parameters:(NSDictionary * _Nonnull) parameters progress:(nullable void (^)(NSProgress * _Nonnull uploadProgress)) uploadProgress - success:(nullable void (^)(NSURLSessionDataTask * _Nullable task, id _Nullable responseObject))success + 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 diff --git a/Pod/Classes/PNObject+PNObjectConnection.m b/Pod/Classes/PNObject+PNObjectConnection.m index 7967947..a232a5c 100644 --- a/Pod/Classes/PNObject+PNObjectConnection.m +++ b/Pod/Classes/PNObject+PNObjectConnection.m @@ -18,7 +18,7 @@ - (void) GETWithEndpointAction:(NSString * _Nonnull) endPoint progress:(nullable void (^)(NSProgress * _Nonnull downloadProgress)) downloadProgress - success:(nullable void (^)(NSURLSessionDataTask * _Nullable task, id _Nullable responseObject))success + success:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSDictionary * _Nullable responseObject))success failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error))failure { @@ -27,7 +27,7 @@ [[[PNObjectConfig sharedInstance] manager] GET:[[[PNObjectConfig sharedInstance] baseUrl] stringByAppendingFormat:@"%@",endPoint] parameters:nil progress:downloadProgress success:^(NSURLSessionDataTask *task, id responseObject) { if (success) { - success(task,[[self class] parseObjectFromResponse:responseObject]); + success(task,responseObject); } } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { @@ -51,7 +51,7 @@ - (void) POSTWithEndpointAction:(NSString * _Nonnull) endPoint parameters:(NSDictionary * _Nonnull) parameters progress:(nullable void (^)(NSProgress * _Nonnull uploadProgress)) uploadProgress - success:(nullable void (^)(NSURLSessionDataTask * _Nullable task, id _Nullable responseObject))success + 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]) { @@ -59,7 +59,7 @@ [[[PNObjectConfig sharedInstance] manager] POST:[[[PNObjectConfig sharedInstance] baseUrl] stringByAppendingFormat:@"%@",endPoint] parameters:parameters progress:uploadProgress success:^(NSURLSessionDataTask *task, id responseObject) { if (success) { - success(task,[[self class] parseObjectFromResponse:responseObject]); + success(task,responseObject); } } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { diff --git a/Pod/Classes/PNObject+Protected.m b/Pod/Classes/PNObject+Protected.m index 433b384..d8cf852 100644 --- a/Pod/Classes/PNObject+Protected.m +++ b/Pod/Classes/PNObject+Protected.m @@ -371,124 +371,6 @@ NSString * const PNObjectMappingSelector = @"PNObjectLocalNotificationRefreshTok })(); } } - - /*for (NSString* propertyName in self.JSONObjectMap) { - - id mappingValue = [self.JSONObjectMap objectForKey:propertyName]; - - if([mappingValue isKindOfClass:NSDictionary.class]) { - mappedJSONKey = [mappingValue valueForKey:@"key"]; - mappedJSONType = [mappingValue valueForKey:@"type"]; - } else { - mappedJSONKey = mappingValue; - } - - NSString *propertyType = [properties valueForKey:propertyName]; - - if (![[formMapping allKeys] containsObject:propertyName]) { - continue; - } - - id value = [self valueForKey:propertyName]; - //TODO: forse รจ da sostituire propertyName con il valore de - ((void (^)())@{ - @"c" : ^{ - char val = [value charValue]; - [JSON setValue:@(val) forKey:propertyName]; - }, - @"d" : ^{ - double val = [value doubleValue]; - [JSON setValue:@(val) forKey:propertyName]; - }, - @"f" : ^{ - float val = [value floatValue]; - [JSON setValue:@(val) forKey:propertyName]; - }, - @"i" : ^{ - int val = [value intValue]; - [JSON setValue:@(val) forKey:propertyName]; - }, - @"l" : ^{ - long val = [value longValue]; - [JSON setValue:@(val) forKey:propertyName]; - }, - @"s" : ^{ - short val = [value shortValue]; - [JSON setValue:@(val) forKey:propertyName]; - }, - @"B" : ^{ - BOOL val = [value boolValue]; - [JSON setValue:@(val) forKey:propertyName]; - }, - - @"UIImage" : ^{ - UIImage *image = [UIImage imageWithData:value]; - [JSON setValue:image forKey:propertyName]; - }, - @"NSURL" : ^{ - NSURL *url = value; - - if (![self isObjNull:url]) { - [JSON setValue:[url absoluteString] forKey:propertyName]; - } - }, - @"NSString" : ^{ - NSString *val = [NSString stringWithFormat:@"%@", value]; - if (![self isObjNull:val]) { - [JSON setValue:val forKey:propertyName]; - } - }, - @"NSNumber" : ^{ - NSInteger val = [value integerValue]; - [JSON setValue:@(val) forKey:propertyName]; - }, - @"NSDate" : ^{ - NSDate *val = [value toLocalTime]; - if (![self isObjNull:val]) { - [JSON setValue:val forKey:propertyName]; - } - }, - @"NSArray" : ^{ - NSMutableArray *arr = [NSMutableArray array]; - for(id object in value) { - - BOOL isPNObjectSubclass = [[object class] isSubclassOfClass:[PNObject class]]; - if(isPNObjectSubclass) { - NSDictionary *objectDict = [(PNObject*) object reverseMapping]; - - [arr addObject:objectDict]; - } - } - - [JSON setValue:arr forKey:propertyName]; - }, - @"NSMutableArray" : ^{ - NSMutableArray *arr = [NSMutableArray array]; - for(id object in value) { - - BOOL isPNObjectSubclass = [[object class] isSubclassOfClass:[PNObject class]]; - if(isPNObjectSubclass) { - NSDictionary *objectDict = [(PNObject*) object reverseMapping]; - - [arr addObject:objectDict]; - } - } - - [JSON setValue:arr forKey:propertyName]; - } - }[propertyType] ?: ^{ - BOOL isPNObjectSubclass = [NSClassFromString(propertyType) isSubclassOfClass:[PNObject class]]; - if(isPNObjectSubclass) { - - NSDictionary *objectDict = [(PNObject*)value reverseMapping]; - - [JSON setValue:objectDict forKey:propertyName]; - } - else { - // do nothing - } - })(); - }*/ } return JSON; } diff --git a/Pod/Classes/PNObject.m b/Pod/Classes/PNObject.m index 0e88ab0..64c6150 100644 --- a/Pod/Classes/PNObject.m +++ b/Pod/Classes/PNObject.m @@ -412,7 +412,7 @@ } } - self.JSON = nil; + _JSON = nil; _JSONObjectMap = nil; _objID = nil; _createdAt = nil; diff --git a/Pod/Classes/PNObjectConfig.h b/Pod/Classes/PNObjectConfig.h index 82f58ce..6e52d43 100644 --- a/Pod/Classes/PNObjectConfig.h +++ b/Pod/Classes/PNObjectConfig.h @@ -14,13 +14,6 @@ #import "AFHTTPRequestSerializer+OAuth2.h" #import "AFOAuthCredential.h" -typedef NS_ENUM(NSInteger, Environment) { - Development = 0, - Stage = 1, - Production = 2 -}; - - #pragma mark LocalNotification Keys extern NSString* _Nonnull const PNObjectLocalNotificationRefreshTokenClientCredentialSuccess; @@ -79,7 +72,7 @@ extern NSString* _Nonnull const Client_Secret; * * @param env <#env description#> */ -- (void) setEnvironment:(Environment) env; +- (void) setEnvironment:(NSString * _Nonnull) environment; /** * <#Description#> @@ -92,12 +85,12 @@ extern NSString* _Nonnull const Client_Secret; /** * <#Description#> * - * @param value <#value description#> + * @param value EnvironmentProduction, EnvironmentStage, EnvironmentDevelopment * @param key <#key description#> */ - (void) removeHTTPHeaderValueForKey:(NSString * _Nonnull) key; -- (void) setClientID:(NSString * _Nonnull) clientID clientSecret:(NSString* _Nonnull) clientSecret forEnv:(Environment) environment; +- (void) setClientID:(NSString * _Nonnull) clientID clientSecret:(NSString* _Nonnull) clientSecret forEnv:(NSString * _Nonnull) environment; /** * <#Description#> @@ -178,6 +171,6 @@ extern NSString* _Nonnull const Client_Secret; /** * <#Description#> */ -@property (nonatomic, strong, readonly) NSString *encrypKey; +@property (nonatomic, strong, nonnull , readonly) NSString *encrypKey; @end \ No newline at end of file diff --git a/Pod/Classes/PNObjectConfig.m b/Pod/Classes/PNObjectConfig.m index 034d751..0c0c532 100644 --- a/Pod/Classes/PNObjectConfig.m +++ b/Pod/Classes/PNObjectConfig.m @@ -42,11 +42,11 @@ NSString* const Client_Secret = @"client_secret"; @property (nonatomic, strong) NSMutableDictionary *configuration; @property (nonatomic, strong) NSMutableDictionary *headerFields; -@property (nonatomic) Environment currentEnv; +@property (nonatomic, strong) NSString *currentEnv; @property (nonatomic, strong) NSString *currentEndPointBaseUrl; @property (nonatomic, strong) NSString *currentOAuthClientID; @property (nonatomic, strong) NSString *currentOAuthClientSecret; -@property (nonatomic, strong) NSMutableArray *environments; +//@property (nonatomic, strong) NSMutableDictionary *environments; @end @@ -84,16 +84,14 @@ static bool isFirstAccess = YES; SINGLETON.oauthEnabled = oauthEnabled; for (NSString *key in [endpointUrlsForEnvironments allKeys]) { - if ([SINGLETON.environments containsObject:key]) { - - NSURL * endpointUrl = [NSURL URLWithString:[endpointUrlsForEnvironments objectForKey:key]]; - if (endpointUrl) { - [SINGLETON.configuration setValue:[NSDictionary dictionaryWithObjectsAndKeys:[endpointUrl absoluteString],BaseUrl, nil] forKey:key]; - } + NSURL * endpointUrl = [NSURL URLWithString:[endpointUrlsForEnvironments objectForKey:key]]; + if (endpointUrl) { + [SINGLETON.configuration setValue:[NSDictionary dictionaryWithObjectsAndKeys:[endpointUrl absoluteString],BaseUrl, nil] forKey:key]; } + } NSAssert([SINGLETON.configuration objectForKey:EnvironmentProduction], @"EnvironmentProduction must be valid endpoint url"); - [SINGLETON setEnvironment:Production]; + [SINGLETON setEnvironment:EnvironmentProduction]; @@ -138,11 +136,9 @@ static bool isFirstAccess = YES; if (self) { if (_oauthEnabled) { - _currentOauthCredential = [AFOAuthCredential retrieveCredentialWithIdentifier:PNObjectServiceCredentialIdentifier]; + [AFOAuthCredential deleteCredentialWithIdentifier:PNObjectServiceCredentialIdentifier]; } - _environments = [[NSMutableArray alloc] initWithArray:@[EnvironmentDevelopment,EnvironmentStage,EnvironmentProduction]]; - _configuration = [[NSMutableDictionary alloc] init]; _minPasswordLenght = minPassLenght; @@ -162,30 +158,20 @@ static bool isFirstAccess = YES; return self; } -- (void) setEnvironment:(Environment) env { +- (void) setEnvironment:(NSString * _Nonnull) environment { - _currentEnv = env; + _currentEnv = environment; _currentEndPointBaseUrl = nil; _currentOAuthClientID = nil; _currentOAuthClientSecret = nil; - if (env < [_environments count]) { - if ([_configuration objectForKey:[_environments objectAtIndex:env]]) { - _currentEndPointBaseUrl = [[_configuration objectForKey:[_environments objectAtIndex:env]] objectForKey:BaseUrl]; - _currentOAuthClientID = [[_configuration objectForKey:[_environments objectAtIndex:env]] objectForKey:Client_ID]; - _currentOAuthClientSecret = [[_configuration objectForKey:[_environments objectAtIndex:env]] objectForKey:Client_Secret]; + if ([_configuration objectForKey:environment]) { + _currentEndPointBaseUrl = [[_configuration objectForKey:_currentEnv] objectForKey:BaseUrl]; + _currentOAuthClientID = [[_configuration objectForKey:_currentEnv] objectForKey:Client_ID]; + _currentOAuthClientSecret = [[_configuration objectForKey:_currentEnv] objectForKey:Client_Secret]; } - } - else { - _currentEndPointBaseUrl = [[_configuration objectForKey:EnvironmentProduction] objectForKey:BaseUrl]; - if ([[_configuration objectForKey:EnvironmentProduction] objectForKey:Client_ID]) { - _currentOAuthClientID = [[_configuration objectForKey:EnvironmentProduction] objectForKey:Client_ID]; - } - if ([[_configuration objectForKey:EnvironmentProduction] objectForKey:Client_Secret]) { - _currentOAuthClientSecret = [[_configuration objectForKey:EnvironmentProduction] objectForKey:Client_Secret]; - } - } - NSLog(@"%@",[[_configuration objectForKey:[_environments objectAtIndex:env]] objectForKey:BaseUrl]); + + NSLog(@"%@",[[_configuration objectForKey:_currentEnv] objectForKey:BaseUrl]); NSAssert(_currentEndPointBaseUrl,@"Selected environment generate error. Please check configuration"); @@ -205,7 +191,7 @@ static bool isFirstAccess = YES; _manager = [AFOAuth2Manager manager]; } - _currentOauthCredential = [AFOAuthCredential retrieveCredentialWithIdentifier:PNObjectServiceCredentialIdentifier]; + //_currentOauthCredential = [AFOAuthCredential retrieveCredentialWithIdentifier:PNObjectServiceCredentialIdentifier]; if (_oauthEnabled && _currentOAuthClientID && _currentOAuthClientSecret) { @@ -246,7 +232,7 @@ static bool isFirstAccess = YES; } - (void) refreshToken { - if([PNUser currentUser] && [[PNUser currentUser] hasValidEmailAndPasswordData]) { + if([PNUser currentUser] && [[PNUser currentUser] hasValidEmailAndPasswordData]) { [self refreshTokenForUser]; } else { @@ -296,7 +282,7 @@ static bool isFirstAccess = YES; if (![email isValidEmail]) { if (failure) { - NSError *error = [NSError errorWithDomain:NSLocalizedString(@"Email is not valid", @"") code:kHTTPStatusCodeBadRequest userInfo:nil]; + NSError *error = [NSError errorWithDomain:NSLocalizedString(@"Email is not valid", @"") code:kHTTPStatusCodeBadRequest userInfo:nil]; failure(error); return; } @@ -308,22 +294,22 @@ static bool isFirstAccess = YES; return; } } - [_manager authenticateUsingOAuthWithURLString:[_currentEndPointBaseUrl stringByAppendingString:@"oauth-token"] username:email password:password scope:nil success:^(AFOAuthCredential * _Nonnull credential) { - _currentOauthCredential = credential; + [_manager authenticateUsingOAuthWithURLString:[_currentEndPointBaseUrl stringByAppendingString:@"oauth-token"] username:email password:password scope:nil success:^(AFOAuthCredential * _Nonnull credential) { + _currentOauthCredential = credential; - [AFOAuthCredential storeCredential:_currentOauthCredential withIdentifier:PNObjectServiceCredentialIdentifier]; - [_manager.requestSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential]; - - if (success) { - success(YES); - } - } failure:^(NSError * _Nonnull error) { + [AFOAuthCredential storeCredential:_currentOauthCredential withIdentifier:PNObjectServiceCredentialIdentifier]; + [_manager.requestSerializer setAuthorizationHeaderFieldWithCredential:_currentOauthCredential]; - [[NSNotificationCenter defaultCenter] postNotificationName:PNObjectLocalNotificationRefreshTokenUserFail object:error]; - if (failure) { - failure(error); - } - }]; + if (success) { + success(YES); + } + } failure:^(NSError * _Nonnull error) { + + [[NSNotificationCenter defaultCenter] postNotificationName:PNObjectLocalNotificationRefreshTokenUserFail object:error]; + if (failure) { + failure(error); + } + }]; } - (void) refreshTokenForClientCredential { @@ -368,16 +354,16 @@ static bool isFirstAccess = YES; } } -- (void) setClientID:(NSString * _Nonnull) clientID clientSecret:(NSString* _Nonnull) clientSecret forEnv:(Environment) environment { +- (void) setClientID:(NSString * _Nonnull) clientID clientSecret:(NSString* _Nonnull) clientSecret forEnv:(NSString *) environment { - if ([_configuration objectForKey:[_environments objectAtIndex:environment]]) { + if ([_configuration objectForKey:environment]) { - NSMutableDictionary *currentConfigurationDict = [[NSMutableDictionary alloc] initWithDictionary:[_configuration objectForKey:[_environments objectAtIndex:environment]]]; + NSMutableDictionary *currentConfigurationDict = [[NSMutableDictionary alloc] initWithDictionary:[_configuration objectForKey:environment]]; [currentConfigurationDict setObject:clientID forKey:Client_ID]; [currentConfigurationDict setObject:clientSecret forKey:Client_Secret]; - - [_configuration setObject:currentConfigurationDict forKey:[_environments objectAtIndex:environment]]; - + + [_configuration setObject:currentConfigurationDict forKey:environment]; + if (_currentEnv == environment) { [self setEnvironment:environment]; } diff --git a/Pod/Classes/PNObjectModel.h b/Pod/Classes/PNObjectModel.h index ac4f93e..e3f36db 100644 --- a/Pod/Classes/PNObjectModel.h +++ b/Pod/Classes/PNObjectModel.h @@ -41,15 +41,6 @@ */ - (id _Nonnull) saveLocally:(id _Nonnull) object; -/** - * <#Description#> - * - * @param object <#object description#> - * - * @return <#return value description#> - */ -- (id _Nonnull) saveNSUSerDefautls:(id _Nonnull) object; - /** * <#Description#> * diff --git a/Pod/Classes/PNObjectModel.m b/Pod/Classes/PNObjectModel.m index 3ad86be..29d4804 100644 --- a/Pod/Classes/PNObjectModel.m +++ b/Pod/Classes/PNObjectModel.m @@ -238,9 +238,9 @@ static bool isFirstAccess = YES; } } -- (id _Nonnull) saveNSUSerDefautls:(id _Nonnull) object { +/*- (id _Nonnull) saveNSUSerDefautls:(id _Nonnull) object { -} +}*/ - (BOOL) removeObjectLocally:(id _Nonnull) object { BOOL isPNObjectSubclass = [[object class] isSubclassOfClass:[PNObject class]];