I am trying to move my DeviceToken to my database this is what I have tried:
I have the code inside my AppDelegate:
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSString *token = [[deviceToken description] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"<>"]];
token = [token stringByReplacingOccurrencesOfString:@" " withString:@""];
NSLog(@"content---%@", token);
NSURL * url = [NSURL URLWithString:@"http://example.co.uk/push/push.php"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:token forKey:@"token"];
}
and for www.example.co.uk/push/push.php I have the php:
<?php
$con=mysqli_connect("localhost","xxx","yyy","zzzz");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="INSERT INTO active_users (device_token) VALUES ('$_POST[token]')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
mysqli_close($con);
?>
I am receiving no errors. But nothing is appearing in my database.
I made a form to post to the php and it works fine. So there is nothing wrong with the php.
The ASIFormDataRequest
is properly imported as there are no errors.
But I am still receiving nothing to my database? - Literally nothing not just an empty cell. Which means that the php is not even being "requested"?
Does anyone know why this might be?
Try adding at the end of your code:
[request startSynchronous];
You are creating the request but you aren't sending it. If you need to get the response, do
NSError *error = [request error];
if (!error) {
NSString *response = [request responseString];
}