1 Reply
      Latest reply on Mar 26, 2020 11:30 AM by v.minakov
      mungbeans Level 1 Level 1 (10 points)

        With XCode 11 I am no longer able to view the full value for a push token. Here's some example code to illustrate:

         

         

          func pushRegistry(_ registry: PKPushRegistry, didUpdate credentials: PKPushCredentials, for type: PKPushType)
            {
                var method1 = NSString(format: "%@", credentials.token as CVarArg) as String
                print("method1: \(method1)")
               
                method1 = method1.replacingOccurrences(of: " ", with: "")
                method1 = method1.replacingOccurrences(of: "<", with: "")
                method1 = method1.replacingOccurrences(of: ">", with: "")
                print("method1 again: \(method1)")
               
                let method2 = String(decoding: credentials.token, as: UTF8.self)
                print("method2: \(String(describing: method2))")
               
                let method3 = credentials.token.description as String
                print("method3: \(method3)")

         

         

         

        However when the above code is run with Xcode 11, this is the output:

         

         

            method1: {length = 32, bytes = 0x5b3f44e0 6d2c5ee5 5252d3db f5bb915b ... 12844aeb 13259e7e }
            method1 again: {length=32,bytes=0x5b3f44e06d2c5ee55252d3dbf5bb915b...12844aeb13259e7e}
            method2: [?D�m,^�RR�����[� � ��>� �J� %�~
            method3: 32 bytes

         

        In previous versions of Xcode, method1 would be logged/viewable as something like this:

         

         

        44154da73234500153106883ffc1071fa59c0d24f1a1d29ea70871e5aa8dbb41

         

         

        But now its this:

         

         

            0x5b3f44e06d2c5ee55252d3dbf5bb915b...12844aeb13259e7e

         

         

        There is ... in the middle of it.

         

         

         

        How can I just log/interactively view the contents of credentials.token with Xcode 11?

         

         

        I want to copy/paste the value into a php script to manually send push message to the app for testing purposes.

        • Re: How can you view the APN push token value in Xcode 11? (Its no longer displayed fully as a string when logged)
          v.minakov Level 1 Level 1 (0 points)

          Hi, you can use the following method:return [tokenString copy];

          - (void)pushRegistry:(nonnull PKPushRegistry *)registry didUpdatePushCredentials:(nonnull PKPushCredentials *)pushCredentials forType:(nonnull PKPushType)type {
              if ([pushCredentials.token length] == 0){
                  NSLog(@"PUSH CREDENTIALS TOKEN IS NULL");
                  return;
              }
              
              NSLog(@"VOIP PUSH TOKEN OBTAINED: %@", [self stringFromVOIPTokenData:pushCredentials.token]);
          }
          
          
          - (NSString *)stringFromVOIPTokenData:(NSData *)tokenData {
              const char *data = [tokenData bytes];
              NSMutableString *tokenString = [NSMutableString string];
              for (int i = 0; i < [tokenData length]; i++) {
                  [tokenString appendFormat:@"%02.2hhx", data[i]];
              }
              
              return [tokenString copy];
          }