@@ -73,6 +73,20 @@ - (id)init
7373 return self;
7474}
7575
76+ - (NSString *)hexadecimalStringFromData : (NSData *)data
77+ {
78+ NSUInteger dataLength = data.length ;
79+ if (dataLength == 0 ) {
80+ return nil ;
81+ }
82+ const unsigned char *dataBuffer = data.bytes ;
83+ NSMutableString *hexString = [NSMutableString stringWithCapacity: (dataLength * 2 )];
84+ for (int i = 0 ; i < dataLength; ++i) {
85+ [hexString appendFormat: @" %02.2hhx " , dataBuffer[i]];
86+ }
87+ return [hexString copy ];
88+ }
89+
7690- (void )setDeviceTokenFromData : (NSData *)deviceTokenData
7791{
7892 [self setDeviceTokenFromData: deviceTokenData
@@ -82,34 +96,16 @@ - (void)setDeviceTokenFromData:(NSData *)deviceTokenData
8296- (void )setDeviceTokenFromData : (NSData *)deviceTokenData
8397 teamId : (NSString *)teamId
8498{
85- if (!deviceTokenData || deviceTokenData. length == 0 ) {
86-
99+ NSString *newDeviceToken = [ self hexadecimalStringFromData: deviceTokenData];
100+ if (!newDeviceToken) {
87101 return ;
88102 }
89-
90- NSCharacterSet *charactersSet = [NSCharacterSet characterSetWithCharactersInString: @" <>" ];
91-
92- NSString *newDeviceToken = [deviceTokenData.description stringByTrimmingCharactersInSet: charactersSet];
93-
94- newDeviceToken = [newDeviceToken stringByReplacingOccurrencesOfString: @" " withString: @" " ];
95-
96- if (newDeviceToken.length == 0 ) {
97-
98- return ;
99- }
100-
101103 NSString *oldDeviceToken = self.deviceToken ;
102-
103104 NSString *oldTeamId = self.apnsTeamId ;
104-
105105 if (![oldDeviceToken isEqualToString: newDeviceToken] || ![teamId isEqualToString: oldTeamId]) {
106-
107106 self.deviceToken = newDeviceToken;
108-
109107 self.apnsTeamId = teamId;
110-
111108 [self ._requestManager synchronize: ^{
112-
113109 [self updateInstallationDictionary: [self ._requestManager setDict ]];
114110 }];
115111 }
0 commit comments