Just thought that I would add my two cents here, as that is me too. If you understand that the device token must have spaces, then to prevent this problem from happening again, replace this section of code:
// Validate input. if(self.deviceToken == nil || self.payload == nil) { return; }
with this:
// Validate input. if(self.deviceToken == nil || self.payload == nil) { return; } else if(![self.deviceToken rangeOfString:@" "].length) { //put in spaces in device token NSMutableString* tempString = [NSMutableString stringWithString:self.deviceToken]; int offset = 0; for(int i = 0; i < tempString.length; i++) { if(i%8 == 0 && i != 0 && i+offset < tempString.length-1) { //NSLog(@"i = %d + offset[%d] = %d", i, offset, i+offset); [tempString insertString:@" " atIndex:i+offset]; offset++; } } NSLog(@" device token string after adding spaces = '%@'", tempString); self.deviceToken = tempString; }
source share