Some BLE Devices Return nil RSSI on iOS ( crashing )

Issue #2 closed
Jason Peterson created an issue

I am in the process of an update to the Asset Store, however if you need a fix now you can add these changes to the "UnityBleBridge.mm" file in "Assets->Plugins->iOS".

Around line 620, change this line:

[self unityBleSendUpdateWithPeripheralId:peripheralId withKey:@"OnRssiUpdate" andValue:[RSSI stringValue]];

to this:

if(RSSI != nil)
{
      [self unityBleSendUpdateWithPeripheralId:peripheralId withKey:@"OnRssiUpdate" andValue:[RSSI stringValue]];
}

Around line 130 change these lines:

NSString *rssi = [[peripheral RSSI] stringValue];
NSString *message = [NSString stringWithFormat:@"%d:%@%d:%@", (int)strlen([identifier UTF8String]), identifier, (int)strlen([rssi UTF8String]), rssi];
UnitySendMessage ([[self gameObjName] UTF8String], "OnRssiUpdate", [message UTF8String]);

to this:

if([peripheral RSSI] != nil)
{
    NSString *rssi = [[peripheral RSSI] stringValue];
    NSString *message = [NSString stringWithFormat:@"%d:%@%d:%@", (int)strlen([identifier UTF8String]), identifier, (int)strlen([rssi UTF8String]), rssi];
    UnitySendMessage ([[self gameObjName] UTF8String], "OnRssiUpdate", [message UTF8String]);
}

Around line 465, change these lines:

NSNumber *RSSI = [peripheral RSSI];
NSString *message = [NSString stringWithFormat:@"%d:%@%d:%@", (int)strlen([(NSString*)peripheralId UTF8String]), peripheralId, (int)strlen([[RSSI stringValue] UTF8String]), [RSSI stringValue]];
UnitySendMessage ([[self gameObjName] UTF8String], "OnRssiUpdate", [message UTF8String]);

to this:

if([peripheral RSSI] != nil)
{
     NSNumber *RSSI = [peripheral RSSI];
     NSString *message = [NSString stringWithFormat:@"%d:%@%d:%@", (int)strlen([(NSString*)peripheralId UTF8String]), peripheralId, (int)strlen([[RSSI stringValue] UTF8String]), [RSSI stringValue]];
     UnitySendMessage ([[self gameObjName] UTF8String], "OnRssiUpdate", [message UTF8String]);
}

Comments (2)

  1. Log in to comment