Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-24291] Hyperloop: iOS - Unable to specify Hyperloop argument type for NSDictionary

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2017-05-03T20:02:21.000+0000
Affected Version/sn/a
Fix Version/sHyperloop 2.1.1
ComponentsHyperloop, iOS
Labelsn/a
ReporterKevin Southworth
AssigneeJan Vennemann
Created2017-01-10T18:44:36.000+0000
Updated2018-08-06T17:49:35.000+0000

Description

I'm trying to define a custom hyperloop class to use as a callback delegate for CoreBluetooth on iOS. However, I'm not able to specify the argument type properly for NSDictionary<NSString *,id> I'm trying to define my delegate class to match https://developer.apple.com/reference/corebluetooth/cbcentralmanagerdelegate/1518937-centralmanager?language=objc
var Delegate = Hyperloop.defineClass('CentralManagerDelegate', 'NSObject',["CBCentralManagerDelegate"]);

Delegate.addMethod({
  selector: "centralManager:didDiscoverPeripheral:advertisementData:RSSI:",  
  arguments: ["CBCentralManager","CBPeripheral","NSDictionary<NSString *,id>","NSNumber"],
  callback: function(central, peripheral, advertisementData, rssi) {
    if(this.didDiscoverPeripheral) {
      this.didDiscoverPeripheral(central, peripheral, advertisementData, rssi);
    }
  }
});
But the NSDictionary<NSString *,id> string in the arguments array is generating a compile-time error:
unknown encoding [CBCentralManager][CBPeripheral][NSDictionary<NSString *,id>][NSNumber] start at index 32
If I change it to just NSDictionary it compiles, but then I don't have the correct data type inside my callback / delegate function

Comments

  1. Hans Knöchel 2017-01-10

    Hey [~ksouthworth], interesting issue! I agree we should support type specifications (not only in NSDictionary but also in other types like NSArray). Moving to TIMOB to be investigated!
  2. Jan Vennemann 2017-03-31

    [~ksouthworth], omitting the generic part for the argument in your method definition shouldn't have an impact on the data you receive because the encoding stays the same. What exactly do you receive inside your callback and what's different than expected? I do not have a BLE device for testing at my disposal so i created a minimal [example Gist](https://gist.github.com/janvennemann/22c756b929dcaee3fefb716700de546e) and i can access the content of the NSDictionary just fine. However, i totally agree that you should be able to specify the parameter as NSDictionary<NSString *,id> without Hyperloop throwing the unknown encoding error.
  3. Jan Vennemann 2017-05-03

    PR (master): https://github.com/appcelerator/hyperloop.next/pull/166 PR (2_1_X): https://github.com/appcelerator/hyperloop.next/pull/167 [~hansknoechel], tested it with Gist from my previous comment. The reporter being unable to properly access the data from the NSDictionary argument was probably related to TIMOB-24383.
  4. Eric Merriman 2018-08-06

    Cleaning up older fixed issues. If this issue should not have been closed as fixed, please reopen.

JSON Source