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

Skip to content

Commit 0c52fd6

Browse files
committed
Merge pull request RFduino#10 from aeberbach/master
Remove dependence on UIKit; fix use of deprecated UUID attribute
2 parents bc02f9c + 08b78f0 commit 0c52fd6

File tree

3 files changed

+15
-48
lines changed

3 files changed

+15
-48
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.DS_Store

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: 13 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,9 @@ - (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+
if ([delegate respondsToSelector:@selector(shouldDisplayAlertTitled:messageBody:)]) {
102+
[delegate shouldDisplayAlertTitled:@"Bluetooth LE Support" messageBody:message];
103+
}
111104

112105
return NO;
113106
}
@@ -193,16 +186,9 @@ - (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPe
193186
if (error.code) {
194187
cancelBlock = block;
195188

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
189+
if ([delegate respondsToSelector:@selector(shouldDisplayAlertTitled:messageBody:)]) {
190+
[delegate shouldDisplayAlertTitled:@"Peripheral Disconnected with Error" messageBody:error.description];
191+
}
206192

207193
}
208194
else
@@ -229,9 +215,9 @@ - (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeri
229215
// NSLog(@"didDiscoverPeripheral");
230216

231217
NSString *uuid = NULL;
232-
if (peripheral.UUID) {
218+
if ([peripheral.identifier.UUIDString length] > 0) {
233219
// only returned if you have connected to the device before
234-
uuid = (__bridge_transfer NSString *)CFUUIDCreateString(NULL, peripheral.UUID);
220+
uuid = peripheral.identifier.UUIDString;
235221
} else {
236222
uuid = @"";
237223
}
@@ -259,7 +245,7 @@ - (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeri
259245
id manufacturerData = [advertisementData objectForKey:CBAdvertisementDataManufacturerDataKey];
260246
if (manufacturerData) {
261247
const uint8_t *bytes = [manufacturerData bytes];
262-
int len = [manufacturerData length];
248+
NSUInteger len = [manufacturerData length];
263249
// skip manufacturer uuid
264250
NSData *data = [NSData dataWithBytes:bytes+2 length:len-2];
265251
rfduino.advertisementData = data;
@@ -283,17 +269,9 @@ - (void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(C
283269
{
284270
NSLog(@"didFailToConnectPeripheral");
285271

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-
272+
if ([delegate respondsToSelector:@selector(shouldDisplayAlertTitled:messageBody:)]) {
273+
[delegate shouldDisplayAlertTitled:@"Connect Failed" messageBody:error.description];
274+
}
297275
}
298276

299277
- (void)centralManager:(CBCentralManager *)central didRetrieveConnectedPeripherals:(NSArray *)peripherals
@@ -302,27 +280,14 @@ - (void)centralManager:(CBCentralManager *)central didRetrieveConnectedPeriphera
302280

303281
- (void)centralManagerDidUpdateState:(CBCentralManager *)aCentral
304282
{
305-
NSLog(@"central manager state = %d", [central state]);
283+
NSLog(@"central manager state = %ld", [central state]);
306284

307285
bool success = [self isBluetoothLESupported];
308286
if (success) {
309287
[self startScan];
310288
}
311289
}
312290

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-
326291
#pragma mark - Rfduino methods
327292

328293
- (bool)isScanning

0 commit comments

Comments
 (0)