Skip to content

Commit

Permalink
refactor: fix all deprecations and warnings, build with latest SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
hansemannn committed Jun 2, 2020
1 parent b0e1954 commit 81bf17d
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 56 deletions.
9 changes: 5 additions & 4 deletions ios/Classes/TiBluetoothCentralManagerProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import "TiBluetoothPeripheralProvider.h"
#import "TiBluetoothUtils.h"
#import "TiUtils.h"
#import "TiBlob.h"

#import "TiBluetoothCharacteristicProxy.h"
#import "TiBluetoothPeripheralProxy.h"
Expand Down Expand Up @@ -181,7 +182,7 @@ - (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeri
withObject:@{
@"peripheral" : [self peripheralProxyFromPeripheral:peripheral],
@"advertisementData" : [self dictionaryFromAdvertisementData:advertisementData],
@"rssi" : NUMINT(RSSI)
@"rssi" : RSSI
}];
}
}
Expand All @@ -191,7 +192,7 @@ - (void)centralManager:(CBCentralManager *)central willRestoreState:(NSDictionar
if ([self _hasListeners:@"willRestoreState"]) {
[self fireEvent:@"willRestoreState"
withObject:@{
@"state" : NUMINT(central.state)
@"state" : @(central.state)
}];
}
}
Expand All @@ -212,7 +213,7 @@ - (void)centralManagerDidUpdateState:(CBCentralManager *)central
if ([self _hasListeners:@"didUpdateState"]) {
[self fireEvent:@"didUpdateState"
withObject:@{
@"state" : NUMINT(central.state)
@"state" : @(central.state)
}];
}
}
Expand Down Expand Up @@ -255,7 +256,7 @@ - (NSDictionary *)dictionaryFromAdvertisementData:(NSDictionary *)advertisementD
// Write own handler
for (id key in advertisementData) {
if ([[advertisementData objectForKey:key] isKindOfClass:[NSData class]]) {
[dict setObject:[[TiBlob alloc] _initWithPageContext:[self pageContext] andData:[advertisementData objectForKey:key] mimetype:@"text/plain"] forKey:key];
[dict setObject:[[TiBlob alloc] initWithData:[advertisementData objectForKey:key] mimetype:@"text/plain"] forKey:key];
} else if ([[advertisementData objectForKey:key] isKindOfClass:[NSNumber class]]) {
[dict setObject:NUMBOOL([advertisementData objectForKey:key]) forKey:key];
} else if ([[advertisementData objectForKey:key] isKindOfClass:[NSString class]]) {
Expand Down
2 changes: 1 addition & 1 deletion ios/Classes/TiBluetoothCharacteristicProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ - (NSArray *)descriptors

- (TiBlob *)value
{
return [[TiBlob alloc] _initWithPageContext:[self pageContext] andData:characteristic.value mimetype:@"text/plain"];
return [[TiBlob alloc] initWithData:characteristic.value mimetype:@"text/plain"];
}

- (NSString *)uuid
Expand Down
4 changes: 0 additions & 4 deletions ios/Classes/TiBluetoothL2CAPChannelProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* Please see the LICENSE included with this distribution for details.
*/

#if IS_XCODE_9

#import "TiProxy.h"
#import <CoreBluetooth/CoreBluetooth.h>

Expand All @@ -21,5 +19,3 @@
- (NSNumber *)PSM;

@end

#endif
4 changes: 0 additions & 4 deletions ios/Classes/TiBluetoothL2CAPChannelProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* Please see the LICENSE included with this distribution for details.
*/

#if IS_XCODE_9

#import "TiBluetoothL2CAPChannelProxy.h"

@implementation TiBluetoothL2CAPChannelProxy
Expand Down Expand Up @@ -36,5 +34,3 @@ - (NSNumber *)PSM
// and then process the data-stream to be wrapped into a Ti.Blob

@end

#endif
9 changes: 3 additions & 6 deletions ios/Classes/TiBluetoothPeripheralManagerProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
#import "TiBluetoothServiceProxy.h"
#import "TiBluetoothUtils.h"
#import "TiUtils.h"
#if IS_XCODE_9
#import "TiBlob.h"
#import "TiBluetoothL2CAPChannelProxy.h"
#endif

@implementation TiBluetoothPeripheralManagerProxy

Expand Down Expand Up @@ -169,7 +168,6 @@ - (NSNumber *)updateValueForCharacteristicOnSubscribedCentrals:(id)args

#pragma mark Delegates

#if IS_XCODE_9
- (void)peripheralManager:(CBPeripheralManager *)peripheral didPublishL2CAPChannel:(CBL2CAPPSM)PSM error:(NSError *)error
{
if ([self _hasListeners:@"didPublishL2CAPChannel"]) {
Expand Down Expand Up @@ -199,14 +197,13 @@ - (void)peripheralManager:(CBPeripheralManager *)peripheral didOpenL2CAPChannel:
}];
}
}
#endif

