Manage Owners

Checking Owners

To check if a certain user is an owner of a thing, use the isOwner method.

The following sample code is checking if the currently logged-in user is the thing owner.

Android

  • try {
      // Instantiate a thing by vendor thing ID.
      KiiThing thing = KiiThing.loadWithVendorThingID("rBnvSPOXBDF9r29GJeGS");
    
      // Check if the current user is an owner of the thing.
      if (thing.isOwner(KiiUser.getCurrentUser())) {
        // The current user is an owner of the thing.
      }
    } 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;
        }
    
        // Check if the current user is an owner of the thing.
        result.isOwner(KiiUser.getCurrentUser(), new KiiCallback<Boolean>() {
          @Override
          public void onComplete(Boolean isOwner, Exception e) {
            if (e != null) {
              // Handle the error.
              return;
            }
    
            if (isOwner) {
              // The current user is an owner of the thing.
            }
          }
        });
      }
    });

iOS

Swift:

  • // Instantiate a thing by vendor thing ID.
    guard let thing = try? KiiThing.loadSynchronous(withVendorThingID: "rBnvSPOXBDF9r29GJeGS") else{
      // Handle the error.
      return
    }
    
    do{
      // Check if the current user is an owner of the thing.
      try thing.checkIsOwnerSynchronous(KiiUser.current()!)
      // The current user is an owner of the thing.
    }catch(let error as NSError){
      if error.kiiHttpStatus() == 404 {
        // The current user is not an owner of the thing.
      }else{
        // 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
      }
    
      // Check if the current user is an owner of the thing.
      thing!.checkIsOwner(KiiUser.current()!, block: { (thing : KiiThing, owner : KiiThingOwner, isOwner : Bool, error) -> Void in
        if error != nil {
          // Handle the error.
          return
        }
    
        if isOwner {
          // The current user is an owner of the thing.
        }
      })
    }

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;
    }
    
    // Check if the current user is an owner of the thing.
    BOOL isOwner = [thing checkIsOwnerSynchronous:[KiiUser currentUser]
                                            error:&error];
    if (error != nil) {
      if(error.kiiHttpStatus == 404){
        // The current user is not an owner of the thing.
      }else{
        // Handle the error.
        return;
      }
    }
    
    if (isOwner) {
        // The current user is an owner of the thing.
    }
  • // Instantiate a thing by vendor thing ID.
    [KiiThing loadWithVendorThingID:@"rBnvSPOXBDF9r29GJeGS"
                     block:^(KiiThing *thing, NSError *error) {
      if (error != nil) {
        // Handle the error.
        return;
      }
    
      // Check if the current user is an owner of the thing.
      [thing checkIsOwner:[KiiUser currentUser]
                    block:^(KiiThing *thing, id<KiiThingOwner> thingOwner, BOOL isOwner, NSError *error) {
        if (error != nil) {
          if(error.kiiHttpStatus == 404){
            // The current user is not an owner of the thing.
          }else{
            // Handle the error.
            return;
          }
        }
    
        if (isOwner) {
          // The current user is an owner of the thing.
        }
      }];
    }];

JavaScript

// Instantiate a thing by vendor thing ID.
KiiThing.loadWithVendorThingID("rBnvSPOXBDF9r29GJeGS", {
  success: function(thing) {
    // Check if the current user is an owner of the thing.
    thing.isOwner(KiiUser.getCurrentUser(), {
      success: function(theThing, isOwner) {
        if(isOwner) {
          // The current user is an owner of the thing.
        }else {
          // The current user is not an owner of the thing.
        }
      },
      failure: function(theThing, error) {
        // Handle the error.
      }
    });
  },
  failure: function(error) {
    // Handle the error.
  }
});

You can also check if a certain group is an owner of a thing. The next sample code is checking if a group, in which the currently logged-in user belongs, is the thing owner.

