From c2c6e9a2993041f2b75a5fcfe71b50970d55de56 Mon Sep 17 00:00:00 2001 From: Giuseppe Nucifora Date: Fri, 29 Apr 2016 17:07:45 +0200 Subject: [PATCH] no message --- Pod/Classes/PNClasses/PNInstallation.h | 14 +++++++----- Pod/Classes/PNClasses/PNInstallation.m | 31 +++++++++++++++++++++----- Pod/Classes/PNObjectConfig.h | 4 ++++ Pod/Classes/PNObjectConfig.m | 4 ++++ 4 files changed, 42 insertions(+), 11 deletions(-) diff --git a/Pod/Classes/PNClasses/PNInstallation.h b/Pod/Classes/PNClasses/PNInstallation.h index 24aa885..4fa1cb1 100644 --- a/Pod/Classes/PNClasses/PNInstallation.h +++ b/Pod/Classes/PNClasses/PNInstallation.h @@ -9,10 +9,10 @@ #import "PNObject.h" #import "PNUser.h" -typedef NS_ENUM(NSInteger, PNInstallationType) { - PNInstallationTypeNew = 0, - PNInstallationTypeChange, - PNInstallationTypeNone, +typedef NS_ENUM(NSInteger, PNInstallationStatus) { + PNInstallationStatusNew = 0, + PNInstallationStatusChange, + PNInstallationStatusNone, }; @interface PNInstallation : PNObject @@ -35,7 +35,7 @@ typedef NS_ENUM(NSInteger, PNInstallationType) { * * @return RETURN YES if token is not set o token changes, NO if token is the same of old token. */ -- (PNInstallationType) setDeviceTokenFromData:(nullable NSData *)deviceTokenData; +- (PNInstallationStatus) setDeviceTokenFromData:(nullable NSData *)deviceTokenData; /** * <#Description#> @@ -82,6 +82,10 @@ typedef NS_ENUM(NSInteger, PNInstallationType) { * <#Description#> */ @property (nonatomic, assign) NSInteger badge; +/** + * <#Description#> + */ +@property (nonatomic, readonly) PNInstallationStatus installationStatus; /** * <#Description#> */ diff --git a/Pod/Classes/PNClasses/PNInstallation.m b/Pod/Classes/PNClasses/PNInstallation.m index 3ae34aa..d048db6 100644 --- a/Pod/Classes/PNClasses/PNInstallation.m +++ b/Pod/Classes/PNClasses/PNInstallation.m @@ -76,9 +76,12 @@ static bool isFirstAccess = YES; return INSTALLATION; } -- (PNInstallationType) setDeviceTokenFromData:(NSData *)deviceTokenData { +- (PNInstallationStatus) setDeviceTokenFromData:(NSData *)deviceTokenData { - PNInstallationType response = PNInstallationTypeNone; + if(!deviceTokenData){ + _installationStatus = PNInstallationStatusNone; + return _installationStatus; + } self.deviceTokenData = deviceTokenData; @@ -89,10 +92,10 @@ static bool isFirstAccess = YES; if (!_deviceToken) { - response = PNInstallationTypeNew; + _installationStatus = PNInstallationStatusNew; } else if (_deviceToken && ![ptoken isEqualToString:_deviceToken]) { - response = PNInstallationTypeChange; + _installationStatus = PNInstallationStatusChange; } /*[self setValue:_deviceToken forKey:VariableName(oldDeviceToken)]; @@ -100,11 +103,11 @@ static bool isFirstAccess = YES; */ _oldDeviceToken = _deviceToken; _deviceToken = ptoken; - if (response != PNInstallationTypeNone) { + if (_installationStatus != PNInstallationStatusNone) { _lastTokenUpdate = [NSDate date]; } - return response; + return _installationStatus; } - (void) setBadge:(NSInteger)badge { @@ -127,6 +130,21 @@ static bool isFirstAccess = YES; _updatedAt = [NSDate date]; } +- (void) setUser:(PNUser *)user { + if (!self.user) { + self.user = user; + [[NSNotificationCenter defaultCenter] postNotificationName:PNObjectLocalNotificationPNInstallationUserNew object:nil]; + } + else if(self.user.objID != user.objID) { + self.user = user; + [[NSNotificationCenter defaultCenter] postNotificationName:PNObjectLocalNotificationPNInstallationUserChange object:nil]; + } + else if (user == nil){ + self.user = nil; + [[NSNotificationCenter defaultCenter] postNotificationName:PNObjectLocalNotificationPNInstallationUserDelete object:nil]; + } +} + #pragma mark - #pragma mark Private Methods @@ -160,6 +178,7 @@ static bool isFirstAccess = YES; [self setValue:[[UIDevice currentDevice] name] forKey:VariableName(deviceName)]; [self setValue:[[DJLocalizationSystem shared] language] forKey:VariableName(localeIdentifier)]; */ + _installationStatus = PNInstallationStatusNone; _deviceType = @"iOS"; _deviceModel = [[UIDevice currentDevice] model]; _osVersion = [[UIDevice currentDevice] systemVersion]; diff --git a/Pod/Classes/PNObjectConfig.h b/Pod/Classes/PNObjectConfig.h index 3b67bf5..a16f7a7 100644 --- a/Pod/Classes/PNObjectConfig.h +++ b/Pod/Classes/PNObjectConfig.h @@ -31,6 +31,10 @@ extern NSString* _Nonnull const PNObjectLocalNotificationUserReloadFromServerFai extern NSString* _Nonnull const PNObjectLocalNotificationUserWillLogout; extern NSString* _Nonnull const PNObjectLocalNotificationUserEndLogout; +extern NSString* _Nonnull const PNObjectLocalNotificationPNInstallationUserNew; +extern NSString* _Nonnull const PNObjectLocalNotificationPNInstallationUserChange; +extern NSString* _Nonnull const PNObjectLocalNotificationPNInstallationUserDelete; + #pragma mark - extern NSString* _Nonnull const EnvironmentProduction; diff --git a/Pod/Classes/PNObjectConfig.m b/Pod/Classes/PNObjectConfig.m index 542f09f..428e87b 100644 --- a/Pod/Classes/PNObjectConfig.m +++ b/Pod/Classes/PNObjectConfig.m @@ -30,6 +30,10 @@ NSString * const PNObjectLocalNotificationUserReloadFromServerFailure = @"PNObje NSString * const PNObjectLocalNotificationUserWillLogout = @"PNObjectLocalNotificationUserLogout"; NSString * const PNObjectLocalNotificationUserEndLogout = @"PNObjectLocalNotificationUserLogout"; +NSString * const PNObjectLocalNotificationPNInstallationUserNew = @"PNObjectLocalNotificationPNInstallationUserNew"; +NSString * const PNObjectLocalNotificationPNInstallationUserChange = @"PNObjectLocalNotificationPNInstallationUserChange"; +NSString * const PNObjectLocalNotificationPNInstallationUserDelete = @"PNObjectLocalNotificationPNInstallationUserDelete"; + NSInteger const minPassLenght = 4; NSString * const PNObjectEncryptionKey = @"PNObjectConfigEncryptionKey";