APNS token compared with NSString
I got two APNS (Apple Push) tokens to compare.
One is from Apple. Every time I launch the app it receives the token (as a NSData *) from Apple.
The other is from my app's SQLite3 database. When the first time my app received the token from Apple, it recorded the token in its SQLite3 database with an INSERT with the token as TEXT.
I then tried to compare these two tokens. Yes they are meant to be the same, and every time I use NSLog to output them on Console, they did look the same.
But every time I use isEqual: or isEqualToString: to compare, I got NO. I'm confused.
Any one ca开发者_运维问答n help?
I had the same problem and found an easy solution. To convert the token (NSData *) into a string (NSString *), simply use description:
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)token {
NSStrinng *strToken = [token description];
...
}
精彩评论