Android

  • try {
      // Instantiate a thing by vendor thing ID.
      KiiThing thing = KiiThing.loadWithVendorThingID("rBnvSPOXBDF9r29GJeGS");
    
      // Get a list of groups that the current user is a member of.
      List<KiiGroup> groups = KiiUser.getCurrentUser().memberOfGroups();
    
      for (KiiGroup group : groups) {
        // Check if the group is an owner of the thing.
        if (thing.isOwner(group)) {
          // The group is an owner of the thing.
        }
      }
    } 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(final KiiThing result, Exception e) {
        if (e != null) {
          // Handle the error.
          return;
        }
    
        // Get a list of groups that the current user is a member of.
        KiiUser.getCurrentUser().memberOfGroups(new KiiUserCallBack() {
          @Override
          public void onMemberOfGroupsCompleted(int token, KiiUser user, List<KiiGroup> groupList, Exception exception) {
            if (exception != null) {
              // Handle the error.
              return;
            }
    
            for (KiiGroup group : groupList) {
              // Check if the group is an owner of the thing.
              result.isOwner(group, new KiiCallback<Boolean>() {
                @Override
                public void onComplete(Boolean isOwner, Exception e) {
                  if (e != null) {
                    // Handle the error.
                    return;
                  }
                  if (isOwner) {
                    // The group is an owner of the thing.
                  }
                }
              });
            }
          }
        });
      }
    });

iOS

Swift:

  • // Instantiate a thing by vendor thing ID.
    guard let thing = try? KiiThing.loadSynchronous(withThingID: "rBnvSPOXBDF9r29GJeGS") else{
      // Handle the error.
      return
    }
    
    // Get a list of groups that the current user is a member of.
    guard let results = try? KiiUser.current()!.memberOfGroupsSynchronous() else{
      // Handle the error.
      return
    }
    
    do{
      for group in results as! [KiiGroup]{
        // Check if the group is an owner of the thing.
        try thing.checkIsOwnerSynchronous(group)
      }
      // The group is an owner of the thing.
    }catch(let error as NSError){
      if error.kiiHttpStatus() == 404 {
        // The group is not an owner of the thing.
      }else{
        // 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
      }
    
      // Get a list of groups that the current user is a member of.
      KiiUser.current()!.memberOfGroups({ (user :KiiUser?, results : [Any]?, error : Error?) -> Void in
        if error != nil {
          // Handle the error.
          return
        }
    
        for group in results as! [KiiGroup]{
          // Check if the group is an owner of the thing.
          thing!.checkIsOwner(group, block: { (thing : KiiThing, owner : KiiThingOwner, isOwner : Bool, error) -> Void in
            if error != nil {
              // Handle the error.
              return
            }
    
            if isOwner {
              // The group is an owner of the thing.
            }
          })
        }
      })
    }

Objective-C:

  • NSError* error = nil;
    
    // Instantiate a thing by vendor thing ID.
    KiiThing* thing = [KiiThing loadSynchronousWithVendorThingID:@"rBnvSPOXBDF9r29GJeGS" andError:&error];
    
    // Get a list of groups that the current user is a member of.
    NSArray* groups = [[KiiUser currentUser] memberOfGroupsSynchronous:&error];
    if (error != nil) {
      // Handle the error.
      return;
    }
    
    [groups enumerateObjectsUsingBlock:^(KiiGroup* group, NSUInteger idx, BOOL *stop) {
        NSError* localError= nil;
    
        // Check if the group is an owner of the thing.
        BOOL isOwner = [thing checkIsOwnerSynchronous:group
                                                error:&localError];
        if (localError != nil) {
          if(error.kiiHttpStatus == 404){
            // The group is not an owner of the thing.
          }else{
            // Handle the error.
            return;
          }
        }
    
        if (isOwner) {
          // The group is an owner of the thing.
        }
    }];
  • // Instantiate a thing by vendor thing ID.
    [KiiThing loadWithVendorThingID:@"rBnvSPOXBDF9r29GJeGS"
                              block:^(KiiThing *thing, NSError *error) {
      if (error != nil) {
        // Handle the error.
        return;
      }
    
      // Get a list of groups that the current user is a member of.
      [[KiiUser currentUser] memberOfGroupsWithBlock:^(KiiUser *user, NSArray *results, NSError *error) {
        if (error != nil) {
          // Handle the error.
          return;
        }
    
        [results enumerateObjectsUsingBlock:^(KiiGroup* group, NSUInteger idx, BOOL *stop) {
          // Check if the group is an owner of the thing.
          [thing checkIsOwner:group
                        block:^(KiiThing *thing, id<KiiThingOwner> thingOwner, BOOL isOwner, NSError *error) {
            if (error != nil) {
              if(error.kiiHttpStatus == 404){
                // The group is not an owner of the thing.
              }else{
                // Handle the error.
                return;
              }
            }
    
            if (isOwner) {
              // The group is an owner of the thing.
            }
          }];
        }];
      }];
    }];

