1 Reply Latest reply on Apr 17, 2015 10:40 AM by billrei RSS
    sureshc Newbie

    iOS SDK- Can i access all the "Things" at a time.

    By using iOS SDK and i can access only single "Thing" (properties,Services and events) info by connecting to Thing WorkX Server.

    Is it possible to access all the "Things" info at a time by using iOS SDK..??


    I did not find any "methods" in doing this by using iOS SDK.

    Please suggest some solution for this...



      • iOS SDK- Can i access all the "Things" at a time.
        billrei Creator

        You can make calls back to the server to your own thing's services or any Resource service you need to call. Results can be returned to you as InfoTables back on the iOS side. Here is a sample function that demonstrates this. It calls EntityServices.getEntityList() on the server side to see if a thing exists. Check out the example that comes with the SDK for more information.

             

            public func checkifThingExist(thingName:String)->Bool {

                logDebug("Checking if thing exists on the server.");

                

                var ds:TWXDataShapeDefinition = TWXDataShapeDefinition(name:nil);

                ds.addFieldDefinitions(

                    [

                        TWXFieldDefinition(name:"type", baseType: TW_STRING),

                        TWXFieldDefinition(name:"nameMask",baseType:TW_STRING),

                        TWXFieldDefinition(name:"tags",baseType:TW_TAGS),

                        TWXFieldDefinition(name:"maxItems",baseType:TW_NUMBER)

                    ]

                );

                

                var err:NSError?;

                var itParams:TWXInfoTable = TWXInfoTable(dataShape: ds);

                itParams.addRowWithEntries(

                    [

                        "type" : TWXStringPrimitive(string: "Thing"),

                        "nameMask" : TWXStringPrimitive(string:thingName),

                        "tags" : TWXStringPrimitive(string:"", andStringBaseType:TW_TAGS),

                        "maxItems" : TWXNumberPrimitive(number:1)

                    ],

                error:&err);

                

                var itResults:TWXInfoTable? = nil;

                err = ThingWorx.connectedThingClient().invokeServiceForEntityWithName(

                    "EntityServices",

                    entityType:TW_RESOURCE,

                    serviceName:"GetEntityList",

                    serviceParameters:itParams,

                    serviceResults:&itResults,

                    timeout:-1,

                    forceConnect:false

                );

                logDebug("Existance Check completed.")

                if ((err == nil) && (itResults?.rowCount>0)) {

                    // it's there

                    return true;

                }

                return false;

            }