如何使用目标C发送设备令牌推送通知和其他用户设置为sql服务器表 [英] How to use Objective C to send device token for push notifications and other user settings to sql table on server
问题描述
在理想情况下,我想送使用POST包含该设备令牌以及一些用户定义的设置推送通知服务器的HTTP请求。从那里我可以建立一个PHP脚本在服务器上处理输入数据和输入它变成一个SQL表。如果这是这样做的唯一途径,我将如何去从目标C发起和HTTP请求?
Ideally, I would like to send an HTTP Request using POST to the Push Notification Server that contains the device token as well as some user-defined settings. From there I can set up a php script on the server to deal with the incoming data and input it into an sql table. If this is the only way to do it, how would I go about initiating and HTTP Request from Objective C?
推荐答案
您首先需要设备令牌转换为十六进制字符串,这样的功能:
You'll first need to convert the device token to a hex string with a function like this:
- (NSString*)stringWithDeviceToken:(NSData*)deviceToken {
const char* data = [deviceToken bytes];
NSMutableString* token = [NSMutableString string];
for (int i = 0; i < [deviceToken length]; i++) {
[token appendFormat:@"%02.2hhX", data[i]];
}
return [[token copy] autorelease];
}
然后,你需要做的请求到服务器:
Then you'll need to make a request to your server:
NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"http://example.com/script.php?token=%@", DEVICE_TOKEN]];
NSMutableURLRequest* request = [[[NSMutableRequest alloc] initWithURL:url] autorelease];
NSURLConnection* connection = [NSURLConnection connectionWithRequest:request delegate: self];
这篇关于如何使用目标C发送设备令牌推送通知和其他用户设置为sql服务器表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!