トピックの有無の確認
モバイルアプリのプログラムから、特定のトピックが存在するかどうかを確認することができます。
以下に、アプリケーションスコープにトピックが存在するかどうかを確認する例を挙げます(グループスコープのトピックとユーザースコープのトピックについても、基本的な操作は同様です)。
-
// 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. } });
ここでは次の処理を行っています。
- 存在を確認したいトピックのインスタンスを取得。
exists
メソッドを実行し、トピックの存在有無を確認。