LoginSignup
1

More than 3 years have passed since last update.

Xcode11でのPush通知用トークン取得方法

Posted at

Objective-Cのアプリをデバッグしていて気づいたのですが、Xcode10まではPush通知用のdevice tokenをこう書いていました。が、これだとうまく動かなくて、

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{   
  NSString *tokenString = [[[[deviceToken description] 
    stringByReplacingOccurrencesOfString:@"<"withString:@""] 
    stringByReplacingOccurrencesOfString:@">" withString:@""] 
    stringByReplacingOccurrencesOfString: @" " withString: @""];

    ・・・

developer forum覗いたところ、descriptionではもうダメで

  const unsigned *tokenBytes = [deviceToken bytes];
  NSString *tokenString = [NSString stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x",
    ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]),
    ntohl(tokenBytes[3]), ntohl(tokenBytes[4]), ntohl(tokenBytes[5]),
    ntohl(tokenBytes[6]), ntohl(tokenBytes[7])];

    ・・・

こうするそうです。
もしもっといけてる方法があれば教えてください。

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
1