iPadのデバイストークンを取得できますが、phpコードを介してサーバーのデータベースに送信する方法に問題があります。
私は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");
}
接続していると表示されますが、データベースには何も挿入されません