- (void)peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheral
{
if ([self _hasListeners:@"didUpdateState"]) {
[self fireEvent:@"didUpdateState"
withObject:@{
@"state" : NUMINT(peripheral.state)
@"state" : @(peripheral.state)
}];
}
}
Expand All @@ -216,7 +213,7 @@ - (void)peripheralManager:(CBPeripheralManager *)peripheral willRestoreState:(NS
if ([self _hasListeners:@"willRestoreState"]) {
[self fireEvent:@"willRestoreState"
withObject:@{
@"state" : NUMINT(peripheral.state)
@"state" : @(peripheral.state)
}];
}
}
Expand Down
25 changes: 16 additions & 9 deletions ios/Classes/TiBluetoothPeripheralProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
#import "TiBluetoothServiceProxy.h"
#import "TiBluetoothUtils.h"
#import "TiUtils.h"
#if IS_XCODE_9
#import "TiBlob.h"
#import "TiBluetoothL2CAPChannelProxy.h"
#endif

@implementation TiBluetoothPeripheralProxy

Expand Down Expand Up @@ -43,12 +42,13 @@ - (NSString *)name

- (NSNumber *)rssi
{
return NUMINT(_peripheral.RSSI);
DEPRECATED_REMOVED(@"Bluetooth.Peripheral.rssi (use \"didReadRSSI\" event instead)", @"2.0.0", @"2.0.0");
return @(-1);
}

- (NSNumber *)state
{
return NUMINT(_peripheral.state);
return @(_peripheral.state);
}

- (NSArray *)services
Expand Down Expand Up @@ -144,7 +144,6 @@ - (void)writeValueForCharacteristicWithType:(id)args
type:[TiUtils intValue:type]];
}

#if IS_XCODE_9
- (NSNumber *)canSendWriteWithoutResponse
{
return NUMBOOL([_peripheral canSendWriteWithoutResponse]);
Expand All @@ -153,9 +152,8 @@ - (NSNumber *)canSendWriteWithoutResponse
- (void)openL2CAPChannel:(id)args
{
ENSURE_SINGLE_ARG(args, NSDictionary);
[_peripheral openL2CAPChannel:nil];
[_peripheral openL2CAPChannel:0];
}
#endif

- (void)setNotifyValueForCharacteristic:(id)args
{
Expand Down Expand Up @@ -201,7 +199,6 @@ - (void)writeValueForDescriptor:(id)args

#pragma mark Peripheral Delegates

#if IS_XCODE_9
- (void)peripheralIsReadyToSendWriteWithoutResponse:(CBPeripheral *)peripheral
{
if ([self _hasListeners:@"isReadyToSendWriteWithoutResponse"]) {
Expand All @@ -222,7 +219,6 @@ - (void)peripheral:(CBPeripheral *)peripheral didOpenL2CAPChannel:(CBL2CAPChanne
}];
}
}
#endif

- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error
{
Expand All @@ -235,6 +231,17 @@ - (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)err
}
}

- (void)peripheral:(CBPeripheral *)peripheral didReadRSSI:(NSNumber *)RSSI error:(NSError *)error
{
if ([self _hasListeners:@"didReadRSSI"]) {
[self fireEvent:@"didReadRSSI"
withObject:@{
@"rssi" : RSSI,
@"error" : NULL_IF_NIL([error localizedDescription])
}];
}
}

- (void)peripheral:(CBPeripheral *)peripheral didUpdateNotificationStateForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error
{
if ([self _hasListeners:@"didUpdateNotificationStateForCharacteristic"]) {
Expand Down
2 changes: 1 addition & 1 deletion ios/Classes/TiBluetoothRequestProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ - (NSNumber *)offset

- (TiBlob *)value
{
return [[TiBlob alloc] _initWithPageContext:[self pageContext] andData:request.value mimetype:@"text/plain"];
return [[TiBlob alloc] initWithData:request.value mimetype:@"text/plain"];
}

- (TiBluetoothCharacteristicProxy *)characteristicProxyFromCharacteristic:(CBCharacteristic *)characteristic
Expand Down
6 changes: 0 additions & 6 deletions ios/TiBluetooth_Prefix.pch
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,3 @@
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#endif

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000
#define IS_XCODE_9 true
#else
#define IS_XCODE_9 false
#endif
4 changes: 2 additions & 2 deletions ios/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 1.3.0
version: 2.0.0
apiversion: 2
architectures: armv7 arm64 i386 x86_64
description: ti.bluetooth
Expand All @@ -15,4 +15,4 @@ name: ti.bluetooth
moduleid: ti.bluetooth
guid: 3c1bc730-d661-401e-8184-84695ad92360
platform: iphone
minsdk: 6.0.0
minsdk: 8.0.0
Loading

0 comments on commit 81bf17d

Please sign in to comment.