Skip to content

Instantly share code, notes, and snippets.

@ncmbadmin
Last active September 14, 2016 07:12
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ncmbadmin/7eb7f2b63557bb255d82 to your computer and use it in GitHub Desktop.
Save ncmbadmin/7eb7f2b63557bb255d82 to your computer and use it in GitHub Desktop.

Github:

   https://github.com/ncmbadmin/iot_ncmb/archive/master.zip 

初期化

    var applicationKey = "APPLICATION_KEY";
    var clientKey = "CLIENT_KEY";
    var ncmb = new NCMB(applicationKey, clientKey);

ドアのステータスを表示する

STEP 1.1

        var Status = ncmb.DataStore("DoorData");

STEP 1.2

        Status.order("createDate", true)
            .fetch()
            .then(function(result){
               //STEP 1.2.1 検索結果を処理し、表示
            })
            .catch(function(err){
                console.log(err);
            });    

STEP 1.2.1

                    if(result.status == 1) {
                        $("#statusImg").attr("src", "image/closed.png" );
                    } else {
                        $("#statusImg").attr("src", "image/open.png" );
                    }

タイムラインを表示する

STEP 2.1

        var Status = ncmb.DataStore("DoorData"); 

STEP 2.2

        Status.order("createDate", true)
            .limit(30)
            .fetchAll()
            .then(function(results){
               //STEP 2.2.1 検索結果を処理し、表示
            })
            .catch(function(err){
                console.log(err);
            });

STEP 2.2.1

                for (var i = 0; i < results.length; i++) {
                    var object = results[i];
                    var item = {};
                    item.type = "smallItem";
                    item.label = displayDateTime(convertDate(object.createDate)); 
                    if (object.status == 1) {
                        item.shortContent = "閉 CLOSED";
                    } else {
                        item.shortContent = "開 OPENED";
                    }
                    item.forcePosition = 'right';
                    items[i] = item;
                }
                $('#timeline-container').timelineMe({"items": items});

プッシュ通知を追加する

STEP 3

document.addEventListener("deviceready", function(){
            // デバイストークンを取得してinstallationに登録する
            window.NCMB.monaca.setDeviceToken(
                applicationKey,
                clientKey,
                "SENDER_ID(Android_only)"
            );
        },false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment