Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-25960] Hyperloop: iOS - Property returns function instead of string

GitHub Issuen/a
TypeBug
Priorityn/a
StatusReopened
ResolutionUnresolved
Affected Version/sn/a
Fix Version/sn/a
ComponentsHyperloop
LabelsengReviewed, hyperloop, ios
ReporterAndreas Schräder
AssigneeJan Vennemann
Created2018-01-05T00:08:13.000+0000
Updated2019-06-18T15:52:50.000+0000

Description

Instead of strings, I only get functions that produce errors when processing the Hyperloop results. That said: console.log prints the correct value for the unmodified variable. I need to access the string that console.log prints.
var HMHomeManager = require('HomeKit/HMHomeManager');
var NSArray = require('Foundation/NSArray');
	
var HMHomeManagerDelegate = Hyperloop.defineClass('HMHomeManagerDelegate', 'NSObject'); 
	
HMHomeManagerDelegate.addMethod({
	selector: 'homeManagerDidUpdateHomes:',
	instance: true,
	arguments: ['HMHomeManager'],
	callback: function(sender) {
		if (this.homeManagerDidUpdateHomes) {
			this.homeManagerDidUpdateHomes(sender);
		}
	}
});

var HMHome = require('HomeKit/HMHome');		

var delegate = new HMHomeManagerDelegate();
delegate.homeManagerDidUpdateHomes = function(sender) {
	
	var name = sender.primaryHome.name;
	console.log('name: '+ name);
	console.log(JSON.stringify({"name":"name","value":name}));
};

var homeManager = new HMHomeManager();
homeManager.delegate = delegate;
Prints:
[INFO] :   name: My Home
Should print:
[INFO] :   name: My Home
[INFO] :  {"name":"name","value":"My Home"}

Attachments

FileDateSize
HomeKitAccess.zip2018-01-10T20:32:49.000+00009299327

Comments

  1. Mostafizur Rahman 2018-01-07

    Hello [~aschräder], Thanks for sharing with us. Can you please share a simple test case to reproduce this on our end. Also share your environment details. Best
  2. Andreas Schräder 2018-01-08

    Hi Mostafizur, I think the below code should be the minimal test case to reproduce the behaviour. Putting this into the index.js should produce the described behaviour:
       var HMHomeManager = require('HomeKit/HMHomeManager');
       var NSArray = require('Foundation/NSArray');
       	
       var HMHomeManagerDelegate = Hyperloop.defineClass('HMHomeManagerDelegate', 'NSObject');  // also tried: ['HomeKit/HMHomeManagerDelegate'] or ['HMHomeManagerDelegate'] instead of manually adding the 'homeManagerDidUpdateHomes:', but that did not work
       	
       HMHomeManagerDelegate.addMethod({
       	selector: 'homeManagerDidUpdateHomes:',
       	instance: true,
       	arguments: ['HMHomeManager'],
       	callback: function(sender) {
       		if (this.homeManagerDidUpdateHomes) {
       			this.homeManagerDidUpdateHomes(sender);
       		}
       	}
       });
       
       var HMHome = require('HomeKit/HMHome');		
       
       var delegate = new HMHomeManagerDelegate();
       delegate.homeManagerDidUpdateHomes = function(sender) {
       	var homes = [
       		{name: sender.primaryHome.name, uuid: sender.primaryHome.uniqueIdentifier}
       	];
       	var name = homes[0].name;
       	console.log('name: '+ name);
       	console.log('name: '+name.toString);
       	console.log('name: '+JSON.stringify(
       		{"name":"name","value":name}
       	));
       };
       
       var homeManager = new HMHomeManager();
       homeManager.delegate = delegate;
       
    With regards to environment details: MacOS, iOS, HomeKit, Appcelerator Studio 5.0.0. (all the latest versions). The hyperloop module is activated. As build properties I have selected the Titanium SDK 6.3.0.GA. in the tiapp.xml I have configured the necessary properties and entitlements:
           <ios>
               <entitlements>
                   <dict>
                       <key>com.apple.developer.homekit</key>
                       <true/>
                       <key>com.apple.external-accessory.wireless-configuration</key>
                       <true/>
                   </dict>
               </entitlements>
                    <property name="run-on-main-thread" type="bool">true</property>
                   <use-jscore-framework>true</use-jscore-framework>
                   <dict>
                       <key>NSHomeKitUsageDescription</key>
                       <string>Switch needs access to your HomeKit devices.</string>
                   </dict>
               </plist>
          </ios>
       
    Hope this helps reproducing the behaviour. In case anything is missing, please let me know.
  3. Sharif AbuDarda 2018-01-08

    Hello, Please create a sample Alloy project with the reproducible code and attach the file in here. Thanks.
  4. Hans Knöchel 2018-01-09

    This is not a Hyperloop issue, please read the native documentation more carefully. I see this kind of issues popping up more and more. Some background for your issue: - The issue is in uuid, not name - uniqueIdentifier returns a UUID instance, not String as documented [here](https://developer.apple.com/documentation/homekit/hmhome/1620243-uniqueidentifier) - Access it as a String by using uniqueIdentifier.uuidString as documented [here](https://developer.apple.com/documentation/foundation/uuid/1779712-uuidstring) - toString is no property but a function (e.g. toString()). It is no native method but a JavaScript method that only works with proper JavaScript types like Number and Array as documented [here](https://www.w3schools.com/jsref/jsref_tostring_number.asp)
  5. Andreas Schräder 2018-01-10

    Please reopen the issue as this has nothing to do with the uniqueIdentifier or the use of toString(). I have cleaned the case description in order to avoid distraction - albeit at the cost that the error message disappears and the problem only occurs 'silently'. sender.primaryHome.name is a string and does not behave as a string would. @Hans Knöchel: while your explanations around the UUID are what I would expect based on the documentation, the evidence is that console.log with uniqueIdentifier.uuidString prints 'undefined' whereas console.log with uniqueIdentifier prints the actual value.
  6. Andreas Schräder 2018-01-10

    @Sharif AbuDarda: I have attached a sample project 'HomeKitAccess' as you suggested.
  7. Hans Knöchel 2018-01-10

    [~aschräder] The Obj-C usage (which Hyperloop is generated from) is UUIDString, not uuidString which is [documented](https://developer.apple.com/documentation/foundation/nsuuid/1416585-uuidstring?language=objc) as well. And the reason why sender.primaryHome.name prints correctly is likely because it prints the description as the native world does as well. If Hyperloop really unwraps this correctly, you should still be able to receive it via sender.primaryHome.name.description.
  8. Andreas Schräder 2018-01-11

    @Hans Knöchel Thanks for the prompt response. I had copied the
     uuidString 
    from your prior post, but the result with
    UUIDString 
    is exactly the same. I've tested the your hypothesis with regards to the description. It turns out that Hyperloop apparently does not unwrap this as expected. With
    sender.primaryHome.name.description 
    it prints:
       [INFO] :   name: undefined
       [INFO] :   {"name":"name"}
       
    Interestingly, this is the same as result that I get with
    UUIDString 
    . I could understand why the description of the
    name 
    property prints
    name 
    , but why would
    sender.primaryHome.uniqueIdentifier.UUIDString 
    print
    name 
    ? I take advantage and address another problem I encounter, which may be related: I seem to be unable to access an array (an
    NSArray 
    ) with Hyperloop. If I define name as any of the three below properties:
       sender.homes[0].name
       sender.homes.objectAtIndex(0).name
       sender.homes.count
       
    it prints nothing at all. I hope it's just me coding it incorrectly. Otherwise it would be hard to implement a HomeKit app without improvements in Hyperloop...
  9. Andreas Schräder 2018-01-24

    @Shak Hossain: Can you please re-open this issue? This is neither invalid nor resolved! Thanks!
  10. Mostafizur Rahman 2018-04-09

    Hello [~aschräder], Can you test the issue on latest SDK and let us know how it goes.
  11. Andreas Schräder 2018-04-10

    I have just tested it with 7.1.0 - and the result is unchanged. The problem continues to exist and needs to be fixed. Andreas
  12. Hans Knöchel 2018-04-12

    Hey there! We will further investigate this and I have moved it to TIMOB. We will let you know once it's scheduled.

JSON Source