如果你不希望使用的服務,如城市飛艇。您可以創建一個數據庫(MySQL的可能),然後使用一個語言如PHP創建一個文件,將允許您發佈的設備令牌,然後將其寫入數據庫。
在PHP中,這看起來像
<?php
$connection = mysql_connect("localhost","username","password");
if (!$connection){
die('Error: ' . mysql_error());
}
mysql_select_db("my_database", $connection);
mysql_query("INSERT INTO tokens (token)
VALUES ('$_POST[token]')");
mysql_close($connection);
?>
在iOS端,您可以使用下面的代碼:
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSString *urlString;
NSURL *url;
NSMutableURLRequest *request;
NSString *postString;
urlString = @"http://yoururl.com/apns/registerDevice";
url = [NSURL URLWithString:urlString];
request = [NSMutableURLRequest requestWithURL:url];
postString = [NSString stringWithFormat:@"token=%@", [[NSString alloc] initWithData:deviceToken encoding:NSUTF8StringEncoding];];
[request setHTTPMethod:@"POST"];
[request setValue:[NSString stringWithFormat:@"%d", [postString length]] forHTTPHeaderField:@"Content-length"];
[request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];
(void)[[NSURLConnection alloc] initWithRequest:request delegate:self];
//Casting this to void makes the warning of unused expression go away.
}
請確保您在輸入數據之前清理輸入! – hypercrypt 2012-07-08 23:23:53