Reputation: 1134
I am implementing Push notifications for my app at the moment. As you know, every user has to register via a certain regID which is stored on the server. I hav been following this tutorial. ( I have used mainly it's code for the server setup aswell)
The problem is, in this tutorial, the regID is stored in a simple txt file and can be only sent to one user (whose id is stored at that time). Now I want to save ALL registered ID's and when pressing the button (as seen in the tutorial).
I want to send the notification to ALL users AT ONCE. Is that possible? If yes how? (I already started some researching, I have to create a mySQL database and the php file needs somehow to access that database, right?)
EDIT:
class DB_Functions {
private $db;
//put your code here
// constructor
function __construct() {
include_once './db_connect.php';
// connecting to database
$this->db = new DB_Connect();
$this->db->connect();
}
// destructor
function __destruct() {
}
/**
* Storing new user
* returns user details
*/
public function storeUser($gcm_regid) {
// insert user into database
$result = mysql_query("INSERT INTO gcm_users(gcm_regid) VALUES('$gcm_regid', NOW())");
// check for successful store
if ($result) {
// get user details
$id = mysql_insert_id(); // last inserted id
$result = mysql_query("SELECT * FROM gcm_users WHERE id = $id") or die(mysql_error());
// return user details
if (mysql_num_rows($result) > 0) {
return mysql_fetch_array($result);
} else {
return false;
}
} else {
return false;
}
}
/**
* Getting all users
*/
public function getAllUsers() {
$result = mysql_query("select * FROM gcm_users");
return $result;
}
}
?>
Upvotes: 0
Views: 107
Reputation: 11
You can read data from file and store in collection and from collection you can retrieve regID and pass this to your push notification method.
Upvotes: 1
Reputation: 6828
Yes you need to insert users' regID
in your mysql
database. For notifying all users, select
all the users using a query and send the notifications to all of them.
This tutorial can help you.
Upvotes: 1