我可以为我的iPad获取设备令牌,但问题是如何通过php代码将其发送到服务器中的数据库。通过http请求发送设备令牌
我已经测试了PHP代码,它正在工作。
这是我的函数来发送设备令牌:
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
NSString *devToken = [[[[deviceToken description]
stringByReplacingOccurrencesOfString:@"<"withString:@""]
stringByReplacingOccurrencesOfString:@">" withString:@""]
stringByReplacingOccurrencesOfString: @" " withString: @""];
NSLog(@"%@",devToken);
NSString *sli = [NSString stringWithFormat:@"http://localhost:8888/insertiphone.php?number=%@",devToken];
NSURL *url = [NSURL URLWithString:sli];
NSData *test = [NSData dataWithContentsOfURL:url];
if ([test length] == 0) {
NSLog(@"no done");
}
}
它不工作..
,这是PHP代码:
<?php
function inserttodatabase(){
$con = mysql_connect("localhost","root","root");
mysql_select_db("my_db", $con);
mysql_query("INSERT INTO iphoneid (idip)
VALUES ($_GET[number])");
echo "done";
}
inserttodatabase();
?>
更新,我也试图与这些代码不起作用
NSString *devToken = [[[[deviceToken description]
stringByReplacingOccurrencesOfString:@"<"withString:@""]
stringByReplacingOccurrencesOfString:@">" withString:@""]
stringByReplacingOccurrencesOfString: @" " withString: @""];
NSString *sli = [NSString stringWithFormat:@"http://localhost:8888/insertiphone.php? number=%@",devToken];
NSLog(@"%@",sli);
NSURL *url = [NSURL URLWithString:sli];
NSURLRequest *urlr = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0];
NSURLConnection* connection = [[NSURLConnection alloc] initWithRequest:urlr delegate:self];
if (connection){
NSLog(@"connecting");
}else {
NSLog(@"error");
}
它说的连接,但没有将被插入到数据库
我不知道如何使用这些类!任何示例请 – 2012-07-10 00:03:18
给我一分钟... – bryanmac 2012-07-10 00:09:49
添加链接使用这些以及链接到使用charles代理来检查电线。希望那些帮助缩小你的问题... – bryanmac 2012-07-10 00:15:18