JavaScript

var user = KiiUser.getCurrentUser();

// Instantiate a thing by vendor thing ID.
KiiThing.loadWithVendorThingID("rBnvSPOXBDF9r29GJeGS", {
  success: function(thing) {
    // Get a list of groups that the current user is a member of.
    user.memberOfGroups({
      success: function(theUser, groupList) {
        for(var i = 0; i < groupList.length; i++) {
          var group = groupList[i];

          // Check if the group is an owner of the thing.
          thing.isOwner(group, {
            success: function(theThing, isOwner) {
              if(isOwner) {
                // The group is an owner of the thing.
              }else {
                // The group is not an owner of the thing.
              }
            },
            failure: function(theThing, error) {
              // Handle the error.
            }
          });
        }
      },
      failure: function(theUser, error) {
        // Handle the error.
      }
    });
  },
  failure: function(error) {
    // Handle the error.
  }
});

Registering Owners

To register a certain user as a thing owner, use the registerOwner method. You need to specify the thing's password when registering a new owner.

The following sample code is adding the currently logged-in user as the thing owner.

Android

  • try {
      // Instantiate a thing by thing ID.
      KiiThing thing = KiiThing.thingWithID("th.1234-5678-abcd-efgh");
    
      // Register the current user as an owner of the thing.
      thing.registerOwner(KiiUser.getCurrentUser(), "ThingPassword");
    } catch (AppException e) {
      // Handle the error.
    } catch (IOException e) {
      // Handle the error.
    }
  • // Instantiate a thing by thing ID.
    KiiThing thing = KiiThing.thingWithID("th.1234-5678-abcd-efgh");
    
    // Register the current user as an owner of the thing.
    thing.registerOwner(KiiUser.getCurrentUser(), "ThingPassword", new KiiCallback<KiiThingOwner>() {
      @Override
      public void onComplete(KiiThingOwner result, Exception e) {
        if (e != null) {
          // Handle the error.
          return;
        }
      }
    });

iOS

Swift:

  • // Instantiate a thing by thing ID.
    let thing = KiiThing(id: "th.1234-5678-abcd-efgh")
    
    do{
      // Register the current user as an owner of the thing.
      try thing.registerOwnerSynchronous(KiiUser.current()!, thingPassword:"thingPassword")
    } catch let error as NSError {
      // Handle the error.
      return
    }
  • // Instantiate a thing by thing ID.
    let thing = KiiThing(id: "th.1234-5678-abcd-efgh")
    
    // Register the current user as an owner of the thing.
    thing.register(KiiUser.current()!, thingPassword:"thingPassword", block: { (thing , error) -> Void in
      if error != nil {
        // Handle the error.
        return
      }
    })

Objective-C:

  • // Instantiate a thing by thing ID.
    // Add an exception handling step if a thing ID is passed with an NSString variable.
    KiiThing* thing = [KiiThing thingWithID:@"th.1234-5678-abcd-efgh"];
    
    NSError* error = nil;
    
    // Register the current user as an owner of the thing.
    [thing registerOwnerSynchronous:[KiiUser currentUser]
                      thingPassword:@"thingPassword"
                              error:&error];
    if (error != nil) {
      // Handle the error.
      return;
    }
  • // Instantiate a thing by thing ID.
    // Add an exception handling step if a thing ID is passed with an NSString variable.e
    KiiThing* thing = [KiiThing thingWithID:@"th.1234-5678-abcd-efgh"];
    
    // Register the current user as an owner of the thing.
    [thing registerOwner:[KiiUser currentUser]
           thingPassword:@"thingPassword"
                   block:^(KiiThing *thing, NSError *error) {
      if (error != nil) {
        // Handle the error.
        return;
      }
    }];

JavaScript

// Instantiate a thing by thing ID.
var thing = KiiThing.thingWithID("th.1234-5678-abcd-efgh");

// Register the current user as an owner of the thing.
thing.registerOwnerWithPassword(KiiUser.getCurrentUser(), "ThingPassword", {
  success: function(theThing) {
    // Do something.
  },
  failure: function(theThing, error) {
    // Handle the error.
  }
});

You can also add an owner with the vendorThingID.

Android

  • try {
      // Register the current user as an owner of the thing.
      KiiThing.registerOwnerWithVenderThingID("rBnvSPOXBDF9r29GJeGS", KiiUser.getCurrentUser(), "ThingPassword");
    
      // Load the thing from Kii Cloud.
      KiiThing thing = KiiThing.loadWithVendorThingID("rBnvSPOXBDF9r29GJeGS");
    } catch (AppException e) {
      // Handle the error.
    } catch (IOException e) {
      // Handle the error.
    }
  • // Register the current user as an owner of the thing.
    KiiThing.registerOwnerWithVenderThingID("rBnvSPOXBDF9r29GJeGS", KiiUser.getCurrentUser(), "ThingPassword", new KiiCallback<KiiThingOwner>() {
      @Override
      public void onComplete(KiiThingOwner result, Exception e) {
        if (e != null) {
          // Handle the error.
          return;
        }
    
        // Load the thing from Kii Cloud.
        KiiThing.loadWithVendorThingID("rBnvSPOXBDF9r29GJeGS", new KiiCallback<KiiThing>() {
          @Override
          public void onComplete(KiiThing result, Exception e) {
            if (e != null) {
              // Handle the error.
              return;
            }
        });
      }
    });

iOS

Swift:

  • let thing : KiiThing
    
    do{
      // Register the current user as an owner of the thing.
      try KiiThing.registerOwnerSynchronous(KiiUser.current()!, vendorThingID: "rBnvSPOXBDF9r29GJeGS", thingPassword:"thingPassword")
    
      // Load the thing from Kii Cloud.
      thing = try KiiThing.loadSynchronous(withVendorThingID: "rBnvSPOXBDF9r29GJeGS")
    }catch(let error as NSError){
      // Handle the error.
      return
    }
  • let vendorThingID = "rBnvSPOXBDF9r29GJeGS"
    
    // Register the current user as an owner of the thing.
    KiiThing.register(KiiUser.current()!, vendorThingID: vendorThingID, thingPassword:"thingPassword") { (owner : KiiThingOwner, error : Error?) -> Void in
      if error != nil {
        // Handle the error.
        return
      }
    
      // Load the thing from Kii Cloud.
      KiiThing.load(withVendorThingID: vendorThingID, block: { (thing , error) -> Void in
        if error != nil {
          // Handle the error.
          return
        }
      })
    }

Objective-C:

  • NSError* error = nil;
    
    // Register the current user as an owner of the thing.
    [KiiThing registerOwnerSynchronous:[KiiUser currentUser]
                         vendorThingID:@"rBnvSPOXBDF9r29GJeGS"
                         thingPassword:@"thingPassword"
                                 error:&error];
    if (error != nil) {
      // Handle the error.
      return;
    }
    
    // Load the thing from Kii Cloud.
    KiiThing* thing =
        [KiiThing loadSynchronousWithVendorThingID:@"rBnvSPOXBDF9r29GJeGS"
                                             error:&error];
    if (error != nil) {
      // Handle the error.
      return;
    }
  • // Register the current user as an owner of the thing.
    [KiiThing registerOwner:[KiiUser currentUser]
              vendorThingID:@"rBnvSPOXBDF9r29GJeGS"
              thingPassword:@"thingPassword"
                      block:^(id<KiiThingOwner> owner, NSError* error) {
        if (error != nil) {
          // Handle the error.
          return;
        }
    
        // Load the thing from Kii Cloud.
        [KiiThing loadWithVendorThingID:@"rBnvSPOXBDF9r29GJeGS"
                                  block:^(KiiThing* thing, NSError* error) {
          if (error != nil) {
            // Handle the error.
            return;
          }
        }
      }
    ];

JavaScript

// Register the current user as an owner of the thing.
KiiThing.registerOwnerWithVendorThingIDAndPassowrd("rBnvSPOXBDF9r29GJeGS", KiiUser.getCurrentUser(), "ThingPassword", {
  success: function(theOwner) {
    // Load the thing from Kii Cloud.
    KiiThing.loadWithVendorThingID("rBnvSPOXBDF9r29GJeGS", {
      success: function(theThing) {
        // Do something.
      },
      failure: function(error) {
        // Handle the error.
      }
    });
  },
  failure: function(error) {
    // Handle the error.
  }
});

You can also register a certain group as a thing owner. The next sample code is adding a group, in which the currently logged-in user belongs, as the thing owner.

Android

  • try {
      // Instantiate a thing by vendor thing ID.
      KiiThing thing = KiiThing.loadWithVendorThingID("rBnvSPOXBDF9r29GJeGS");
    
      // Create a group and add the current user to it.
      KiiGroup group = KiiGroup.createWithName("ThingUsers");
      group.addUser(KiiUser.getCurrentUser());
    
      // Save the group.
      group.save();
    
      // Register the group as an owner of the thing.
      thing.registerOwner(group, "ThingPassword");
    } catch (GroupOperationException e) {
      // Handle the error.
    } 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(final KiiThing result, Exception e) {
        if (e != null) {
          // Handle the error.
          return;
        }
    
        // Create a group and add the current user to it.
        KiiGroup group = KiiGroup.createWithName("ThingUsers");
        group.addUser(KiiUser.getCurrentUser());
    
        // Save the group.
        group.save(new KiiGroupCallBack() {
          @Override
          public void onSaveCompleted(int token, KiiGroup group, Exception e) {
            if (e != null) {
              // Handle the error.
              return;
            }
    
            // Register the group as an owner of the thing.
            result.registerOwner(KiiUser.getCurrentUser(), "ThingPassword", new KiiCallback<KiiThingOwner>() {
              @Override
              public void onComplete(KiiThingOwner 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
    }
    
    // Create a group and add the current user to it.
    let group = KiiGroup(name: "owners", andMembers: [KiiUser.current()!])
    
    do{
      // Save the group.
      try group.saveSynchronous()
    
      // Register the group as an owner of the thing.
      try thing.registerOwnerSynchronous(group, thingPassword:"thingPassword")
    } catch let error as NSError {
      // Handle the error.
      return
    }
  • let vendorThingID = "rBnvSPOXBDF9r29GJeGS"
    
    // Instantiate a thing by vendor thing ID.
    KiiThing.load(withVendorThingID: vendorThingID, block: { (thing , error) -> Void in
      if error != nil {
        // Handle the error.
        return
      }
    
      // Create a group and add the current user to it.
      let group = KiiGroup(name: "owners", andMembers: [KiiUser.current()!])
    
      // Save the group.
      group.save({ (group : KiiGroup?, error : Error?) -> Void in
        if error != nil {
          // Handle the error.
          return
        }
    
        // Register the group as an owner of the thing.
        thing!.register(group!, thingPassword:"thingPassword", block: { (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;
    }
    
    // Create a group and add the current user to it.
    KiiGroup* group= [Kii groupWithName:@"owners" andMembers:@[[KiiUser currentUser]]];
    
    // Save the group.
    [group saveSynchronous:&error];
    if (error != nil) {
      // Handle the error.
      return;
    }
    
    // Register the group as an owner of the thing.
    [thing registerOwnerSynchronous:group
                      thingPassword:@"thingPassword"
                              error:&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;
      }
    
      // Create a group and add the current user to it.
      KiiGroup* group= [Kii groupWithName:@"owners" andMembers:@[[KiiUser currentUser]]];
    
      // Save the group.
      [group saveWithBlock:^(KiiGroup *group, NSError *error) {
        if (error != nil) {
          // Handle the error.
          return;
        }
    
        // Register the group as an owner of the thing.
        [thing registerOwner:group
               thingPassword:@"thingPassword"
                       block:^(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) {
    // Create a group and add the current user to it.
    var group = KiiGroup.groupWithName("myGroup");
    group.addUser(KiiUser.getCurrentUser());

    // Save the group.
    group.save({
      success: function(theGroup) {

        // Register the group as an owner of the thing.
        thing.registerOwnerWithPassword(group, "ThingPassword", {
          success: function(theThing) {
            // Do something.
          },
          failure: function(theThing, error) {
            // Handle the error.
          }
        });
      },
      failure: function(theGroup, error) {
        // Handle the error.
      }
    });
  },
  failure: function(error) {
    // Handle the error.
  }
});

Unregistering Owners

To unregister a certain user from a thing owner, use the unregisterOwner method.

The following sample code is removing the currently logged-in user from the thing owner.

Android

  • try {
      // Instantiate a thing by vendor thing ID.
      KiiThing thing = KiiThing.loadWithVendorThingID("rBnvSPOXBDF9r29GJeGS");
    
      // Revoke the current user's ownership of the thing.
      thing.unregisterOwner(KiiUser.getCurrentUser());
    } 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;
        }
    
        // Revoke the current user's ownership of the thing.
        result.unregisterOwner(KiiUser.getCurrentUser(), new KiiCallback<KiiThingOwner>() {
          @Override
          public void onComplete(KiiThingOwner 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")
    
      // Revoke the current user's ownership of the thing.
      try thing.unregisterOwnerSynchronous(KiiUser.current()!)
    }catch(let error as NSError){
      // Handle the error.
      return
    }
  • // Instantiate a thing by vendor thing ID.
    KiiThing.load(withVendorThingID: "rBnvSPOXBDF9r29GJeGS", block: { (thing , error) -> Void in
      if error != nil {
        // Handle the error.
        return
      }
    
      // Revoke the current user's ownership of the thing.
      thing!.unregisterOwner(KiiUser.current()!, block: { (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;
    }
    
    // Revoke the current user's ownership of the thing.
    [thing unregisterOwnerSynchronous:[KiiUser currentUser]
                                error:&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;
      }
    
      // Revoke the current user's ownership of the thing.
      [thing unregisterOwner:[KiiUser currentUser]
                       block:^(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) {
    // Revoke the current user's ownership of the thing.
    thing.unregisterOwner(KiiUser.getCurrentUser(), {
      success: function(theThing) {
        // Do something.
      },
      failure: function(theThing, error) {
        // Handle the error.
      }
    });
  },
  failure: function(error) {
    // Handle the error.
  }
});

You can also unregister a certain group from a thing owner. The next sample code is removing a group, in which the currently logged-in user belongs, from the thing owner.

Android

  • // Instantiate a group.
    Uri uri = Uri.parse("Set the URI of an existing group here");
    KiiGroup group = KiiGroup.createByUri(uri);
    
    try {
      // Instantiate a thing by vendor thing ID.
      KiiThing thing = KiiThing.loadWithVendorThingID("rBnvSPOXBDF9r29GJeGS");
    
      // Revoke the group's ownership of the thing.
      thing.unregisterOwner(group);
    } catch (AppException e) {
      // Handle the error.
    } catch (IOException e) {
      // Handle the error.
    }
  • // Instantiate a group.
    Uri uri = Uri.parse("Set the URI of an existing group here");
    final KiiGroup group = KiiGroup.createByUri(uri);
    
    // Instantiate a thing by vendor thing ID.
    KiiThing.loadWithVendorThingID("rBnvSPOXBDF9r29GJeGS", new KiiCallback<KiiThing>() {
      @Override
      public void onComplete(final KiiThing result, Exception e) {
        if (e != null) {
          // Handle the error.
          return;
        }
    
        // Revoke the group's ownership of the thing.
        result.unregisterOwner(group, new KiiCallback<KiiThingOwner>() {
          @Override
          public void onComplete(KiiThingOwner 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
    }
    
    // Instantiate a group.
    let group = KiiGroup(uri: "Set the URI of an existing group here")
    
    do{
      // Revoke the group's ownership of the thing.
      try thing.unregisterOwnerSynchronous(group)
    } catch let error as NSError {
      // Handle the error.
      return
    }
  • let vendorThingID = "rBnvSPOXBDF9r29GJeGS"
    
    // Instantiate a thing by vendor thing ID.
    KiiThing.load(withVendorThingID: vendorThingID, block: { (thing , error) -> Void in
      if error != nil {
        // Handle the error.
        return
      }
    
      // Instantiate a group.
      let group = KiiGroup(uri: "Set the URI of an existing group here")
    
      // Revoke the group's ownership of the thing.
      thing!.unregisterOwner(group!, block: { (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;
    }
    
    // Instantiate a group.
    KiiGroup* group= [KiiGroup groupWithURI:@"Set the URI of an existing group here"];
    
    // Revoke the group's ownership of the thing.
    [thing unregisterOwnerSynchronous:group
                                error:&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;
      }
    
      // Instantiate a group.
      KiiGroup* group= [KiiGroup groupWithURI:@"Set the URI of an existing group here"];
    
      // Revoke the group's ownership of the thing.
      [thing unregisterOwner:group
                       block:^(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) {
    // Instantiate a group.
    var group = KiiGroup.groupWithURI("Set the URI of an existing group here");

    // Revoke the group's ownership of the thing.
    thing.unregisterOwner(group, {
      success: function(theThing) {
        // Do something.
      },
      failure: function(theThing, error) {
        // Handle the error.
      }
    });
  },
  failure: function(error) {
    // Handle the error.
  }
});