简体   繁体   English

我应该如何在sql数据库上存储iOS设备令牌?

[英]How should I store iOS Device Tokens on sql database?

I am making an iOS app which receives push notifications. 我正在制作一个接收推送通知的iOS应用程序。 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. 我测试它的方法是在发送通知的.php文件中手动输入我自己手机的设备令牌。 I know I need to set up an SQL-database which stores all the device-tokens. 我知道我需要建立一个存储所有设备令牌的SQL数据库。 I also know I have to "call" this website in the dedRegisterForRemoteNotificationWithDeviceToken in Xcode. 我也知道我必须在Xcode中的dedRegisterForRemoteNotificationWithDeviceToken中“调用”这个网站。 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 >". 如果我没记错的话,当我NSLog出我的设备令牌时,我会得到类似“<xxxx xxxx xxxx xxxx>”的内容。 I think I have to parse this to be "xxxxxxxxxxxxxxxx". 我想我必须将其解析为“xxxxxxxxxxxxxxxx”。

I'm sure I'll figure this out.. My main question is, what TYPE should the column for token be? 我相信我会弄清楚这一点。我的主要问题是,令牌的列应该是什么类型? INT? INT? VARCHAR? 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); 我正在考虑设置表(TokenID int AUTO_INCREMENT,Token(??)UNIQUE);

I do not need users or anything.. Just the token(the TokenID is just my standard procedure..). 我不需要用户或任何东西..只是令牌(TokenID只是我的标准程序..)。 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 "< xxx >" to "xxx" 也许还有如何解析它从“<xxx>”到“xxx”

我在这里找到了一个例子: http//www.easyapns.com/mysql-tables

 `devicetoken` char(64) NOT NULL,

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. 正确的方法是将值存储为BINARY(32)并使用MySQL函数UNHEX和HEX来存储和检索值。

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 ...

BINARY(32) NOT NULL UNIQUE怎么样?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM