Thing の無効化/有効化
Thing オーナーは Thing を無効化できます。無効化すると Thing は「ロック」状態になり、以後スコープ内のデータ(Bucket および Object)にアクセスできなくなります。Thing が無効化されてもデータ自体は Kii Cloud に残り、Thing オーナーはデータにアクセス可能です。この機能は、たとえば Thing が盗難にあったり紛失したりした場合において、一時的に Thing の利用を停止したい場合などに有効です。
もちろん Thing オーナーは、後ほど Thing を有効化できます。有効化すると Thing は「ロック解除」状態になり、以後スコープ内のデータにアクセス可能となります。
Thing を無効化する例を以下に挙げます。
Android
-
try { // Instantiate a thing by vendor thing ID. KiiThing thing = KiiThing.loadWithVendorThingID("rBnvSPOXBDF9r29GJeGS"); // Disable the thing if it is enabled. if (!thing.disabled()) { thing.disable(); } } catch (AppException e) { // Handle the error. } catch (IOException e) { // Handle the error. }
-
// Instantiate a thing by vendor thing ID. KiiThing.loadWithVendorThingID("rBnvSPOXBDF9r29GJeGS", new KiiCallback<KiiThing>() { @Override public void onComplete(KiiThing result, Exception e) { if (e != null) { // Handle the error. return; } // Disable the thing if it is enabled. if (!result.disabled()) { result.disable(new KiiCallback<KiiThing>() { @Override public void onComplete(KiiThing result, Exception e) { if (e != null) { // Handle the error. return; } } }); } } });
iOS
Swift:
-
let thing : KiiThing do{ // Instantiate a thing by vendor thing ID. thing = try KiiThing.loadSynchronous(withVendorThingID: "rBnvSPOXBDF9r29GJeGS") }catch(let error as NSError){ // Handle the error. return } // Disable the thing if it is enabled. if !thing.disabled { do{ try thing.disableSynchronous() } catch let error as NSError { // Handle the error. return } }
-
// Instantiate a thing by vendor thing ID. KiiThing.load(withVendorThingID: "rBnvSPOXBDF9r29GJeGS") { (thing , error) -> Void in if error != nil { // Handle the error. return } // Disable the thing if it is enabled. if !thing!.disabled { thing!.disable({ (thing , error) -> Void in if error != nil { // Handle the error. return } }) } }
Objective-C:
-
NSError* error = nil; // Instantiate a thing by vendor thing ID. KiiThing* thing = [KiiThing loadSynchronousWithVendorThingID:@"rBnvSPOXBDF9r29GJeGS" error:&error]; if (error != nil) { // Handle the error. return; } // Disable the thing if it is enabled. if (!thing.disabled) { [thing disableSynchronous:&error]; if (error != nil) { // Handle the error. return; } }
-
// Instantiate a thing by vendor thing ID. [KiiThing loadWithVendorThingID:@"rBnvSPOXBDF9r29GJeGS" block:^(KiiThing *thing, NSError *error) { if (error != nil) { // Handle the error. return; } // Disable the thing if it is enabled. if (!thing.disabled) { [thing disable:^(KiiThing *thing, NSError *error) { if (error != nil) { // Handle the error. return; } }]; } }];
JavaScript
// Instantiate a thing by vendor thing ID.
KiiThing.loadWithVendorThingID("rBnvSPOXBDF9r29GJeGS", {
success: function(thing) {
// Disable the thing if it is enabled.
if(!thing.getDisabled()) {
thing.disable({
success: function(theThing) {
// Do something.
},
failure: function(theThing, error) {
// Handle the error.
}
});
}
},
failure: function(error) {
// Handle the error.
}
});
Thing を有効化する例を以下に挙げます。
Android
-
try { // Instantiate a thing by vendor thing ID. KiiThing thing = KiiThing.loadWithVendorThingID("rBnvSPOXBDF9r29GJeGS"); // Enable the thing if it is disabled. if (thing.disabled()) { thing.enable(); } } catch (AppException e) { // Handle the error. } catch (IOException e) { // Handle the error. }
-
// Instantiate a thing by vendor thing ID. KiiThing.loadWithVendorThingID("rBnvSPOXBDF9r29GJeGS", new KiiCallback<KiiThing>() { @Override public void onComplete(KiiThing result, Exception e) { if (e != null) { // Handle the error. return; } // Enable the thing if it is disabled. if (result.disabled()) { result.enable(new KiiCallback<KiiThing>() { @Override public void onComplete(KiiThing result, Exception e) { if (e != null) { // Handle the error. return; } } }); } } });
iOS
Swift:
-
let thing : KiiThing do{ // Instantiate a thing by vendor thing ID. thing = try KiiThing.loadSynchronous(withVendorThingID: "rBnvSPOXBDF9r29GJeGS") }catch(let error as NSError){ // Handle the error. return } // Enable the thing if it is disabled. if thing.disabled { do{ try thing.enableSynchronous() } catch let error as NSError { // Handle the error. return } }
-
// Instantiate a thing by vendor thing ID. KiiThing.load(withVendorThingID: "rBnvSPOXBDF9r29GJeGS") { (thing , error) -> Void in if error != nil { // Handle the error. return } // Enable the thing if it is disabled. if thing!.disabled { thing!.enable({ (thing , error) -> Void in if error != nil { // Handle the error. return } }) } }
Objective-C:
-
NSError* error = nil; // Instantiate a thing by vendor thing ID. KiiThing* thing = [KiiThing loadSynchronousWithVendorThingID:@"rBnvSPOXBDF9r29GJeGS" error:&error]; // Enable the thing if it is disabled. if (thing.disabled) { [thing enableSynchronous:&error]; if (error != nil) { // Handle the error. return; } }
-
// Instantiate a thing by vendor thing ID. [KiiThing loadWithVendorThingID:@"rBnvSPOXBDF9r29GJeGS" block:^(KiiThing *thing, NSError *error) { if (error != nil) { // Handle the error. return; } // Enable the thing if it is disabled. if (thing.disabled) { [thing enable:^(KiiThing *thing, NSError *error) { if (error != nil) { // Handle the error. return; } }]; } }];
JavaScript
// Instantiate a thing by vendor thing ID.
KiiThing.loadWithVendorThingID("rBnvSPOXBDF9r29GJeGS", {
success: function(thing) {
// Enable the thing if it is disabled.
if(thing.getDisabled()) {
thing.enable({
success: function(theThing) {
// Do something.
},
failure: function(theThing, error) {
// Handle the error.
}
});
}
},
failure: function(error) {
// Handle the error.
}
});