no message

This commit is contained in:
Giuseppe Nucifora 2016-04-29 17:07:45 +02:00
parent 33672c87eb
commit c2c6e9a299
4 changed files with 42 additions and 11 deletions

View File

@ -9,10 +9,10 @@
#import "PNObject.h" #import "PNObject.h"
#import "PNUser.h" #import "PNUser.h"
typedef NS_ENUM(NSInteger, PNInstallationType) { typedef NS_ENUM(NSInteger, PNInstallationStatus) {
PNInstallationTypeNew = 0, PNInstallationStatusNew = 0,
PNInstallationTypeChange, PNInstallationStatusChange,
PNInstallationTypeNone, PNInstallationStatusNone,
}; };
@interface PNInstallation : PNObject @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. * @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#> * <#Description#>
@ -82,6 +82,10 @@ typedef NS_ENUM(NSInteger, PNInstallationType) {
* <#Description#> * <#Description#>
*/ */
@property (nonatomic, assign) NSInteger badge; @property (nonatomic, assign) NSInteger badge;
/**
* <#Description#>
*/
@property (nonatomic, readonly) PNInstallationStatus installationStatus;
/** /**
* <#Description#> * <#Description#>
*/ */

View File

@ -76,9 +76,12 @@ static bool isFirstAccess = YES;
return INSTALLATION; return INSTALLATION;
} }
- (PNInstallationType) setDeviceTokenFromData:(NSData *)deviceTokenData { - (PNInstallationStatus) setDeviceTokenFromData:(NSData *)deviceTokenData {
PNInstallationType response = PNInstallationTypeNone; if(!deviceTokenData){
_installationStatus = PNInstallationStatusNone;
return _installationStatus;
}
self.deviceTokenData = deviceTokenData; self.deviceTokenData = deviceTokenData;
@ -89,10 +92,10 @@ static bool isFirstAccess = YES;
if (!_deviceToken) { if (!_deviceToken) {
response = PNInstallationTypeNew; _installationStatus = PNInstallationStatusNew;
} }
else if (_deviceToken && ![ptoken isEqualToString:_deviceToken]) { else if (_deviceToken && ![ptoken isEqualToString:_deviceToken]) {
response = PNInstallationTypeChange; _installationStatus = PNInstallationStatusChange;
} }
/*[self setValue:_deviceToken forKey:VariableName(oldDeviceToken)]; /*[self setValue:_deviceToken forKey:VariableName(oldDeviceToken)];
@ -100,11 +103,11 @@ static bool isFirstAccess = YES;
*/ */
_oldDeviceToken = _deviceToken; _oldDeviceToken = _deviceToken;
_deviceToken = ptoken; _deviceToken = ptoken;
if (response != PNInstallationTypeNone) { if (_installationStatus != PNInstallationStatusNone) {
_lastTokenUpdate = [NSDate date]; _lastTokenUpdate = [NSDate date];
} }
return response; return _installationStatus;
} }
- (void) setBadge:(NSInteger)badge { - (void) setBadge:(NSInteger)badge {
@ -127,6 +130,21 @@ static bool isFirstAccess = YES;
_updatedAt = [NSDate date]; _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 -
#pragma mark Private Methods #pragma mark Private Methods
@ -160,6 +178,7 @@ static bool isFirstAccess = YES;
[self setValue:[[UIDevice currentDevice] name] forKey:VariableName(deviceName)]; [self setValue:[[UIDevice currentDevice] name] forKey:VariableName(deviceName)];
[self setValue:[[DJLocalizationSystem shared] language] forKey:VariableName(localeIdentifier)]; [self setValue:[[DJLocalizationSystem shared] language] forKey:VariableName(localeIdentifier)];
*/ */
_installationStatus = PNInstallationStatusNone;
_deviceType = @"iOS"; _deviceType = @"iOS";
_deviceModel = [[UIDevice currentDevice] model]; _deviceModel = [[UIDevice currentDevice] model];
_osVersion = [[UIDevice currentDevice] systemVersion]; _osVersion = [[UIDevice currentDevice] systemVersion];

View File

@ -31,6 +31,10 @@ extern NSString* _Nonnull const PNObjectLocalNotificationUserReloadFromServerFai
extern NSString* _Nonnull const PNObjectLocalNotificationUserWillLogout; extern NSString* _Nonnull const PNObjectLocalNotificationUserWillLogout;
extern NSString* _Nonnull const PNObjectLocalNotificationUserEndLogout; extern NSString* _Nonnull const PNObjectLocalNotificationUserEndLogout;
extern NSString* _Nonnull const PNObjectLocalNotificationPNInstallationUserNew;
extern NSString* _Nonnull const PNObjectLocalNotificationPNInstallationUserChange;
extern NSString* _Nonnull const PNObjectLocalNotificationPNInstallationUserDelete;
#pragma mark - #pragma mark -
extern NSString* _Nonnull const EnvironmentProduction; extern NSString* _Nonnull const EnvironmentProduction;

View File

@ -30,6 +30,10 @@ NSString * const PNObjectLocalNotificationUserReloadFromServerFailure = @"PNObje
NSString * const PNObjectLocalNotificationUserWillLogout = @"PNObjectLocalNotificationUserLogout"; NSString * const PNObjectLocalNotificationUserWillLogout = @"PNObjectLocalNotificationUserLogout";
NSString * const PNObjectLocalNotificationUserEndLogout = @"PNObjectLocalNotificationUserLogout"; NSString * const PNObjectLocalNotificationUserEndLogout = @"PNObjectLocalNotificationUserLogout";
NSString * const PNObjectLocalNotificationPNInstallationUserNew = @"PNObjectLocalNotificationPNInstallationUserNew";
NSString * const PNObjectLocalNotificationPNInstallationUserChange = @"PNObjectLocalNotificationPNInstallationUserChange";
NSString * const PNObjectLocalNotificationPNInstallationUserDelete = @"PNObjectLocalNotificationPNInstallationUserDelete";
NSInteger const minPassLenght = 4; NSInteger const minPassLenght = 4;
NSString * const PNObjectEncryptionKey = @"PNObjectConfigEncryptionKey"; NSString * const PNObjectEncryptionKey = @"PNObjectConfigEncryptionKey";