Checking if a Topic Exists
You can check if a certain topic already exists from your mobile application.
The following example checks if the specified topic already exist in an application scope (you can similarly check the topic existence in a user and group scopes).
-
// Instantiate the target topic. var topic = Kii.topicWithName("SendingAlert"); // Check if the topic exists. topic.exists().then( function(existed) { if (existed) { // The topic already exists. } else { // The topic does not exist. } } ).catch( function(error) { // Handle the error. var theTopic = error.target; var errorString = error.message; } );
-
// Instantiate the target topic. var topic = Kii.topicWithName("SendingAlert"); // Check if the topic exists. topic.exists({ success: function(existed) { if (existed) { // The topic already exists. } else { // The topic does not exist. } }, failure: function(errorString) { // Handle the error. } });
This is the brief explanation of the sample code:
- Get an instance of the topic that you want to check if it exists.
- Execute the
exists
method to check if the topic exists or not.