9
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

iOS13&Xcode11で通知が受け取れなくなった話

Last updated at Posted at 2019-10-03

環境

  • iPhone8
  • iOS13.1.2
  • Xcode11.1 GM

原因

  • Objective-cの下記のコードで渡るdeviceTokenの中身が変わっていた
SampleAppDelegate.m
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    // iOS12:<00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000>
    // iOS13:{length = 32, bytes = 0x00000000 00000000 00000000 00000000 ... 00000000 00000000 }
    NSString *token = deviceToken.description;
}

対応

SampleAppDelegate.m
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    NSString *token = [self hexadecimalStringFromData:deviceToken];
}

-(NSString *)hexadecimalStringFromData:(NSData *)data {
    NSUInteger dataLength = data.length;
    if (dataLength == 0) {
        return nil;
    }

    const unsigned char *dataBuffer = data.bytes;
    NSMutableString *hexString  = [NSMutableString stringWithCapacity:(dataLength * 2)];
    for (int i = 0; i < dataLength; ++i) {
        [hexString appendFormat:@"%02x", dataBuffer[i]];
    }
    return [hexString copy];
}
9
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?