Reputation: 8493
I am making an iOS app which receives push notifications. Everything is set up correctly, and I have made it work already. The way I tested it was to manually enter the device token of my own phone in the .php file which sent the notification. I know I need to set up an SQL-database which stores all the device-tokens. I also know I have to "call" this website in the dedRegisterForRemoteNotificationWithDeviceToken in Xcode. I know how to do all this, but I am not sure how I should create the field for the actual token in the database, and how to parse it correctly.
If I remember right, when I NSLog out my device token, I get something like "< xxxx xxxx xxxx xxxx >". I think I have to parse this to be "xxxxxxxxxxxxxxxx".
I'm sure I'll figure this out.. My main question is, what TYPE should the column for token be? INT? VARCHAR? I can tell that it's a hex of some kind, but I don't know how to go about that in the database..
I'm thinking of setting up the table just with (TokenID int AUTO_INCREMENT, Token (??) UNIQUE);
I do not need users or anything.. Just the token(the TokenID is just my standard procedure..). This is a kind of "news"-notification specified for one field. Anyone knows what type my token-value should be? And maybe also how to parse it from "< x-x-x >" to "xxx"
Upvotes: 5
Views: 6581
Reputation: 1266
The correct way is to store the value as BINARY(32) and use the MySQL functions UNHEX and HEX to store and retrieve the values.
INSERT INTO devices SET devicetoke=UNHEX('$token'), ...
UPDATE devices SET badgecount=badgecount+1 WHERE devicetoken=UNHEX('$token')
SELECT HEX(devicetoken) AS token FROM devices WHERE ...
Upvotes: 4
Reputation: 8493
I found an example here: http://www.easyapns.com/mysql-tables
`devicetoken` char(64) NOT NULL,
Upvotes: 4