Push Notification 用の deviceToken をコンソールに表示するコードを書いてみた。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) { | |
let trimCharacterSet = NSCharacterSet(charactersInString: "<>"); | |
let deviceTokenString = deviceToken.description.stringByTrimmingCharactersInSet(trimCharacterSet) | |
.stringByReplacingOccurrencesOfString(" ", withString: "", options: nil, range: nil); | |
println("application:didRegisterForRemoteNotificationWithDeviceToken: " + deviceTokenString); | |
} |
NSData
型の変数 deviceToken
を文字列に変えるのに deviceToken.description
で十分だったのがびっくり。
deviceToken.description
は 「<スペース区切りのトークン>」な形式なので、stringByTrimmingChaaractersInSet
で「<>」を削り、stringByReplacingOccurencesOfString
でスペースを削ってる。
0 件のコメント:
コメントを投稿