Skip to content

Commit 308d8f5

Browse files
committed
improved bluetooth connections
1 parent 422e2e9 commit 308d8f5

File tree

12 files changed

+120
-290
lines changed

12 files changed

+120
-290
lines changed

icon-144.png

-20.3 KB
Binary file not shown.

icon-72.png

-9.14 KB
Binary file not shown.

icon.png

-5.25 KB
Binary file not shown.

icon@2x.png

-16.5 KB
Binary file not shown.

rfduino/AppDelegate.m

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@
2525
*/
2626

2727
#import "AppDelegate.h"
28+
#import <Parse/Parse.h>
2829

2930
#import "ScanViewController.h"
3031
#import "RFduinoManager.h"
32+
#import "RFduino.h"
3133

3234
@interface AppDelegate()
3335
{
@@ -40,6 +42,9 @@ @implementation AppDelegate
4042

4143
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
4244
{
45+
[Parse setApplicationId:@"NFkmPbOSWfkrZqof8E1D2dAnv0lyZb8EnrakcbrT"
46+
clientKey:@"0V9mnHCepkmaXVvRaWnsqkocTKyJGVhdYO22npqY"];
47+
4348
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
4449

4550
rfduinoManager = RFduinoManager.sharedRFduinoManager;
@@ -60,9 +65,6 @@ - (void)applicationWillResignActive:(UIApplication *)application
6065
{
6166
NSLog(@"applicationWillResignActive");
6267

63-
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
64-
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
65-
6668
wasScanning = false;
6769

6870
if (rfduinoManager.isScanning) {
@@ -71,17 +73,39 @@ - (void)applicationWillResignActive:(UIApplication *)application
7173
}
7274
}
7375

74-
- (void)applicationDidEnterBackground:(UIApplication *)application
76+
- (void)application:(UIApplication *)application
77+
didReceiveRemoteNotification:(NSDictionary *)userInfo
78+
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler
7579
{
76-
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
77-
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
80+
NSLog(@"Received remote push notification from Parse");
81+
82+
for(RFduino *rfduino in rfduinoManager.rfduinos)
83+
{
84+
uint8_t tx[3] = { 10, 3, 99 };
85+
NSData *data = [NSData dataWithBytes:(void*)&tx length:3];
86+
[rfduino send:data];
87+
}
88+
89+
if (handler) {
90+
handler(UIBackgroundFetchResultNewData);
91+
}
7892
}
7993

80-
- (void)applicationWillEnterForeground:(UIApplication *)application
81-
{
82-
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
94+
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
95+
// Store the deviceToken in the current installation and save it to Parse.
96+
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
97+
[currentInstallation setDeviceTokenFromData:deviceToken];
98+
currentInstallation.channels = @[ @"global" ];
99+
[currentInstallation saveInBackground];
100+
}
101+
102+
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
103+
[PFPush handlePush:userInfo];
83104
}
84105

106+
- (void)applicationDidEnterBackground:(UIApplication *)application {}
107+
- (void)applicationWillEnterForeground:(UIApplication *)application {}
108+
85109
- (void)applicationDidBecomeActive:(UIApplication *)application
86110
{
87111
NSLog(@"applicationDidBecomeActive");
@@ -94,9 +118,6 @@ - (void)applicationDidBecomeActive:(UIApplication *)application
94118
}
95119
}
96120

97-
- (void)applicationWillTerminate:(UIApplication *)application
98-
{
99-
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
100-
}
121+
- (void)applicationWillTerminate:(UIApplication *)application {}
101122

102123
@end

rfduino/CustomCellBackground.h

Lines changed: 0 additions & 36 deletions
This file was deleted.

rfduino/CustomCellBackground.m

Lines changed: 0 additions & 81 deletions
This file was deleted.

rfduino/RFduino.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ extern NSString *customUUID;
6262
@property(assign, nonatomic) NSInteger outOfRange;
6363
- (void)connected;
6464
- (void)disconnect;
65+
- (bool)isConnected;
6566

6667
- (void)send:(NSData *)data;
6768

rfduino/RFduino.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ - (id)init
106106
return self;
107107
}
108108

109+
- (bool)isConnected{
110+
return service_uuid != NULL;
111+
}
112+
109113
- (void)connected
110114
{
111115
NSLog(@"rfduino connected");
@@ -163,7 +167,7 @@ - (void)peripheral:(CBPeripheral *)_peripheral didDiscoverCharacteristicsForServ
163167

164168
- (void)peripheral:(CBPeripheral *)aPeripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error
165169
{
166-
NSLog(@"didUpdateValueForCharacteristic");
170+
167171
if ([characteristic.UUID isEqual:receive_uuid]) {
168172
SEL didReceive = @selector(didReceive:);
169173
if ([delegate respondsToSelector:didReceive]) {

rfduino/RfduinoManager.m

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -173,29 +173,13 @@ - (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPerip
173173
- (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error
174174
{
175175
NSLog(@"didDisconnectPeripheral");
176-
177-
void (^block)(void) = ^{
178-
if ([delegate respondsToSelector:@selector(didDisconnectRFduino:)]) {
179-
RFduino *rfduino = [self rfduinoForPeripheral:peripheral];
180-
if (rfduino) {
181-
[delegate didDisconnectRFduino:rfduino];
182-
}
183-
}
184-
};
185-
186-
if (error.code) {
187-
cancelBlock = block;
188-
189-
if ([delegate respondsToSelector:@selector(shouldDisplayAlertTitled:messageBody:)]) {
190-
[delegate shouldDisplayAlertTitled:@"Peripheral Disconnected with Error" messageBody:error.description];
191-
}
192-
176+
RFduino *rfduino = [self rfduinoForPeripheral:peripheral];
177+
if (rfduino) {
178+
[delegate didDisconnectRFduino:rfduino];
193179
}
194-
else
195-
block();
196-
180+
197181
if (peripheral) {
198-
[peripheral setDelegate:nil];
182+
[peripheral setDelegate: nil];
199183
peripheral = nil;
200184
}
201185
}
@@ -326,8 +310,11 @@ - (void)stopScan
326310
- (void)connectRFduino:(RFduino *)rfduino
327311
{
328312
NSLog(@"connectRFduino");
329-
330-
[central connectPeripheral:[rfduino peripheral] options:nil];
313+
NSDictionary *options = nil;
314+
options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES]
315+
forKey:CBConnectPeripheralOptionNotifyOnNotificationKey];
316+
317+
[central connectPeripheral:[rfduino peripheral] options:options];
331318
}
332319

333320
- (void)disconnectRFduino:(RFduino *)rfduino

0 commit comments

Comments
 (0)