Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldorner committed Jan 23, 2014
0 parents commit 3e43449
Show file tree
Hide file tree
Showing 37 changed files with 2,252 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Xcode
.DS_Store
*/build/*
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
profile
*.moved-aside
DerivedData
.idea/
*.hmap
*.xccheckout

#CocoaPods
Pods
527 changes: 527 additions & 0 deletions BeeTee.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions BeeTee.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions BeeTee/AppDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// AppDelegate.h
// BeeTee
//
// Created by Michael Dorner on 13.10.13.
// Copyright (c) 2013 Michael Dorner. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end
46 changes: 46 additions & 0 deletions BeeTee/AppDelegate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// AppDelegate.m
// BeeTee
//
// Created by Michael Dorner on 13.10.13.
// Copyright (c) 2013 Michael Dorner. All rights reserved.
//

#import "AppDelegate.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
// 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.
// 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.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
// 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.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
// 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.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
49 changes: 49 additions & 0 deletions BeeTee/BeeTee-Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>de.michaeldorner.${PRODUCT_NAME:rfc1034identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIMainStoryboardFile</key>
<string>Main_iPhone</string>
<key>UIMainStoryboardFile~ipad</key>
<string>Main_iPad</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
16 changes: 16 additions & 0 deletions BeeTee/BeeTee-Prefix.pch
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// Prefix header
//
// The contents of this file are implicitly included at the beginning of every source file.
//

#import <Availability.h>

#ifndef __IPHONE_5_0
#warning "This project uses features only available in iOS SDK 5.0 and later."
#endif

#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#endif
29 changes: 29 additions & 0 deletions BeeTee/BluetoothScanner.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// BluetoothScanner.h
// BluetoothScanner
//
// Created by Michael Dorner on 12.10.13.
// Copyright (c) 2013 Michael Dorner. All rights reserved.
//

#import <Foundation/Foundation.h>

@class BluetoothDevice;


@protocol BluetoothScannerProtocol <NSObject>

- (void)addBluetoothDevice:(BluetoothDevice *)bluetoothDevice;
- (void)removeBluetoothDevice:(BluetoothDevice *)bluetoothDevice;

@end



@interface BluetoothScanner : NSObject

@property (assign, nonatomic, readonly) BOOL isScanning;

- (id)initWithDelegate:(id<BluetoothScannerProtocol>)delegate;

@end
131 changes: 131 additions & 0 deletions BeeTee/BluetoothScanner.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
//
// BluetoothScanner.m
// BluetoothScanner
//
// Created by Michael Dorner on 12.10.13.
// Copyright (c) 2013 Michael Dorner. All rights reserved.
//

#import "BluetoothScanner.h"
#import <BluetoothManager/BluetoothManager.h>
#import <BluetoothManager/BluetoothDevice.h>


@interface BluetoothScanner ()

@property (retain, nonatomic) BluetoothManager *bluetoothManager;
@property (assign, nonatomic, readwrite) BOOL isScanning;
@property (retain, nonatomic) NSMutableDictionary *currentDevices;
@property (retain, nonatomic) id<BluetoothScannerProtocol> delegate;

- (void)addNotification;

@end


@implementation BluetoothScanner

- (id)initWithDelegate:(id<BluetoothScannerProtocol>)delegate
{
self = [super init];
if (self) {
_isScanning = NO;
_currentDevices = [[NSMutableDictionary alloc] init];
_bluetoothManager = [BluetoothManager sharedInstance]; // necessary, do not remove this line, although it is a singleton
self.delegate = delegate;
[self addNotification];
}
return self;
}


- (void)addNotification
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(bluetoothPowerChanged:) name:@"BluetoothPowerChangedNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(bluetoothAvailabilityChanged:) name:@"BluetoothAvailabilityChangedNotification" object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(bluetoothDeviceDiscovered:) name:@"BluetoothDeviceDiscoveredNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(bluetoothDeviceRemoved:) name:@"BluetoothDeviceRemovedNotification" object:nil];


// all available notifications belonging to BluetoothManager I could figure out - not used and therefore implemented in this demo app
/*
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(bluetoothPowerChanged:) name:@"BluetoothPowerChangedNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(bluetoothConnectabilityChanged:) name:@"BluetoothConnectabilityChangedNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(bluetoothDeviceUpdated:) name:@"BluetoothDeviceUpdatedNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(bluetoothDiscoveryStateChanged:) name:@"BluetoothDiscoveryStateChangedNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(bluetoothDeviceDiscovered:) name:@"BluetoothDeviceDiscoveredNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(bluetoothDeviceConnectSuccess:) name:@"BluetoothDeviceConnectSuccessNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(bluetoothConnectionStatusChanged:) name:@"BluetoothConnectionStatusChangedNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(bluetoothDeviceDisconnectSuccess:) name:@"BluetoothDeviceDisconnectSuccessNotification" object:nil];
*/


// this helped me very much to figure out the methods mentioned the lines above
/*
// credits to http://stackoverflow.com/a/3738387/1864294 :
CFNotificationCenterAddObserver(CFNotificationCenterGetLocalCenter(),
NULL,
notificationCallback,
NULL,
NULL,
CFNotificationSuspensionBehaviorDeliverImmediately);
*/
}


void notificationCallback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo)
{
if ([(NSString*)name characterAtIndex:0] == 'B') { // notice only notification they are associated with the BluetoothManager.framework
NSLog(@"Callback detected: \n\t name: %@ \n\t object:%@", name, object);
}
}


- (void)bluetoothAvailabilityChanged:(NSNotification *)notification
{
if (![self.bluetoothManager enabled]) {
[self.bluetoothManager setEnabled:YES]; // automatically turn bluetooth on
}
else {
[self.bluetoothManager setDeviceScanningEnabled:YES];
[self.bluetoothManager scanForServices:0xFFFFFFFF];
}
}


- (void)bluetoothPowerChanged:(NSNotification *)notification
{
if ([self.bluetoothManager enabled]) {
[self.bluetoothManager setDeviceScanningEnabled:YES];
[self.bluetoothManager scanForServices:0xFFFFFFFF];
}
}



- (void)bluetoothDeviceDiscovered:(NSNotification *)notification
{
BluetoothDevice *device = (BluetoothDevice *)[notification object];
[self.delegate addBluetoothDevice:[device copy]];

// Log it
//NSLog(@"Name: %@\nAddress: %@\nMajorClass: %u\nMinorClass:%u\nType:%d\nBatteryLevelSupport:%hhd", device.name, device.address, device.majorClass, device.minorClass, device.type, device.supportsBatteryLevel);

}


- (void)bluetoothDeviceRemoved:(NSNotification *)notification
{
BluetoothDevice *device = (BluetoothDevice *)[notification object];
[self.delegate removeBluetoothDevice:device];

}





@end
16 changes: 16 additions & 0 deletions BeeTee/DeviceDetailViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// DeviceDetailViewController.h
// BluetoothScanner
//
// Created by Michael Dorner on 12.10.13.
// Copyright (c) 2013 Michael Dorner. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <BluetoothManager/BluetoothDevice.h>

@interface DeviceDetailViewController : UITableViewController

- (void)setBluetoothDevices:(BluetoothDevice *)device;

@end
Loading

0 comments on commit 3e43449

Please sign in to comment.