From d45c68f35b1e8e34dc502cdc017a4120dfff80b2 Mon Sep 17 00:00:00 2001 From: Giuseppe Nucifora Date: Mon, 16 Jan 2017 14:41:36 +0100 Subject: [PATCH] - Fix Installation Date --- Example/PNObject.xcodeproj/project.pbxproj | 9 ++ Example/PNObject/PNObjAppDelegate.m | 47 ++++++ Example/PNObject_Example.entitlements | 8 + Example/Podfile.lock | 8 +- .../Pods/Local Podspecs/PNObject.podspec.json | 4 +- Example/Pods/Manifest.lock | 8 +- .../Pod/Classes/NSDate+NSDate_Util.h | 24 ++- .../Pod/Classes/NSDate+NSDate_Util.m | 18 ++- PNObject.podspec | 2 +- PNObject/Classes/PNClasses/PNInstallation.h | 12 ++ PNObject/Classes/PNClasses/PNInstallation.m | 137 +++++++++++++++++- 11 files changed, 253 insertions(+), 24 deletions(-) create mode 100644 Example/PNObject_Example.entitlements diff --git a/Example/PNObject.xcodeproj/project.pbxproj b/Example/PNObject.xcodeproj/project.pbxproj index df253db..ebeb57b 100644 --- a/Example/PNObject.xcodeproj/project.pbxproj +++ b/Example/PNObject.xcodeproj/project.pbxproj @@ -61,6 +61,7 @@ 6003F5BB195388D20070C39A /* Tests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Tests.m; sourceTree = ""; }; 606FC2411953D9B200FFA9A0 /* Tests-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Tests-Prefix.pch"; sourceTree = ""; }; 68119C951E155BAA00E066C7 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; }; + 681A32481E2CFB7300DF98BF /* PNObject_Example.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = PNObject_Example.entitlements; sourceTree = ""; }; 873B8AEA1B1F5CCA007FD442 /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = ""; }; A90E0E5930707E3F83662328 /* Pods-PNObject_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PNObject_Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-PNObject_Tests/Pods-PNObject_Tests.debug.xcconfig"; sourceTree = ""; }; C0F786F6B0C2234E3B3A5F30 /* Pods-PNObject_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PNObject_Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-PNObject_Tests/Pods-PNObject_Tests.release.xcconfig"; sourceTree = ""; }; @@ -99,6 +100,7 @@ 6003F581195388D10070C39A = { isa = PBXGroup; children = ( + 681A32481E2CFB7300DF98BF /* PNObject_Example.entitlements */, 60FF7A9C1954A5C5007DD14C /* Podspec Metadata */, 6003F593195388D20070C39A /* Example for PNObject */, 6003F5B5195388D20070C39A /* Tests */, @@ -253,6 +255,11 @@ TargetAttributes = { 6003F589195388D20070C39A = { DevelopmentTeam = 825G85A28E; + SystemCapabilities = { + com.apple.Push = { + enabled = 1; + }; + }; }; 6003F5AD195388D20070C39A = { TestTargetID = 6003F589195388D20070C39A; @@ -529,6 +536,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; + CODE_SIGN_ENTITLEMENTS = PNObject_Example.entitlements; DEVELOPMENT_TEAM = 825G85A28E; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "PNObject/PNObject-Prefix.pch"; @@ -546,6 +554,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; + CODE_SIGN_ENTITLEMENTS = PNObject_Example.entitlements; DEVELOPMENT_TEAM = 825G85A28E; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "PNObject/PNObject-Prefix.pch"; diff --git a/Example/PNObject/PNObjAppDelegate.m b/Example/PNObject/PNObjAppDelegate.m index cdbdcff..1579702 100644 --- a/Example/PNObject/PNObjAppDelegate.m +++ b/Example/PNObject/PNObjAppDelegate.m @@ -19,6 +19,7 @@ #import "UIDevice-Hardware.h" #import +#import @implementation PNObjAppDelegate @@ -156,6 +157,52 @@ //[installation setUser:nil]; + [self updateDeviceUser]; + +} + +- (void) updateDeviceUser { + + + PNInstallation * installation = [PNInstallation currentInstallation]; + + if ([PNUser currentUser] && [[PNUser currentUser] isAuthenticated]) { + [[PNInstallation currentInstallation] setUser:[PNUser currentUser]]; + } + else { + [[PNInstallation currentInstallation] setUser:nil]; + } + + if (![[PNInstallation currentInstallation] registeredAt] || [[NSDate date] isLaterThanDate:[[[PNInstallation currentInstallation] lastTokenUpdate] dateByAddingDays:1]]) { + [self registerRemoteDevice]; + } + else if ([[PNInstallation currentInstallation] updatedAt] || [[NSDate date] isLaterThanDate:[[[PNInstallation currentInstallation] updatedAt] dateByAddingMinutes:30]]) { + [self updateRemoteDevice]; + } +} + +- (void) registerRemoteDevice { + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [[PNInstallation currentInstallation] registerDeviceWithBlockProgress:^(NSProgress * _Nonnull uploadProgress) { + + } Success:^(BOOL response) { + NSLog(@"device registrato"); + } failure:^(NSError * _Nonnull error) { + NSLog(@"device non registrato"); + }]; + }); +} + +- (void) updateRemoteDevice { + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [[PNInstallation currentInstallation] updateDeviceWithBlockProgress:^(NSProgress * _Nonnull uploadProgress) { + + } Success:^(BOOL response) { + NSLog(@"device aggiornato"); + } failure:^(NSError * _Nonnull error) { + NSLog(@"device non aggiornato"); + }]; + }); } - (void) application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings { diff --git a/Example/PNObject_Example.entitlements b/Example/PNObject_Example.entitlements new file mode 100644 index 0000000..903def2 --- /dev/null +++ b/Example/PNObject_Example.entitlements @@ -0,0 +1,8 @@ + + + + + aps-environment + development + + diff --git a/Example/Podfile.lock b/Example/Podfile.lock index 070502a..875cdb6 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -33,11 +33,11 @@ PODS: - FBSDKShareKit (4.18.0): - FBSDKCoreKit - NSDataAES (0.2.2) - - NSDate_Utils (1.0.3) + - NSDate_Utils (1.0.5) - NSString-Helper (1.0.5) - nv-ios-http-status (0.0.1) - PEAR-FileManager-iOS (1.3.1) - - PNObject (1.1.1): + - PNObject (1.1.5): - AFNetworking - CodFis-Helper - DDDKeychainWrapper @@ -80,11 +80,11 @@ SPEC CHECKSUMS: FBSDKLoginKit: 6773073e970b2b15fb12e451ce7f11da0532b880 FBSDKShareKit: 0b8d6cc3f103c75297eb3c62caec284a2ccf1b9e NSDataAES: 967ea3337476a80e9838a533c25d570a06855ed0 - NSDate_Utils: 2fb4071323341507c610821bc99b98ef8c46d4ac + NSDate_Utils: b0ab72ccec6df25297766bd64b0cd0c124521a45 NSString-Helper: 459e1b6a62b3bf7db10f01b0d102548608e945c4 nv-ios-http-status: b6c2b5fc8656cc19e0d3000dadce2080b99d0e2f PEAR-FileManager-iOS: 3bc403f68a53483f5629aa822f4649e40275c4d3 - PNObject: f38657e6b3e643f397da970c9e454bd2991b5b94 + PNObject: 38f5fa8f707f7c53579c81a2c425ad7c2d04cb78 PureLayout: 4d550abe49a94f24c2808b9b95db9131685fe4cd RZDataBinding: 6981e90ddaae2f5e02028323b1043f8c31013109 Specta: ac94d110b865115fe60ff2c6d7281053c6f8e8a2 diff --git a/Example/Pods/Local Podspecs/PNObject.podspec.json b/Example/Pods/Local Podspecs/PNObject.podspec.json index 651bd52..eee1824 100644 --- a/Example/Pods/Local Podspecs/PNObject.podspec.json +++ b/Example/Pods/Local Podspecs/PNObject.podspec.json @@ -1,6 +1,6 @@ { "name": "PNObject", - "version": "1.1.1", + "version": "1.1.5", "summary": "PNObject is a simple replica of the more complex ParseObject", "homepage": "https://git.giuseppenucifora.com/giuseppenucifora/PNObject", "license": { @@ -12,7 +12,7 @@ }, "source": { "git": "https://git.giuseppenucifora.com/giuseppenucifora/PNObject.git", - "tag": "1.1.1" + "tag": "1.1.5" }, "platforms": { "ios": "8.0" diff --git a/Example/Pods/Manifest.lock b/Example/Pods/Manifest.lock index 070502a..875cdb6 100644 --- a/Example/Pods/Manifest.lock +++ b/Example/Pods/Manifest.lock @@ -33,11 +33,11 @@ PODS: - FBSDKShareKit (4.18.0): - FBSDKCoreKit - NSDataAES (0.2.2) - - NSDate_Utils (1.0.3) + - NSDate_Utils (1.0.5) - NSString-Helper (1.0.5) - nv-ios-http-status (0.0.1) - PEAR-FileManager-iOS (1.3.1) - - PNObject (1.1.1): + - PNObject (1.1.5): - AFNetworking - CodFis-Helper - DDDKeychainWrapper @@ -80,11 +80,11 @@ SPEC CHECKSUMS: FBSDKLoginKit: 6773073e970b2b15fb12e451ce7f11da0532b880 FBSDKShareKit: 0b8d6cc3f103c75297eb3c62caec284a2ccf1b9e NSDataAES: 967ea3337476a80e9838a533c25d570a06855ed0 - NSDate_Utils: 2fb4071323341507c610821bc99b98ef8c46d4ac + NSDate_Utils: b0ab72ccec6df25297766bd64b0cd0c124521a45 NSString-Helper: 459e1b6a62b3bf7db10f01b0d102548608e945c4 nv-ios-http-status: b6c2b5fc8656cc19e0d3000dadce2080b99d0e2f PEAR-FileManager-iOS: 3bc403f68a53483f5629aa822f4649e40275c4d3 - PNObject: f38657e6b3e643f397da970c9e454bd2991b5b94 + PNObject: 38f5fa8f707f7c53579c81a2c425ad7c2d04cb78 PureLayout: 4d550abe49a94f24c2808b9b95db9131685fe4cd RZDataBinding: 6981e90ddaae2f5e02028323b1043f8c31013109 Specta: ac94d110b865115fe60ff2c6d7281053c6f8e8a2 diff --git a/Example/Pods/NSDate_Utils/Pod/Classes/NSDate+NSDate_Util.h b/Example/Pods/NSDate_Utils/Pod/Classes/NSDate+NSDate_Util.h index 4e2e633..84fe9b2 100755 --- a/Example/Pods/NSDate_Utils/Pod/Classes/NSDate+NSDate_Util.h +++ b/Example/Pods/NSDate_Utils/Pod/Classes/NSDate+NSDate_Util.h @@ -42,14 +42,23 @@ static NSString * _Nonnull kNSDateHelperFormatSQLDateWithTimeIT_shashSeparated static NSString * _Nonnull kNSDateHelperFormatSQLDateWithTimeEN = @"MM-dd-yyyy HH:mm:ss"; static NSString * _Nonnull kNSDateHelperFormatSQLDateWithTimeEN_shashSeparated = @"MM/dd/yyyy HH:mm:ss"; -static NSString * _Nonnull kNSDateHelperFormatSQLDateWithTimeZone = @"yyyy-MM-dd'T'HH:mm:ss'Z'"; -static NSString * _Nonnull kNSDateHelperFormatSQLDateWithTimeZone_shashSeparated = @"yyyy/MM/dd'T'HH:mm:ss'Z'"; +static NSString * _Nonnull kNSDateHelperFormatSQLDateWithTimeZone_T_Separator = @"yyyy-MM-dd'T'HH:mm:ss ZZZ"; +static NSString * _Nonnull kNSDateHelperFormatSQLDateWithTimeZone_T_Separator_shashSeparated = @"yyyy/MM/dd'T'HH:mm:ss ZZZ"; -static NSString * _Nonnull kNSDateHelperFormatSQLDateWithTimeZoneEN = @"MM-dd-yyyy'T'HH:mm:ss'Z'"; -static NSString * _Nonnull kNSDateHelperFormatSQLDateWithTimeZoneEN_shashSeparated = @"MM/dd/yyyy'T'HH:mm:ss'Z'"; +static NSString * _Nonnull kNSDateHelperFormatSQLDateWithTimeZoneEN_T_Separator = @"MM-dd-yyyy'T'HH:mm:ss ZZZ"; +static NSString * _Nonnull kNSDateHelperFormatSQLDateWithTimeZoneENAndTSeparator_shashSeparated = @"MM/dd/yyyy'T'HH:mm:ss ZZZ"; -static NSString * _Nonnull kNSDateHelperFormatSQLDateWithTimeZoneIT = @"dd-MM-yyyy'T'HH:mm:ss'Z'"; -static NSString * _Nonnull kNSDateHelperFormatSQLDateWithTimeZoneIT_shashSeparated = @"dd/MM/yyyy'T'HH:mm:ss'Z'"; +static NSString * _Nonnull kNSDateHelperFormatSQLDateWithTimeZoneIT_T_Separator = @"dd-MM-yyyy'T'HH:mm:ss ZZZ"; +static NSString * _Nonnull kNSDateHelperFormatSQLDateWithTimeZoneIT_T_Separator_shashSeparated = @"dd/MM/yyyy'T'HH:mm:ss ZZZ"; + +static NSString * _Nonnull kNSDateHelperFormatSQLDateWithTimeZone = @"yyyy-MM-dd HH:mm:ss ZZZ"; +static NSString * _Nonnull kNSDateHelperFormatSQLDateWithTimeZone_shashSeparated = @"yyyy/MM/dd HH:mm:ss ZZZ"; + +static NSString * _Nonnull kNSDateHelperFormatSQLDateWithTimeZoneEN = @"MM-dd-yyyy HH:mm:ss ZZZ"; +static NSString * _Nonnull kNSDateHelperFormatSQLDateWithTimeZoneEN_shashSeparated = @"MM/dd/yyyy HH:mm:ss ZZZ"; + +static NSString * _Nonnull kNSDateHelperFormatSQLDateWithTimeZoneIT = @"dd-MM-yyyy HH:mm:ss ZZZ"; +static NSString * _Nonnull kNSDateHelperFormatSQLDateWithTimeZoneIT_shashSeparated = @"dd/MM/yyyy HH:mm:ss ZZZ"; @interface NSDate (NSDate_Util) @@ -82,6 +91,9 @@ static NSString * _Nonnull kNSDateHelperFormatSQLDateWithTimeZoneIT_shashSeparat + (NSString * _Nonnull) getUniversalHourFromDateString:(NSString * _Nonnull) string formatterString:(NSString * _Nonnull) formatterString andUppercaseString:(BOOL) uppercaseString; ++ (NSTimeInterval) timeIntervalFromMinutes:(NSUInteger) minutes; ++ (NSTimeInterval) timeIntervalFromHours:(NSUInteger) minutes; + - (NSDate * _Nonnull) dateToNearestMinutes:(NSInteger)minutes; - (NSDate * _Nonnull) dateByAddingMinutes:(NSInteger) dMinutes; diff --git a/Example/Pods/NSDate_Utils/Pod/Classes/NSDate+NSDate_Util.m b/Example/Pods/NSDate_Utils/Pod/Classes/NSDate+NSDate_Util.m index 01f1731..f4a59b2 100755 --- a/Example/Pods/NSDate_Utils/Pod/Classes/NSDate+NSDate_Util.m +++ b/Example/Pods/NSDate_Utils/Pod/Classes/NSDate+NSDate_Util.m @@ -194,7 +194,10 @@ static NSDateFormatter *_displayFormatter = nil; kNSDateHelperFormatSQLDateWithTimeEN_shashSeparated,kNSDateHelperFormatSQLDateWithTimeZone, kNSDateHelperFormatSQLDateWithTimeZone_shashSeparated,kNSDateHelperFormatSQLDateWithTimeZoneEN, kNSDateHelperFormatSQLDateWithTimeZoneEN_shashSeparated,kNSDateHelperFormatSQLDateWithTimeZoneIT, - kNSDateHelperFormatSQLDateWithTimeZoneIT_shashSeparated, nil]; + kNSDateHelperFormatSQLDateWithTimeZoneIT_shashSeparated,kNSDateHelperFormatSQLDateWithTimeZone_T_Separator, + kNSDateHelperFormatSQLDateWithTimeZone_T_Separator_shashSeparated,kNSDateHelperFormatSQLDateWithTimeZoneEN_T_Separator, + kNSDateHelperFormatSQLDateWithTimeZoneENAndTSeparator_shashSeparated, kNSDateHelperFormatSQLDateWithTimeZoneIT_T_Separator, + kNSDateHelperFormatSQLDateWithTimeZoneIT_T_Separator_shashSeparated, nil]; for (NSString *dateFormat in dateFormatsArray) { @@ -516,6 +519,19 @@ static NSDateFormatter *_displayFormatter = nil; } ++ (NSTimeInterval) timeIntervalFromMinutes:(NSUInteger) minutes { + + NSTimeInterval seconds = minutes /60; + + return seconds; +} + + ++ (NSTimeInterval) timeIntervalFromHours:(NSUInteger) hours { + +} + + - (NSDate *) dateAtStartOfDay { NSDateComponents *components = [CURRENT_CALENDAR components:DATE_COMPONENTS fromDate:self]; diff --git a/PNObject.podspec b/PNObject.podspec index b783118..da82ae3 100644 --- a/PNObject.podspec +++ b/PNObject.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'PNObject' -s.version = '1.1.3' +s.version = '1.1.5' s.summary = 'PNObject is a simple replica of the more complex ParseObject' diff --git a/PNObject/Classes/PNClasses/PNInstallation.h b/PNObject/Classes/PNClasses/PNInstallation.h index 4fa1cb1..13e2497 100644 --- a/PNObject/Classes/PNClasses/PNInstallation.h +++ b/PNObject/Classes/PNClasses/PNInstallation.h @@ -46,6 +46,18 @@ typedef NS_ENUM(NSInteger, PNInstallationStatus) { - (void) setUpdated; +- (void) registerDeviceWithBlockProgress:(nullable void (^)(NSProgress * _Nonnull uploadProgress)) uploadProgress + Success:(nullable void (^)(BOOL response))success + failure:(nullable void (^)(NSError * _Nonnull error))failure; + +- (void) updateDeviceWithBlockProgress:(nullable void (^)(NSProgress * _Nonnull uploadProgress)) uploadProgress + Success:(nullable void (^)(BOOL response))success + failure:(nullable void (^)(NSError * _Nonnull error))failure; + +- (void) removeDeviceWithBlockProgress:(nullable void (^)(NSProgress * _Nonnull uploadProgress)) uploadProgress + Success:(nullable void (^)(BOOL response))success + failure:(nullable void (^)(NSError * _Nonnull error))failure; + ///-------------------------------------- #pragma mark - PNInstallation Properties ///-------------------------------------- diff --git a/PNObject/Classes/PNClasses/PNInstallation.m b/PNObject/Classes/PNClasses/PNInstallation.m index c8bcda4..ec7ad31 100644 --- a/PNObject/Classes/PNClasses/PNInstallation.m +++ b/PNObject/Classes/PNClasses/PNInstallation.m @@ -9,6 +9,8 @@ #import "PNInstallation.h" #import "DJLocalization.h" #import "PNObjectConfig.h" +#import "PNObject+PNObjectConnection.h" +#import "NSDate+NSDate_Util.h" @@ -172,12 +174,6 @@ static bool isFirstAccess = YES; if (self) { - /*[super setValue:@"iOS" forKey:VariableName(deviceType)]; - [super setValue:[[UIDevice currentDevice] model] forKey:VariableName(deviceModel)]; - [super setValue:[[UIDevice currentDevice] systemVersion] forKey:VariableName(osVersion)]; - [self setValue:[[UIDevice currentDevice] name] forKey:VariableName(deviceName)]; - [self setValue:[[DJLocalizationSystem shared] language] forKey:VariableName(localeIdentifier)]; - */ _installationStatus = PNInstallationStatusNone; _deviceType = @"iOS"; _deviceModel = [[UIDevice currentDevice] model]; @@ -190,6 +186,135 @@ static bool isFirstAccess = YES; return self; } + +- (void) registerDeviceWithBlockProgress:(nullable void (^)(NSProgress * _Nonnull uploadProgress)) uploadProgress + Success:(nullable void (^)(BOOL response))success + failure:(nullable void (^)(NSError * _Nonnull error))failure { + [self registerDeviceForced:NO WithBlockProgress:uploadProgress Success:success failure:failure]; + +} + + +- (void) registerDeviceForced:(BOOL) forced + WithBlockProgress:(nullable void (^)(NSProgress * _Nonnull uploadProgress)) uploadProgress + Success:(nullable void (^)(BOOL response))success + failure:(nullable void (^)(NSError * _Nonnull error))failure { + if (self.deviceToken && (forced || !self.registeredAt || [self.registeredAt isEarlierThanDate:[[NSDate date] dateByAddingHours:3]])) { + + [[self class] POSTWithEndpointAction:@"device/register" parameters:[self registrationDeviceFormObject] + progress:uploadProgress + success:^(NSURLSessionDataTask * _Nullable task, NSDictionary * _Nullable responseObject) { + [self setRegistered]; + [self saveLocally]; + if(success){ + success(YES); + } + } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { + [self setRegistered]; + [self saveLocally]; + if (failure) { + failure(error); + } + }]; + } + else { + if (success) { + success(YES); + } + } +} + +- (NSDictionary * _Nonnull) registrationDeviceFormObject { + + NSMutableDictionary *registrationDeviceDictionary = [[NSMutableDictionary alloc] initWithDictionary:[self JSONFormObject]]; + + [registrationDeviceDictionary setObject:[self deviceType] forKey:@"platform"]; + + return registrationDeviceDictionary; +} + + +- (void) updateDeviceWithBlockProgress:(nullable void (^)(NSProgress * _Nonnull uploadProgress)) uploadProgress + Success:(nullable void (^)(BOOL response))success + failure:(nullable void (^)(NSError * _Nonnull error))failure { + if (self.deviceToken && self.oldDeviceToken && (!self.updatedAt || [self.updatedAt isEarlierThanDate:[[NSDate date] dateByAddingHours:3]])) { + + [[self class] POSTWithEndpointAction:@"device/update" parameters:[self updateDeviceFormObject] + progress:uploadProgress + success:^(NSURLSessionDataTask * _Nullable task, NSDictionary * _Nullable responseObject) { + [self setUpdated]; + [self saveLocally]; + if(success){ + success(YES); + } + } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { + if (failure) { + failure(error); + } + }]; + } + else { + if (success) { + success(YES); + } + } +} + +- (NSDictionary * _Nonnull) updateDeviceFormObject { + + NSMutableDictionary *updateDeviceDictionary = [[NSMutableDictionary alloc] initWithDictionary:[self JSONFormObject]]; + + if ([updateDeviceDictionary objectForKey:VariableName(self.deviceToken)]) { + [updateDeviceDictionary setObject:[updateDeviceDictionary objectForKey:VariableName(self.deviceToken)] forKey:@"newDeviceToken"]; + + } + if ([updateDeviceDictionary objectForKey:VariableName(self.oldDeviceToken)]) { + [updateDeviceDictionary setObject:[updateDeviceDictionary objectForKey:VariableName(self.oldDeviceToken)] forKey:VariableName(self.deviceToken)]; + [updateDeviceDictionary removeObjectForKey:VariableName(self.oldDeviceToken)]; + } + + + + return updateDeviceDictionary; +} + +- (void) removeDeviceWithBlockProgress:(nullable void (^)(NSProgress * _Nonnull uploadProgress)) uploadProgress + Success:(nullable void (^)(BOOL response))success + failure:(nullable void (^)(NSError * _Nonnull error))failure { + + if (self.deviceToken) { + + [[self class] POSTWithEndpointAction:@"device/remove-user" parameters:[self removeDeviceFormObject] + progress:uploadProgress + success:^(NSURLSessionDataTask * _Nullable task, NSDictionary * _Nullable responseObject) { + NSLog(@"response %@",responseObject); + if(success){ + success(YES); + } + } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { + NSLog(@"error : %@",error); + if (failure) { + failure(error); + } + }]; + } + else{ + if (success) { + success(YES); + } + } +} + +- (NSDictionary * _Nonnull) removeDeviceFormObject { + + NSMutableDictionary *updateDeviceDictionary = [[NSMutableDictionary alloc] init]; + + [updateDeviceDictionary setObject:self.deviceToken forKey:VariableName(self.deviceToken)]; + + return updateDeviceDictionary; +} + + #pragma mark - @end