mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-16 08:42:28 +00:00
fix Preferences for iOS 3 (regression)
This commit is contained in:
parent
db93a898c2
commit
380349c4d8
@ -32,8 +32,8 @@
|
|||||||
// adapted from Ryan Petrich's Activator preferences bundle
|
// adapted from Ryan Petrich's Activator preferences bundle
|
||||||
// https://github.com/rpetrich/libactivator/blob/master/Preferences.m
|
// https://github.com/rpetrich/libactivator/blob/master/Preferences.m
|
||||||
|
|
||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
|
#include <dlfcn.h>
|
||||||
|
|
||||||
#import "BluetoothTableViewAdapter.h"
|
#import "BluetoothTableViewAdapter.h"
|
||||||
#import "BluetoothController.h"
|
#import "BluetoothController.h"
|
||||||
@ -42,6 +42,9 @@
|
|||||||
@interface PSViewController : NSObject
|
@interface PSViewController : NSObject
|
||||||
- (id)initForContentSize:(CGSize)size;
|
- (id)initForContentSize:(CGSize)size;
|
||||||
- (id)navigationItem;
|
- (id)navigationItem;
|
||||||
|
- (void)viewWillBecomeVisible:(void *)source;
|
||||||
|
- (void)viewWillAppear:(BOOL)animated;
|
||||||
|
- (void)viewDidDisappear:(BOOL)animated;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface PSViewController (OS32)
|
@interface PSViewController (OS32)
|
||||||
@ -58,6 +61,7 @@
|
|||||||
BluetoothController *bluetoothController;
|
BluetoothController *bluetoothController;
|
||||||
UIView *_wrapperView; // for < 3.2
|
UIView *_wrapperView; // for < 3.2
|
||||||
UITableView *tableView;
|
UITableView *tableView;
|
||||||
|
BOOL initialized;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation BluetoothPSViewController
|
@implementation BluetoothPSViewController
|
||||||
@ -65,6 +69,7 @@
|
|||||||
- (id)initForContentSize:(CGSize)size
|
- (id)initForContentSize:(CGSize)size
|
||||||
{
|
{
|
||||||
// NSLog(@"initForContentSize");
|
// NSLog(@"initForContentSize");
|
||||||
|
initialized = NO;
|
||||||
if ([PSViewController instancesRespondToSelector:@selector(initForContentSize:)]) {
|
if ([PSViewController instancesRespondToSelector:@selector(initForContentSize:)]) {
|
||||||
if ((self = [super initForContentSize:size])) {
|
if ((self = [super initForContentSize:size])) {
|
||||||
CGRect frame;
|
CGRect frame;
|
||||||
@ -93,6 +98,8 @@
|
|||||||
|
|
||||||
[_wrapperView release];
|
[_wrapperView release];
|
||||||
|
|
||||||
|
initialized = NO;
|
||||||
|
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,6 +108,53 @@
|
|||||||
return [super view] ? [super view] : _wrapperView;
|
return [super view] ? [super view] : _wrapperView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-(void)myInit{
|
||||||
|
|
||||||
|
if (initialized) return;
|
||||||
|
|
||||||
|
initialized = YES;
|
||||||
|
|
||||||
|
// NSLog(@"myInit");
|
||||||
|
|
||||||
|
((UINavigationItem*)[super navigationItem]).title = @"BTstack";
|
||||||
|
|
||||||
|
UIView *view = [self view];
|
||||||
|
|
||||||
|
tableView = [[UITableView alloc] initWithFrame:view.bounds style:UITableViewStyleGrouped];
|
||||||
|
tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
||||||
|
|
||||||
|
tableViewAdapter = [[BluetoothTableViewAdapter alloc] initWithTableView:tableView];
|
||||||
|
tableView.dataSource = tableViewAdapter;
|
||||||
|
tableView.delegate = tableViewAdapter;
|
||||||
|
|
||||||
|
[view addSubview:tableView];
|
||||||
|
|
||||||
|
[[BluetoothController sharedInstance] setListener:tableViewAdapter];
|
||||||
|
[[BluetoothController sharedInstance] open];
|
||||||
|
|
||||||
|
// register for backgrounding events on iOS 4+
|
||||||
|
NSString ** pUIApplicationDidEnterBackgroundNotification = nil;
|
||||||
|
NSString ** pUIApplicationWillEnterForegroundNotification = nil;
|
||||||
|
|
||||||
|
pUIApplicationDidEnterBackgroundNotification = dlsym(RTLD_DEFAULT, "UIApplicationDidEnterBackgroundNotification");
|
||||||
|
pUIApplicationWillEnterForegroundNotification = dlsym(RTLD_DEFAULT, "UIApplicationWillEnterForegroundNotification");
|
||||||
|
|
||||||
|
if (!pUIApplicationDidEnterBackgroundNotification) return;
|
||||||
|
if (!pUIApplicationWillEnterForegroundNotification) return;
|
||||||
|
|
||||||
|
[[NSNotificationCenter defaultCenter]
|
||||||
|
addObserver:self
|
||||||
|
selector:@selector(didEnterBackground:)
|
||||||
|
name:*pUIApplicationDidEnterBackgroundNotification
|
||||||
|
object:nil];
|
||||||
|
|
||||||
|
[[NSNotificationCenter defaultCenter]
|
||||||
|
addObserver:self
|
||||||
|
selector:@selector(willEnterForeground:)
|
||||||
|
name:*pUIApplicationWillEnterForegroundNotification
|
||||||
|
object:nil];
|
||||||
|
}
|
||||||
|
|
||||||
-(void)didEnterBackground:(id)object{
|
-(void)didEnterBackground:(id)object{
|
||||||
// NSLog(@"didEnterBackground");
|
// NSLog(@"didEnterBackground");
|
||||||
// close connection to BTdaemon
|
// close connection to BTdaemon
|
||||||
@ -110,53 +164,37 @@
|
|||||||
-(void)willEnterForeground:(id)object{
|
-(void)willEnterForeground:(id)object{
|
||||||
// NSLog(@"willEnterForeground");
|
// NSLog(@"willEnterForeground");
|
||||||
// open connection to BTdaemon
|
// open connection to BTdaemon
|
||||||
|
[self myInit];
|
||||||
[[BluetoothController sharedInstance] open];
|
[[BluetoothController sharedInstance] open];
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)viewWillAppear:(BOOL)animated {
|
|
||||||
|
- (void)viewWillAppear:(BOOL)animated
|
||||||
|
{
|
||||||
// NSLog(@"viewWillAppear");
|
// NSLog(@"viewWillAppear");
|
||||||
// open connection to BTdaemon
|
[super viewWillAppear:animated];
|
||||||
|
[self myInit];
|
||||||
[[BluetoothController sharedInstance] open];
|
[[BluetoothController sharedInstance] open];
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void) viewDidDisappear:(BOOL)animated {
|
- (void)viewWillBecomeVisible:(void *)source
|
||||||
|
{
|
||||||
|
// NSLog(@"viewWillBecomeVisible %@", source);
|
||||||
|
[super viewWillBecomeVisible:source];
|
||||||
|
[self myInit];
|
||||||
|
}
|
||||||
|
|
||||||
|
-(void)viewDidDisappear:(BOOL)animated {
|
||||||
// NSLog(@"viewDidDisappear");
|
// NSLog(@"viewDidDisappear");
|
||||||
// close connection to BTdaemon
|
// close connection to BTdaemon
|
||||||
[[BluetoothController sharedInstance] close];
|
[[BluetoothController sharedInstance] close];
|
||||||
|
[super viewDidDisappear:animated];
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)viewDidLoad {
|
-(void)viewDidLoad
|
||||||
// setup view
|
{
|
||||||
// NSLog(@"initialize");
|
// NSLog(@"viewDidLoad");
|
||||||
|
[super viewDidLoad];
|
||||||
((UINavigationItem*)[super navigationItem]).title = @"BTstack";
|
[self myInit];
|
||||||
|
|
||||||
UIView *view = [self view];
|
|
||||||
|
|
||||||
tableView = [[UITableView alloc] initWithFrame:view.bounds style:UITableViewStyleGrouped];
|
|
||||||
tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
|
||||||
|
|
||||||
tableViewAdapter = [[BluetoothTableViewAdapter alloc] initWithTableView:tableView];
|
|
||||||
tableView.dataSource = tableViewAdapter;
|
|
||||||
tableView.delegate = tableViewAdapter;
|
|
||||||
|
|
||||||
[view addSubview:tableView];
|
|
||||||
|
|
||||||
// setup Bluetooth Controller
|
|
||||||
[[BluetoothController sharedInstance] setListener:tableViewAdapter];
|
|
||||||
|
|
||||||
// register for backrounding events
|
|
||||||
[[NSNotificationCenter defaultCenter]
|
|
||||||
addObserver:self
|
|
||||||
selector:@selector(didEnterBackground:)
|
|
||||||
name:UIApplicationDidEnterBackgroundNotification
|
|
||||||
object:nil];
|
|
||||||
|
|
||||||
[[NSNotificationCenter defaultCenter]
|
|
||||||
addObserver:self
|
|
||||||
selector:@selector(willEnterForeground:)
|
|
||||||
name:UIApplicationWillEnterForegroundNotification
|
|
||||||
object:nil];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user