Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aa4cd23

Browse files
author
Adam Eberbach
committed
Remove dependence on UIKit; fix use of deprecated UUID attribute
1 parent 6a97b09 commit aa4cd23

File tree

2 files changed

+8
-48
lines changed

2 files changed

+8
-48
lines changed

iPhone Apps/rfduino/RFduinoManagerDelegate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,6 @@
3939
- (void)didConnectRFduino:(RFduino *)rfduino;
4040
- (void)didLoadServiceRFduino:(RFduino *)rfduino;
4141
- (void)didDisconnectRFduino:(RFduino *)rfduino;
42+
- (void)shouldDisplayAlertTitled:(NSString *)title messageBody:(NSString *)body;
4243

4344
@end

iPhone Apps/rfduino/RfduinoManager.m

Lines changed: 7 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,7 @@ - (bool)isBluetoothLESupported
9898

9999
}
100100

101-
#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
102-
103-
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Bluetooth LE Support"
104-
message:message
105-
delegate:nil
106-
cancelButtonTitle:@"OK"
107-
otherButtonTitles:nil];
108-
[alert show];
109-
110-
#endif
101+
[delegate shouldDisplayAlertTitled:@"Bluetooth LE Support" messageBody:message];
111102

112103
return NO;
113104
}
@@ -193,16 +184,7 @@ - (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPe
193184
if (error.code) {
194185
cancelBlock = block;
195186

196-
#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
197-
198-
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Peripheral Disconnected with Error"
199-
message:error.description
200-
delegate:self
201-
cancelButtonTitle:@"OK"
202-
otherButtonTitles:nil];
203-
[alert show];
204-
205-
#endif
187+
[delegate shouldDisplayAlertTitled:@"Peripheral Disconnected with Error" messageBody:error.description];
206188

207189
}
208190
else
@@ -229,9 +211,9 @@ - (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeri
229211
// NSLog(@"didDiscoverPeripheral");
230212

231213
NSString *uuid = NULL;
232-
if (peripheral.UUID) {
214+
if ([peripheral.identifier.UUIDString length] > 0) {
233215
// only returned if you have connected to the device before
234-
uuid = (__bridge_transfer NSString *)CFUUIDCreateString(NULL, peripheral.UUID);
216+
uuid = peripheral.identifier.UUIDString;
235217
} else {
236218
uuid = @"";
237219
}
@@ -259,7 +241,7 @@ - (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeri
259241
id manufacturerData = [advertisementData objectForKey:CBAdvertisementDataManufacturerDataKey];
260242
if (manufacturerData) {
261243
const uint8_t *bytes = [manufacturerData bytes];
262-
int len = [manufacturerData length];
244+
NSUInteger len = [manufacturerData length];
263245
// skip manufacturer uuid
264246
NSData *data = [NSData dataWithBytes:bytes+2 length:len-2];
265247
rfduino.advertisementData = data;
@@ -283,17 +265,7 @@ - (void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(C
283265
{
284266
NSLog(@"didFailToConnectPeripheral");
285267

286-
#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
287-
288-
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Connect Failed"
289-
message:error.description
290-
delegate:nil
291-
cancelButtonTitle:@"OK"
292-
otherButtonTitles:nil];
293-
[alert show];
294-
295-
#endif
296-
268+
[delegate shouldDisplayAlertTitled:@"Connect Failed" messageBody:error.description];
297269
}
298270

299271
- (void)centralManager:(CBCentralManager *)central didRetrieveConnectedPeripherals:(NSArray *)peripherals
@@ -302,27 +274,14 @@ - (void)centralManager:(CBCentralManager *)central didRetrieveConnectedPeriphera
302274

303275
- (void)centralManagerDidUpdateState:(CBCentralManager *)aCentral
304276
{
305-
NSLog(@"central manager state = %d", [central state]);
277+
NSLog(@"central manager state = %ld", [central state]);
306278

307279
bool success = [self isBluetoothLESupported];
308280
if (success) {
309281
[self startScan];
310282
}
311283
}
312284

313-
#pragma mark - UIAlertViewDelegate methods
314-
315-
#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
316-
317-
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger) buttonIndex
318-
{
319-
if (buttonIndex == 0) {
320-
cancelBlock();
321-
}
322-
}
323-
324-
#endif
325-
326285
#pragma mark - Rfduino methods
327286

328287
- (bool)isScanning

0 commit comments

Comments
 (0)