Last active
October 25, 2025 13:37
-
-
Save shahidghafoor00/11e5a68800dc3f5a8431c452aa992e4e to your computer and use it in GitHub Desktop.
MasterViewController Updated code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import "MasterViewController.h" | |
| #import "DetailViewController.h" | |
| #import "UIImage+PDF.h" | |
| #import "TestViewController.h" | |
| #import "Constants.h" | |
| #include <sys/types.h> | |
| #include <sys/sysctl.h> | |
| @interface MasterViewController () | |
| @end | |
| @implementation MasterViewController | |
| //- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { | |
| // return YES; | |
| //} | |
| - (BOOL)shouldAutorotate | |
| { | |
| return YES; | |
| } | |
| - (NSString *) platform { | |
| size_t size; | |
| sysctlbyname("hw.machine", NULL, &size, NULL, 0); | |
| char *machine = malloc(size); | |
| sysctlbyname("hw.machine", machine, &size, NULL, 0); | |
| NSString *platform = [NSString stringWithUTF8String:machine]; | |
| free(machine); | |
| return platform; | |
| } | |
| -(void)platformNotSupported{ | |
| // UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Model Not Supported" | |
| // message:@"This iPad model is not yet supported, please contact OTG" | |
| // delegate:nil | |
| // cancelButtonTitle:@"OK" otherButtonTitles: nil]; | |
| // [alert show]; | |
| UIAlertController * alert = [UIAlertController | |
| alertControllerWithTitle:@"Model Not Supported" | |
| message:@"This iPad model is not yet supported, please contact OTG" | |
| preferredStyle:UIAlertControllerStyleAlert]; | |
| UIAlertAction* yesButton = [UIAlertAction | |
| actionWithTitle:@"OK" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction * action) { | |
| }]; | |
| [alert addAction:yesButton]; | |
| [self presentViewController:alert animated:YES completion:nil]; | |
| } | |
| -(void)iPadShouldNotHaveExternal{ | |
| // UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Use Near or Inter" | |
| // message:@"Please place this iPad into Bluetooth Receiving mode and use a Near or Inter iPad to setup test" | |
| // delegate:nil | |
| // cancelButtonTitle:@"OK" otherButtonTitles: nil]; | |
| // [alert show]; | |
| UIAlertController * alert = [UIAlertController | |
| alertControllerWithTitle:@"Use Near or Inter" | |
| message:@"Please place this iPad into Bluetooth Receiving mode and use a Near or Inter iPad to setup test" | |
| preferredStyle:UIAlertControllerStyleAlert]; | |
| UIAlertAction* yesButton = [UIAlertAction | |
| actionWithTitle:@"OK" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction * action) { | |
| }]; | |
| [alert addAction:yesButton]; | |
| [self presentViewController:alert animated:YES completion:nil]; | |
| } | |
| - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil | |
| { | |
| self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; | |
| if (self) { | |
| self.title = NSLocalizedString(@"Master", @"Master"); | |
| self.clearsSelectionOnViewWillAppear = NO; | |
| self.preferredContentSize = CGSizeMake(320.0, 600.0); | |
| } | |
| return self; | |
| } | |
| -(void)viewDidAppear:(BOOL)animated { | |
| if (self.centralManager) { | |
| if (self.discoveredPeripheral){ | |
| [self.centralManager cancelPeripheralConnection:self.discoveredPeripheral]; | |
| } | |
| } | |
| [self.navigationController setToolbarHidden:NO]; | |
| if ([[UIScreen screens] count] > 1) { | |
| [self externalScreenMounted]; | |
| } | |
| } | |
| -(void)viewWillDisappear:(BOOL)animated { | |
| [self.centralManager stopScan]; | |
| //[self.receivingAlert dismissWithClickedButtonIndex:0 animated:false]; | |
| if (self.receivingAlert) { | |
| [self.receivingAlert dismissViewControllerAnimated:true completion:nil]; | |
| } | |
| } | |
| - (void)externalScreenMounted { | |
| UIScreen *secondScreen = [[UIScreen screens] objectAtIndex:1]; | |
| self.secondWindow = [[UIWindow alloc] initWithFrame:CGRectMake(0,0,1920,1080)]; | |
| self.secondWindow.screen = secondScreen; | |
| secondScreen.overscanCompensation = 3; | |
| self.secondWindow.hidden = NO; | |
| self.slideView = [[UIImageView alloc]init]; | |
| self.slideView.image = [UIImage imageNamed:@"readyScreen"]; | |
| self.currentPage = 0; | |
| self.slideView.contentMode = UIViewContentModeScaleAspectFill; | |
| self.slideView.frame = self.secondWindow.frame; | |
| self.secondWindow.backgroundColor = [self testSpecificBackgroundColor]; | |
| [self.secondWindow addSubview:self.slideView]; | |
| } | |
| - (void)externalScreenMountedGo { | |
| UIScreen *secondScreen = [[UIScreen screens] objectAtIndex:1]; | |
| self.secondWindow = [[UIWindow alloc] initWithFrame:CGRectMake(0,0,1920,1080)]; | |
| self.secondWindow.screen = secondScreen; | |
| secondScreen.overscanCompensation = 3; | |
| self.secondWindow.hidden = NO; | |
| self.slideView = [[UIImageView alloc]init]; | |
| self.slideView.image = [UIImage imageWithData:[self.testSlides objectAtIndex:0]]; | |
| self.currentPage = 0; | |
| self.slideView.contentMode = UIViewContentModeScaleAspectFit; | |
| self.slideView.frame = self.secondWindow.frame; | |
| self.secondWindow.backgroundColor = [self testSpecificBackgroundColor]; | |
| [self.secondWindow addSubview:self.slideView]; | |
| } | |
| - (void) screenDidConnect:(NSNotification *)aNotification { | |
| NSLog(@"A new screen got connected: %@", [aNotification object]); | |
| if ([self.testType isEqualToString:@"VA Alternate Three Landolt"] && | |
| [[UIScreen screens] count] > 1) { | |
| self.testDistance = @"400cm-400cm-400cm"; | |
| self.title = @"Test Setup - Three Landolt Distance"; | |
| } | |
| if ([[UIScreen screens] count] > 1) { | |
| self.testDistance = @"200cm"; | |
| self.title = @"Test Setup - Distance"; | |
| if ([self.testType isEqualToString:@"VA Alternate Two Landolt"]){ | |
| self.testType = @"VA Static Letter"; | |
| } | |
| } else if ([IPADMINIS containsObject:[self platform]]){ | |
| self.testDistance = @"40cm"; | |
| self.title = @"Test Setup - Near"; | |
| ////iPad Mini | |
| } else if ([IPADAIRS containsObject:[self platform]]){ | |
| self.testDistance = @"100cm"; | |
| self.title = @"Test Setup - Inter"; | |
| ////iPad Airs | |
| } else { | |
| self.testDistance = @"40cm"; | |
| self.title = @"Test Setup"; | |
| } | |
| [self.tableView reloadData]; | |
| } | |
| - (void) screenDidDisconnect:(NSNotification *)aNotification{ | |
| NSLog(@"A screen got disconnected: %@", [aNotification object]); | |
| if ([self.testType isEqualToString:@"VA Alternate Three Landolt"]) { | |
| if ([IPADMINIS containsObject:[self platform]]){ | |
| self.testDistance = @"40cm-67cm-400cm"; | |
| } else { | |
| self.testDistance = @"400cm-400cm-400cm"; | |
| } | |
| self.title = @"Test Setup - Three Landolt"; | |
| } | |
| if ([[UIScreen screens] count] > 1) { | |
| self.testDistance = @"200cm"; | |
| self.title = @"Test Setup - Distance"; | |
| } else if ([IPADMINIS containsObject:[self platform]]){ | |
| self.testDistance = @"40cm"; | |
| self.title = @"Test Setup - Near"; | |
| ////iPad Mini | |
| } else if ([IPADAIRS containsObject:[self platform]]){ | |
| self.testDistance = @"100cm"; | |
| self.title = @"Test Setup - Inter"; | |
| ////iPad Airs | |
| } else { | |
| self.testDistance = @"40cm"; | |
| self.title = @"Test Setup"; | |
| } | |
| [self.tableView reloadData]; | |
| } | |
| - (void)viewDidLoad | |
| { | |
| [super viewDidLoad]; | |
| if ([self.navigationController.toolbar respondsToSelector:@selector(setTintColor:)]) { | |
| [self.navigationController.toolbar setTintColor:[UIColor redColor]]; | |
| [self.navigationController.toolbar setBackgroundColor:[UIColor lightGrayColor]]; | |
| } | |
| [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(screenDidConnect:) name:UIScreenDidConnectNotification object:nil]; | |
| [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(screenDidDisconnect:) name:UIScreenDidDisconnectNotification object:nil]; | |
| [[NSNotificationCenter defaultCenter] addObserver:self | |
| selector:@selector(nextExternal) | |
| name:@"nextExternal" | |
| object:nil]; | |
| [[NSNotificationCenter defaultCenter] addObserver:self | |
| selector:@selector(previousExternal) | |
| name:@"previousExternal" | |
| object:nil]; | |
| [[NSNotificationCenter defaultCenter] addObserver:self | |
| selector:@selector(closeTest) | |
| name:@"closeTest" | |
| object:nil]; | |
| [[NSNotificationCenter defaultCenter] addObserver:self | |
| selector:@selector(nextExternalAlternate) | |
| name:@"externalShowAlternate" | |
| object:nil]; | |
| [[NSNotificationCenter defaultCenter] addObserver:self | |
| selector:@selector(goBlank) | |
| name:@"externalBlank" | |
| object:nil]; | |
| [[NSNotificationCenter defaultCenter] addObserver:self | |
| selector:@selector(finishExternal) | |
| name:@"finishExternal" | |
| object:nil]; | |
| self.luminance = @"Special"; | |
| [[UIScreen mainScreen] setBrightness:1.0]; | |
| if ([[UIScreen screens] count] > 1) { | |
| self.testDistance = @"200cm"; | |
| self.title = @"Test Setup - Distance"; | |
| } else if ([IPADMINIS containsObject:[self platform]]){ | |
| self.testDistance = @"40cm"; | |
| self.title = @"Test Setup - Near"; | |
| ////iPad Mini | |
| } else if ([IPADAIRS containsObject:[self platform]]){ | |
| self.testDistance = @"100cm"; | |
| self.title = @"Test Setup - Inter"; | |
| ////iPad Airs | |
| } else { | |
| self.testDistance = @"400cm"; | |
| self.title = @"Test Setup"; | |
| } | |
| // Set Country Driving as default test | |
| self.testType = @"Country Driving"; | |
| self.contrast = @"Standard"; | |
| self.testSet = @"Set 1"; | |
| self.dynamicTime = @"1000ms"; | |
| self.letterSize = @"-10"; | |
| self.exposureEven = 1000; | |
| self.exposureOdd = 300; | |
| [[UIScreen mainScreen] setBrightness:1.0]; | |
| UIImageView *tempImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"master-background"]]; | |
| [tempImageView setFrame:self.tableView.frame]; | |
| self.tableView.backgroundView = tempImageView; | |
| [self.tableView setSeparatorColor:[UIColor clearColor]]; | |
| [self.tableView reloadData]; | |
| UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithTitle:@"Load Test" style:UIBarButtonItemStylePlain target:self action:@selector(beginTest)]; | |
| [barButton setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: | |
| [UIFont fontWithName:@"AvenirNext-DemiBoldItalic" size:18], NSFontAttributeName, nil] forState:UIControlStateNormal]; | |
| UIBarButtonItem *barButtonFlexibleGap = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; | |
| // [self setToolbarItems:[NSArray arrayWithObjects: barButtonFlexibleGap,barButton,barButtonFlexibleGap,nil]]; | |
| [self setToolbarItems:[NSArray arrayWithObjects: barButtonFlexibleGap,barButton,barButtonFlexibleGap,nil]]; | |
| self.tableView.rowHeight = 50; | |
| } | |
| -(void)closeTest{ | |
| if (self.slideView != nil){ | |
| self.slideView.image = [UIImage imageNamed:@"readyScreen"]; | |
| self.slideView.contentMode = UIViewContentModeScaleAspectFill; | |
| [self.closeButtonExternal removeFromSuperview]; | |
| [self.blurViewExternal removeFromSuperview]; | |
| } | |
| } | |
| -(void)previousExternal{ | |
| if (self.slideView != nil && self.slideView.image != [UIImage imageNamed:@"readyScreen"]){ | |
| if (self.currentPage > 0){ | |
| self.currentPage = self.currentPage - 1; | |
| self.slideView.contentMode = UIViewContentModeScaleAspectFit; | |
| self.slideView.image = [UIImage imageWithData:[self.testSlides objectAtIndex:self.currentPage]]; | |
| } | |
| } | |
| } | |
| -(void)nextExternal{ | |
| if (self.slideView != nil && self.slideView.image != [UIImage imageNamed:@"readyScreen"]){ | |
| if (self.currentPage < self.totalPages){ | |
| self.currentPage = self.currentPage + 1; | |
| self.slideView.contentMode = UIViewContentModeScaleAspectFit; | |
| self.slideView.image = [UIImage imageWithData:[self.testSlides objectAtIndex:self.currentPage]]; | |
| } | |
| } | |
| } | |
| -(void)nextExternalAlternate{ | |
| if (self.slideView != nil && self.slideView.image != [UIImage imageNamed:@"readyScreen"]){ | |
| if (self.currentPage < self.totalPages - 1){ | |
| self.currentPage = self.currentPage + 2; | |
| self.slideView.contentMode = UIViewContentModeScaleAspectFit; | |
| self.slideView.image = [UIImage imageWithData:[self.testSlides objectAtIndex:self.currentPage]]; | |
| [self performSelector:@selector(goBlank) withObject:nil afterDelay:((double)self.exposureOdd/1000)]; | |
| } | |
| } | |
| } | |
| -(void)goBlank{ | |
| self.slideView.image = nil; | |
| } | |
| -(void)finishExternal{ | |
| if (self.slideView!= nil){ | |
| UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]; | |
| self.blurViewExternal = [[UIVisualEffectView alloc] initWithEffect:blurEffect]; | |
| self.blurViewExternal.frame = self.secondWindow.bounds; | |
| self.blurViewExternal.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; | |
| [self.secondWindow addSubview:self.blurViewExternal]; | |
| self.closeButtonExternal = [UIButton buttonWithType:UIButtonTypeCustom]; | |
| [self.closeButtonExternal setTitle:@"Test Complete" forState:UIControlStateNormal]; | |
| self.closeButtonExternal.backgroundColor = [UIColor clearColor]; | |
| self.closeButtonExternal.titleLabel.font = [UIFont fontWithName:@"AvenirNext-DemiBoldItalic" size:24]; | |
| self.closeButtonExternal.frame = self.secondWindow.bounds; | |
| [self.secondWindow addSubview:self.closeButtonExternal]; | |
| } | |
| } | |
| #pragma mark - Table View | |
| - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView | |
| { | |
| if ([self.testType isEqualToString:@"CS Peripheral Shape"] || | |
| [self.testType isEqualToString:@"Reading Test A"] || | |
| [self.testType isEqualToString:@"Reading Test B"] || | |
| [self.testType isEqualToString:@"Reading Test C"] | |
| ) | |
| { | |
| return 5; | |
| } else if ( | |
| [self.testType isEqualToString:@"VA Alternate Two Landolt"] | |
| ) | |
| { | |
| return 6; | |
| } else if ( | |
| [self.testType isEqualToString:@"Country Driving"] || | |
| [self.testType isEqualToString:@"In Town Driving No Glare"] || | |
| [self.testType isEqualToString:@"In Town Driving Glare 1"] || | |
| [self.testType isEqualToString:@"In Town Driving Glare 2"] || | |
| [self.testType isEqualToString:@"Extra 1"] || | |
| [self.testType isEqualToString:@"Extra 2"] || | |
| [self.testType isEqualToString:@"Extra 3"] || | |
| [self.testType isEqualToString:@"Extra 4"] || | |
| [self.testType isEqualToString:@"Extra 5"] || | |
| [self.testType isEqualToString:@"City Night Driving 10% Glare Off"] || | |
| [self.testType isEqualToString:@"City Night Driving 25% Glare Off"] || | |
| [self.testType isEqualToString:@"City Night Driving 100% Glare Off"] | |
| ) | |
| { | |
| return 7; // Test Type, Luminance, Distance, Contrast, Set, Letter Size, Inter Optotype Time | |
| } else { | |
| return 7; | |
| } | |
| } | |
| - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section | |
| { | |
| return 1; | |
| } | |
| // Customize the appearance of table view cells. | |
| - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath | |
| { | |
| static NSString *CellIdentifier = @"Cell"; | |
| UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; | |
| if (cell == nil) { | |
| cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; | |
| } | |
| NSArray *menuHeaders = @[self.testType,self.luminance,self.testDistance,self.contrast,self.testSet,self.letterSize,self.dynamicTime]; | |
| cell.textLabel.textColor = [UIColor whiteColor]; | |
| cell.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0]; | |
| cell.textLabel.font = [UIFont fontWithName:@"AvenirNext-DemiBoldItalic" size:17]; | |
| UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, cell.contentView.bounds.size.width, 1)]; | |
| lineView.backgroundColor = [UIColor colorWithRed:0.4 green:0.8 blue:0.992 alpha:0.5]; | |
| lineView.autoresizingMask = 0x3f; | |
| UIView *lineView2 = [[UIView alloc] initWithFrame:CGRectMake(0, 49, cell.contentView.bounds.size.width, 1)]; | |
| lineView2.backgroundColor = [UIColor whiteColor]; | |
| [cell addSubview:lineView2]; | |
| cell.textLabel.text = [menuHeaders objectAtIndex:indexPath.section]; | |
| if (indexPath.section == 0){ | |
| cell.imageView.image = [UIImage imageNamed:@"testType"]; | |
| } else if (indexPath.section == 1){ | |
| cell.imageView.image = [UIImage imageNamed:@"luminance"]; | |
| } else if (indexPath.section == 2){ | |
| cell.imageView.image = [UIImage imageNamed:@"distance"]; | |
| } else if (indexPath.section == 3){ | |
| cell.imageView.image = [UIImage imageNamed:@"contrast"]; | |
| } else if (indexPath.section == 4){ | |
| cell.imageView.image = [UIImage imageNamed:@"set"]; | |
| } else if (indexPath.section == 5){ | |
| cell.imageView.image = [UIImage imageNamed:@"letterSize"]; | |
| } else if (indexPath.section == 6){ | |
| cell.imageView.image = [UIImage imageNamed:@"exposure"]; | |
| } else { | |
| cell.imageView.image = nil; | |
| } | |
| cell.selectedBackgroundView = [UIView new]; | |
| cell.selectedBackgroundView.backgroundColor = [UIColor blackColor]; | |
| return cell; | |
| } | |
| -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section | |
| { | |
| UIView *tempView=[[UIView alloc]initWithFrame:CGRectMake(0,200,300,244)]; | |
| tempView.backgroundColor=[UIColor colorWithRed:0.024 green:0.318 blue:0.467 alpha:0.0]; | |
| UILabel *tempLabel=[[UILabel alloc]initWithFrame:CGRectMake(10,4,300,16)]; | |
| tempLabel.backgroundColor=[UIColor clearColor]; | |
| tempLabel.textColor = [UIColor colorWithWhite:1.0 alpha:0.7]; //here you can change the text color of header. | |
| tempLabel.font = [UIFont fontWithName:@"AvenirNext-DemiBoldItalic" size:15]; | |
| NSArray *sectionNamesArray; | |
| if ( | |
| [self.testType isEqualToString:@"Country Driving"] || | |
| [self.testType isEqualToString:@"In Town Driving No Glare"] || | |
| [self.testType isEqualToString:@"In Town Driving Glare 1"] || | |
| [self.testType isEqualToString:@"In Town Driving Glare 2"] || | |
| [self.testType isEqualToString:@"Extra 1"] || | |
| [self.testType isEqualToString:@"Extra 2"] || | |
| [self.testType isEqualToString:@"Extra 3"] || | |
| [self.testType isEqualToString:@"Extra 4"] || | |
| [self.testType isEqualToString:@"Extra 5"] || | |
| [self.testType isEqualToString:@"City Night Driving 10% Glare Off"] || // NEW | |
| [self.testType isEqualToString:@"City Night Driving 25% Glare Off"] || // NEW | |
| [self.testType isEqualToString:@"City Night Driving 100% Glare Off"]) { // NEW | |
| sectionNamesArray = @[@"Test Type", @"Luminance", @"Test Distance", @"Contrast", @"Set", @"Letter Size", @"Inter Optotype"]; | |
| } else { | |
| sectionNamesArray = @[@"Test Type", @"Luminance", @"Test Distance", @"Contrast", @"Set", @"Letter Size", @"Exposure"]; | |
| } | |
| tempLabel.text= [sectionNamesArray objectAtIndex:section]; | |
| [tempView addSubview:tempLabel]; | |
| return tempView; | |
| } | |
| - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath | |
| { | |
| return NO; | |
| } | |
| - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath | |
| { | |
| ///////TEST TYPE | |
| if (indexPath.section == 0){ | |
| UIAlertController *alert= [UIAlertController | |
| alertControllerWithTitle:@"Select Test Type" | |
| message:nil | |
| preferredStyle:UIAlertControllerStyleActionSheet]; | |
| UIAlertAction *option2g = [UIAlertAction | |
| actionWithTitle:@"Country Driving" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) { | |
| self.testType = @"Country Driving"; | |
| self.testDistance = @"400cm"; | |
| self.contrast = @"Standard"; | |
| self.dynamicTime = @"1000ms"; | |
| self.luminance = @"Special"; | |
| [[UIScreen mainScreen] setBrightness:1.0]; | |
| // Set validation | |
| if ([self.testSet isEqualToString:@"Set 1"] || | |
| [self.testSet isEqualToString:@"Set 2"] || | |
| [self.testSet isEqualToString:@"Set 3"] || | |
| [self.testSet isEqualToString:@"Set 4"] || | |
| [self.testSet isEqualToString:@"Set 5"]) { | |
| // Valid sets remain unchanged | |
| } else { | |
| self.testSet = @"Set 1"; | |
| } | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| [self.centralManager stopScan]; | |
| if (self.centralManager && self.discoveredPeripheral) { | |
| [self.centralManager cancelPeripheralConnection:self.discoveredPeripheral]; | |
| } | |
| } | |
| ]; | |
| UIAlertAction *option2h = [UIAlertAction | |
| actionWithTitle:@"In Town Driving No Glare" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) { | |
| self.testType = @"In Town Driving No Glare"; | |
| self.testDistance = @"400cm"; | |
| self.contrast = @"Standard"; | |
| self.dynamicTime = @"1000ms"; | |
| self.luminance = @"Special"; | |
| self.letterSize = @"+1"; | |
| [[UIScreen mainScreen] setBrightness:1.0]; | |
| // Set validation | |
| if ([self.testSet isEqualToString:@"Set 1"] || | |
| [self.testSet isEqualToString:@"Set 2"] || | |
| [self.testSet isEqualToString:@"Set 3"] || | |
| [self.testSet isEqualToString:@"Set 4"] || | |
| [self.testSet isEqualToString:@"Set 5"]) { | |
| // Valid sets remain unchanged | |
| } else { | |
| self.testSet = @"Set 1"; | |
| } | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| [self.centralManager stopScan]; | |
| if (self.centralManager && self.discoveredPeripheral) { | |
| [self.centralManager cancelPeripheralConnection:self.discoveredPeripheral]; | |
| } | |
| } | |
| ]; | |
| UIAlertAction *option2i = [UIAlertAction | |
| actionWithTitle:@"In Town Driving Glare 1" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) { | |
| self.testType = @"In Town Driving Glare 1"; | |
| self.testDistance = @"400cm"; | |
| self.contrast = @"Standard"; | |
| self.dynamicTime = @"1000ms"; | |
| self.luminance = @"Special"; | |
| self.letterSize = @"-1"; | |
| [[UIScreen mainScreen] setBrightness:1.0]; | |
| // Set validation | |
| if ([self.testSet isEqualToString:@"Set 1"] || | |
| [self.testSet isEqualToString:@"Set 2"] || | |
| [self.testSet isEqualToString:@"Set 3"] || | |
| [self.testSet isEqualToString:@"Set 4"] || | |
| [self.testSet isEqualToString:@"Set 5"]) { | |
| // Valid sets remain unchanged | |
| } else { | |
| self.testSet = @"Set 1"; | |
| } | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| [self.centralManager stopScan]; | |
| if (self.centralManager && self.discoveredPeripheral) { | |
| [self.centralManager cancelPeripheralConnection:self.discoveredPeripheral]; | |
| } | |
| } | |
| ]; | |
| UIAlertAction *option2j = [UIAlertAction | |
| actionWithTitle:@"In Town Driving Glare 2" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) { | |
| self.testType = @"In Town Driving Glare 2"; | |
| self.testDistance = @"400cm"; | |
| self.contrast = @"Standard"; | |
| self.dynamicTime = @"1000ms"; | |
| self.luminance = @"Special"; | |
| self.letterSize = @"-6"; | |
| [[UIScreen mainScreen] setBrightness:1.0]; | |
| // Set validation | |
| if ([self.testSet isEqualToString:@"Set 1"] || | |
| [self.testSet isEqualToString:@"Set 2"] || | |
| [self.testSet isEqualToString:@"Set 3"] || | |
| [self.testSet isEqualToString:@"Set 4"] || | |
| [self.testSet isEqualToString:@"Set 5"]) { | |
| // Valid sets remain unchanged | |
| } else { | |
| self.testSet = @"Set 1"; | |
| } | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| [self.centralManager stopScan]; | |
| if (self.centralManager && self.discoveredPeripheral) { | |
| [self.centralManager cancelPeripheralConnection:self.discoveredPeripheral]; | |
| } | |
| } | |
| ]; | |
| UIAlertAction *option2k = [UIAlertAction | |
| actionWithTitle:@"Extra 1" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) { | |
| self.testType = @"Extra 1"; | |
| self.testDistance = @"400cm"; | |
| self.contrast = @"25%"; | |
| self.dynamicTime = @"500ms"; | |
| // Set validation | |
| if ([self.testSet isEqualToString:@"Set 1"] || | |
| [self.testSet isEqualToString:@"Set 2"] || | |
| [self.testSet isEqualToString:@"Set 3"] || | |
| [self.testSet isEqualToString:@"Set 4"] || | |
| [self.testSet isEqualToString:@"Set 5"]) { | |
| // Valid sets remain unchanged | |
| } else { | |
| self.testSet = @"Set 1"; | |
| } | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| [self.centralManager stopScan]; | |
| if (self.centralManager && self.discoveredPeripheral) { | |
| [self.centralManager cancelPeripheralConnection:self.discoveredPeripheral]; | |
| } | |
| } | |
| ]; | |
| UIAlertAction *option2l = [UIAlertAction | |
| actionWithTitle:@"Extra 2" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) { | |
| self.testType = @"Extra 2"; | |
| self.testDistance = @"400cm"; | |
| self.contrast = @"100%"; | |
| self.dynamicTime = @"500ms"; | |
| // Set validation | |
| if ([self.testSet isEqualToString:@"Set 1"] || | |
| [self.testSet isEqualToString:@"Set 2"] || | |
| [self.testSet isEqualToString:@"Set 3"] || | |
| [self.testSet isEqualToString:@"Set 4"] || | |
| [self.testSet isEqualToString:@"Set 5"]) { | |
| // Valid sets remain unchanged | |
| } else { | |
| self.testSet = @"Set 1"; | |
| } | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| [self.centralManager stopScan]; | |
| if (self.centralManager && self.discoveredPeripheral) { | |
| [self.centralManager cancelPeripheralConnection:self.discoveredPeripheral]; | |
| } | |
| } | |
| ]; | |
| UIAlertAction *option2m = [UIAlertAction | |
| actionWithTitle:@"Extra 3" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) { | |
| self.testType = @"Extra 3"; | |
| self.testDistance = @"400cm"; | |
| self.contrast = @"10%"; | |
| self.dynamicTime = @"500ms"; | |
| // Set validation | |
| if ([self.testSet isEqualToString:@"Set 1"] || | |
| [self.testSet isEqualToString:@"Set 2"] || | |
| [self.testSet isEqualToString:@"Set 3"] || | |
| [self.testSet isEqualToString:@"Set 4"] || | |
| [self.testSet isEqualToString:@"Set 5"]) { | |
| // Valid sets remain unchanged | |
| } else { | |
| self.testSet = @"Set 1"; | |
| } | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| [self.centralManager stopScan]; | |
| if (self.centralManager && self.discoveredPeripheral) { | |
| [self.centralManager cancelPeripheralConnection:self.discoveredPeripheral]; | |
| } | |
| } | |
| ]; | |
| UIAlertAction *option2n = [UIAlertAction | |
| actionWithTitle:@"Extra 4" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) { | |
| self.testType = @"Extra 4"; | |
| self.testDistance = @"400cm"; | |
| self.contrast = @"25%"; | |
| self.dynamicTime = @"500ms"; | |
| // Set validation | |
| if ([self.testSet isEqualToString:@"Set 1"] || | |
| [self.testSet isEqualToString:@"Set 2"] || | |
| [self.testSet isEqualToString:@"Set 3"] || | |
| [self.testSet isEqualToString:@"Set 4"] || | |
| [self.testSet isEqualToString:@"Set 5"]) { | |
| // Valid sets remain unchanged | |
| } else { | |
| self.testSet = @"Set 1"; | |
| } | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| [self.centralManager stopScan]; | |
| if (self.centralManager && self.discoveredPeripheral) { | |
| [self.centralManager cancelPeripheralConnection:self.discoveredPeripheral]; | |
| } | |
| } | |
| ]; | |
| UIAlertAction *option2o = [UIAlertAction | |
| actionWithTitle:@"Extra 5" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) { | |
| self.testType = @"Extra 5"; | |
| self.testDistance = @"400cm"; | |
| self.contrast = @"100%"; | |
| self.dynamicTime = @"500ms"; | |
| // Set validation | |
| if ([self.testSet isEqualToString:@"Set 1"] || | |
| [self.testSet isEqualToString:@"Set 2"] || | |
| [self.testSet isEqualToString:@"Set 3"] || | |
| [self.testSet isEqualToString:@"Set 4"] || | |
| [self.testSet isEqualToString:@"Set 5"]) { | |
| // Valid sets remain unchanged | |
| } else { | |
| self.testSet = @"Set 1"; | |
| } | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| [self.centralManager stopScan]; | |
| if (self.centralManager && self.discoveredPeripheral) { | |
| [self.centralManager cancelPeripheralConnection:self.discoveredPeripheral]; | |
| } | |
| } | |
| ]; | |
| UIAlertAction *option5 = [UIAlertAction | |
| actionWithTitle:@"Receive Bluetooth" | |
| style:UIAlertActionStyleDestructive | |
| handler:^(UIAlertAction *action) | |
| { | |
| [self scanForBluetoothSignal]; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| }]; | |
| UIAlertAction *cancel = [UIAlertAction | |
| actionWithTitle:@"Cancel" | |
| style:UIAlertActionStyleCancel | |
| handler:^(UIAlertAction *action) | |
| { | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| }]; | |
| [alert addAction:option2g]; // Country Driving | |
| [alert addAction:option2h]; // In Town Driving No Glare | |
| [alert addAction:option2i]; // In Town Driving Glare 1 | |
| [alert addAction:option2j]; // In Town Driving Glare 2 | |
| [alert addAction:option2k]; | |
| [alert addAction:option2l]; | |
| [alert addAction:option2m]; | |
| [alert addAction:option2n]; | |
| [alert addAction:option2o]; | |
| if (![self.title isEqualToString:@"Test Setup - Near"]) { | |
| [alert addAction:option5]; | |
| ////Will not show Receive Bluetooth if app identifies Near iPad | |
| } | |
| if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone ) { | |
| [alert addAction:cancel]; | |
| } | |
| alert.popoverPresentationController.sourceView = [tableView cellForRowAtIndexPath:indexPath]; | |
| alert.popoverPresentationController.sourceRect = [tableView cellForRowAtIndexPath:indexPath].bounds; | |
| dispatch_async(dispatch_get_main_queue(), ^{ | |
| [alert.view layoutIfNeeded]; | |
| [self presentViewController:alert animated:YES completion:nil]; | |
| }); | |
| } | |
| ///////TEST TYPE | |
| ///////LUMINANCE | |
| if (indexPath.section == 1){ | |
| UIAlertController *alert= [UIAlertController | |
| alertControllerWithTitle:@"Select Luminance" | |
| message:nil | |
| preferredStyle:UIAlertControllerStyleActionSheet]; | |
| UIAlertAction *option1 = [UIAlertAction | |
| actionWithTitle:@"Low / 50cd" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.luminance = @"Low / 50cd"; | |
| [[UIScreen mainScreen] setBrightness:0.28]; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option2 = [UIAlertAction | |
| actionWithTitle:@"High / 250cd" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.luminance = @"High / 250cd"; | |
| [[UIScreen mainScreen] setBrightness:0.8]; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option3 = [UIAlertAction | |
| actionWithTitle:@"Medium / 85cd" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.luminance = @"Medium / 85cd"; | |
| [[UIScreen mainScreen] setBrightness:0.4]; // Adjust brightness to approximate 85cd | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option4 = [UIAlertAction | |
| actionWithTitle:@"Special" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.luminance = @"Special"; | |
| [[UIScreen mainScreen] setBrightness:1.0]; // Or whatever brightness you want for "Special" | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *cancel = [UIAlertAction | |
| actionWithTitle:@"Cancel" | |
| style:UIAlertActionStyleCancel | |
| handler:^(UIAlertAction *action) | |
| { | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| }]; | |
| // Add Special option for the new test types | |
| if ([self.testType isEqualToString:@"Country Driving"] || | |
| [self.testType isEqualToString:@"In Town Driving No Glare"] || | |
| [self.testType isEqualToString:@"In Town Driving Glare 1"] || | |
| [self.testType isEqualToString:@"In Town Driving Glare 2"]) { | |
| [alert addAction:option4]; // Special | |
| } else { | |
| [alert addAction:option1]; | |
| if ([self.testType isEqualToString:@"Reading Test A"] || | |
| [self.testType isEqualToString:@"Reading Test B"] || | |
| [self.testType isEqualToString:@"Reading Test C"]) { | |
| [alert addAction:option3]; // Medium / 85cd | |
| } | |
| [alert addAction:option2]; | |
| if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone ) { | |
| [alert addAction:cancel]; | |
| } | |
| } | |
| alert.popoverPresentationController.sourceView = [tableView cellForRowAtIndexPath:indexPath]; | |
| alert.popoverPresentationController.sourceRect = [tableView cellForRowAtIndexPath:indexPath].bounds; | |
| dispatch_async(dispatch_get_main_queue(), ^{ | |
| [alert.view layoutIfNeeded]; | |
| [self presentViewController:alert animated:YES completion:nil]; | |
| }); | |
| } | |
| ///////LUMINANCE | |
| ///////DISTANCE | |
| if (indexPath.section == 2 && | |
| ([self.testType isEqualToString:@"Country Driving"] || | |
| [self.testType isEqualToString:@"In Town Driving No Glare"] || | |
| [self.testType isEqualToString:@"In Town Driving Glare 1"] || | |
| [self.testType isEqualToString:@"In Town Driving Glare 2"] || | |
| [self.testType isEqualToString:@"Extra 1"] || | |
| [self.testType isEqualToString:@"Extra 2"] || | |
| [self.testType isEqualToString:@"Extra 3"] || | |
| [self.testType isEqualToString:@"Extra 4"] || | |
| [self.testType isEqualToString:@"Extra 5"] || | |
| [self.testType isEqualToString:@"City Night Driving 10% Glare Off"] || // NEW | |
| [self.testType isEqualToString:@"City Night Driving 25% Glare Off"] || // NEW | |
| [self.testType isEqualToString:@"City Night Driving 100% Glare Off"])) { | |
| UIAlertController *alert = [UIAlertController | |
| alertControllerWithTitle:@"Test Distance" | |
| message:nil | |
| preferredStyle:UIAlertControllerStyleActionSheet]; | |
| UIAlertAction *option = [UIAlertAction | |
| actionWithTitle:@"400cm" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) { | |
| // Only option is 400cm | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *cancel = [UIAlertAction | |
| actionWithTitle:@"Cancel" | |
| style:UIAlertActionStyleCancel | |
| handler:^(UIAlertAction *action) | |
| { | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| }]; | |
| [alert addAction:option]; | |
| if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone ) { | |
| [alert addAction:cancel]; | |
| } | |
| alert.popoverPresentationController.sourceView = [tableView cellForRowAtIndexPath:indexPath]; | |
| alert.popoverPresentationController.sourceRect = [tableView cellForRowAtIndexPath:indexPath].bounds; | |
| dispatch_async(dispatch_get_main_queue(), ^{ | |
| [alert.view layoutIfNeeded]; | |
| [self presentViewController:alert animated:YES completion:nil]; | |
| }); | |
| } | |
| if (indexPath.section == 2){ | |
| UIAlertController *alert= [UIAlertController | |
| alertControllerWithTitle:@"Select Distance" | |
| message:nil | |
| preferredStyle:UIAlertControllerStyleActionSheet]; | |
| UIAlertAction *option1 = [UIAlertAction | |
| actionWithTitle:@"40cm" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testDistance = @"40cm"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option2 = [UIAlertAction | |
| actionWithTitle:@"50cm" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testDistance = @"50cm"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option3 = [UIAlertAction | |
| actionWithTitle:@"67cm" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testDistance = @"67cm"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option4 = [UIAlertAction | |
| actionWithTitle:@"100cm" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testDistance = @"100cm"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option5 = [UIAlertAction | |
| actionWithTitle:@"200cm" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testDistance = @"200cm"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option6 = [UIAlertAction | |
| actionWithTitle:@"400cm" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testDistance = @"400cm"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *cancel = [UIAlertAction | |
| actionWithTitle:@"Cancel" | |
| style:UIAlertActionStyleCancel | |
| handler:^(UIAlertAction *action) | |
| { | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| }]; | |
| UIAlertAction *option7 = [UIAlertAction | |
| actionWithTitle:@"40cm - 100cm" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testDistance = @"40cm - 100cm"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option8 = [UIAlertAction | |
| actionWithTitle:@"40cm - 200cm" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testDistance = @"40cm - 200cm"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option9 = [UIAlertAction | |
| actionWithTitle:@"40cm - 400cm" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testDistance = @"40cm - 400cm"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option10 = [UIAlertAction | |
| actionWithTitle:@"50cm - 100cm" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testDistance = @"50cm - 100cm"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option11 = [UIAlertAction | |
| actionWithTitle:@"50cm - 200cm" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testDistance = @"50cm - 200cm"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option12 = [UIAlertAction | |
| actionWithTitle:@"50cm - 400cm" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testDistance = @"50cm - 400cm"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option13 = [UIAlertAction | |
| actionWithTitle:@"67cm - 100cm" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testDistance = @"67cm - 100cm"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option14 = [UIAlertAction | |
| actionWithTitle:@"67cm - 200cm" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testDistance = @"67cm - 200cm"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option15 = [UIAlertAction | |
| actionWithTitle:@"67cm - 400cm" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testDistance = @"67cm - 400cm"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option16 = [UIAlertAction | |
| actionWithTitle:@"100cm - 200cm" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testDistance = @"100cm - 200cm"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option17 = [UIAlertAction | |
| actionWithTitle:@"100cm - 400cm" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testDistance = @"100cm - 400cm"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option18 = [UIAlertAction | |
| actionWithTitle:@"40cm-67cm-400cm" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testDistance = @"40cm-67cm-400cm"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option19 = [UIAlertAction | |
| actionWithTitle:@"400cm-400cm-400cm" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testDistance = @"400cm-400cm-400cm"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| if ([self.testType isEqualToString:@"VA Alternate Two Landolt"]) { | |
| if ([[UIScreen screens] count] > 1) { | |
| [self iPadShouldNotHaveExternal]; | |
| return; | |
| } else if ([IPADMINIS containsObject:[self platform]]) { | |
| [alert addAction:option7]; | |
| [alert addAction:option8]; | |
| [alert addAction:option9]; | |
| [alert addAction:option10]; | |
| [alert addAction:option11]; | |
| [alert addAction:option12]; | |
| [alert addAction:option13]; | |
| [alert addAction:option14]; | |
| [alert addAction:option15]; | |
| } else if ([IPADAIRS containsObject:[self platform]]) { | |
| [alert addAction:option16]; | |
| [alert addAction:option17]; | |
| } else { | |
| [alert addAction:option7]; | |
| [alert addAction:option8]; | |
| [alert addAction:option9]; | |
| [alert addAction:option10]; | |
| [alert addAction:option11]; | |
| [alert addAction:option12]; | |
| [alert addAction:option13]; | |
| [alert addAction:option14]; | |
| [alert addAction:option15]; | |
| [alert addAction:option16]; | |
| [alert addAction:option17]; | |
| } | |
| } else if ([self.testType isEqualToString:@"VA Alternate Three Landolt"]) { | |
| if ([[UIScreen screens] count] > 1) { | |
| [self iPadShouldNotHaveExternal]; | |
| return; | |
| } else { | |
| [alert addAction:option18]; | |
| [alert addAction:option19]; | |
| } | |
| } else if ([self.testType isEqualToString:@"Reading Test A"] || | |
| [self.testType isEqualToString:@"Reading Test B"] || // Added | |
| [self.testType isEqualToString:@"Reading Test C"]) { | |
| [alert addAction:option1]; | |
| [alert addAction:option2]; | |
| [alert addAction:option3]; | |
| } else { | |
| if ([[UIScreen screens] count] > 1) { | |
| [alert addAction:option5]; | |
| [alert addAction:option6]; | |
| } else if ([IPADMINIS containsObject:[self platform]]) { | |
| [alert addAction:option1]; | |
| [alert addAction:option2]; | |
| [alert addAction:option3]; | |
| } else if ([IPADAIRS containsObject:[self platform]]) { | |
| [alert addAction:option4]; | |
| } else { | |
| [alert addAction:option1]; | |
| [alert addAction:option2]; | |
| [alert addAction:option3]; | |
| [alert addAction:option4]; | |
| [alert addAction:option5]; | |
| [alert addAction:option6]; | |
| } | |
| } | |
| if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone ) { | |
| [alert addAction:cancel]; | |
| } | |
| alert.popoverPresentationController.sourceView = [tableView cellForRowAtIndexPath:indexPath]; | |
| alert.popoverPresentationController.sourceRect = [tableView cellForRowAtIndexPath:indexPath].bounds; | |
| dispatch_async(dispatch_get_main_queue(), ^{ | |
| [alert.view layoutIfNeeded]; | |
| [self presentViewController:alert animated:YES completion:nil]; | |
| }); | |
| } | |
| ///////DISTANCE | |
| ///////CONTRAST | |
| if (indexPath.section == 3 && | |
| ([self.testType isEqualToString:@"Country Driving"] || | |
| [self.testType isEqualToString:@"In Town Driving No Glare"] || | |
| [self.testType isEqualToString:@"In Town Driving Glare 1"] || | |
| [self.testType isEqualToString:@"In Town Driving Glare 2"])) { | |
| UIAlertController *alert = [UIAlertController | |
| alertControllerWithTitle:@"Contrast" | |
| message:nil | |
| preferredStyle:UIAlertControllerStyleActionSheet]; | |
| UIAlertAction *option = [UIAlertAction | |
| actionWithTitle:@"Standard" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) { | |
| self.contrast = @"Standard"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *cancel = [UIAlertAction | |
| actionWithTitle:@"Cancel" | |
| style:UIAlertActionStyleCancel | |
| handler:^(UIAlertAction *action) { | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| }]; | |
| [alert addAction:option]; | |
| if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { | |
| [alert addAction:cancel]; | |
| } | |
| alert.popoverPresentationController.sourceView = [tableView cellForRowAtIndexPath:indexPath]; | |
| alert.popoverPresentationController.sourceRect = [tableView cellForRowAtIndexPath:indexPath].bounds; | |
| dispatch_async(dispatch_get_main_queue(), ^{ | |
| [alert.view layoutIfNeeded]; | |
| [self presentViewController:alert animated:YES completion:nil]; | |
| }); | |
| } | |
| else if (indexPath.section == 3 && | |
| ([self.testType isEqualToString:@"Country Driving"] || | |
| [self.testType isEqualToString:@"In Town Driving Glare 2"] || | |
| [self.testType isEqualToString:@"Extra 3"] || | |
| [self.testType isEqualToString:@"City Night Driving 10% Glare Off"])) { | |
| UIAlertController *alert = [UIAlertController | |
| alertControllerWithTitle:@"Contrast" | |
| message:@"Fixed at 10%" | |
| preferredStyle:UIAlertControllerStyleActionSheet]; | |
| UIAlertAction *option = [UIAlertAction | |
| actionWithTitle:@"10%" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) { | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *cancel = [UIAlertAction | |
| actionWithTitle:@"Cancel" | |
| style:UIAlertActionStyleCancel | |
| handler:^(UIAlertAction *action) { | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| }]; | |
| [alert addAction:option]; | |
| if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { | |
| [alert addAction:cancel]; | |
| } | |
| alert.popoverPresentationController.sourceView = [tableView cellForRowAtIndexPath:indexPath]; | |
| alert.popoverPresentationController.sourceRect = [tableView cellForRowAtIndexPath:indexPath].bounds; | |
| dispatch_async(dispatch_get_main_queue(), ^{ | |
| [alert.view layoutIfNeeded]; | |
| [self presentViewController:alert animated:YES completion:nil]; | |
| }); | |
| } | |
| else if (indexPath.section == 3 && | |
| ([self.testType isEqualToString:@"In Town Driving No Glare"] || | |
| [self.testType isEqualToString:@"Extra 1"] || | |
| [self.testType isEqualToString:@"Extra 4"] || | |
| [self.testType isEqualToString:@"City Night Driving 25% Glare Off"])) { | |
| UIAlertController *alert = [UIAlertController | |
| alertControllerWithTitle:@"Contrast" | |
| message:@"Fixed at 25%" | |
| preferredStyle:UIAlertControllerStyleActionSheet]; | |
| UIAlertAction *option = [UIAlertAction | |
| actionWithTitle:@"25%" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) { | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *cancel = [UIAlertAction | |
| actionWithTitle:@"Cancel" | |
| style:UIAlertActionStyleCancel | |
| handler:^(UIAlertAction *action) { | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| }]; | |
| [alert addAction:option]; | |
| if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { | |
| [alert addAction:cancel]; | |
| } | |
| alert.popoverPresentationController.sourceView = [tableView cellForRowAtIndexPath:indexPath]; | |
| alert.popoverPresentationController.sourceRect = [tableView cellForRowAtIndexPath:indexPath].bounds; | |
| dispatch_async(dispatch_get_main_queue(), ^{ | |
| [alert.view layoutIfNeeded]; | |
| [self presentViewController:alert animated:YES completion:nil]; | |
| }); | |
| } | |
| else if (indexPath.section == 3 && | |
| ([self.testType isEqualToString:@"In Town Driving Glare 1"] || | |
| [self.testType isEqualToString:@"Extra 2"] || | |
| [self.testType isEqualToString:@"Extra 5"] || | |
| [self.testType isEqualToString:@"City Night Driving 100% Glare Off"])) { | |
| UIAlertController *alert = [UIAlertController | |
| alertControllerWithTitle:@"Contrast" | |
| message:@"Fixed at 100%" | |
| preferredStyle:UIAlertControllerStyleActionSheet]; | |
| UIAlertAction *option = [UIAlertAction | |
| actionWithTitle:@"100%" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) { | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *cancel = [UIAlertAction | |
| actionWithTitle:@"Cancel" | |
| style:UIAlertActionStyleCancel | |
| handler:^(UIAlertAction *action) { | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| }]; | |
| [alert addAction:option]; | |
| if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { | |
| [alert addAction:cancel]; | |
| } | |
| alert.popoverPresentationController.sourceView = [tableView cellForRowAtIndexPath:indexPath]; | |
| alert.popoverPresentationController.sourceRect = [tableView cellForRowAtIndexPath:indexPath].bounds; | |
| dispatch_async(dispatch_get_main_queue(), ^{ | |
| [alert.view layoutIfNeeded]; | |
| [self presentViewController:alert animated:YES completion:nil]; | |
| }); | |
| } | |
| ///////CONTRAST | |
| ///////TEST SET | |
| if (indexPath.section == 4 && | |
| ([self.testType isEqualToString:@"Country Driving"] || | |
| [self.testType isEqualToString:@"In Town Driving No Glare"] || | |
| [self.testType isEqualToString:@"In Town Driving Glare 1"] || | |
| [self.testType isEqualToString:@"In Town Driving Glare 2"] || | |
| [self.testType isEqualToString:@"Extra 1"] || | |
| [self.testType isEqualToString:@"Extra 2"] || | |
| [self.testType isEqualToString:@"Extra 3"] || | |
| [self.testType isEqualToString:@"Extra 4"] || | |
| [self.testType isEqualToString:@"Extra 5"] || | |
| [self.testType isEqualToString:@"City Night Driving 10% Glare Off"] || | |
| [self.testType isEqualToString:@"City Night Driving 25% Glare Off"] || | |
| [self.testType isEqualToString:@"City Night Driving 100% Glare Off"])) { | |
| UIAlertController *alert = [UIAlertController | |
| alertControllerWithTitle:@"Select Set" | |
| message:nil | |
| preferredStyle:UIAlertControllerStyleActionSheet]; | |
| UIAlertAction *option1 = [UIAlertAction | |
| actionWithTitle:@"Set 1" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) { | |
| self.testSet = @"Set 1"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option2 = [UIAlertAction | |
| actionWithTitle:@"Set 2" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) { | |
| self.testSet = @"Set 2"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option3 = [UIAlertAction | |
| actionWithTitle:@"Set 3" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) { | |
| self.testSet = @"Set 3"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option4 = [UIAlertAction | |
| actionWithTitle:@"Set 4" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) { | |
| self.testSet = @"Set 4"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option5 = [UIAlertAction | |
| actionWithTitle:@"Set 5" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) { | |
| self.testSet = @"Set 5"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *cancel = [UIAlertAction | |
| actionWithTitle:@"Cancel" | |
| style:UIAlertActionStyleCancel | |
| handler:^(UIAlertAction *action) { | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| }]; | |
| [alert addAction:option1]; | |
| [alert addAction:option2]; | |
| [alert addAction:option3]; | |
| [alert addAction:option4]; | |
| [alert addAction:option5]; | |
| if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { | |
| [alert addAction:cancel]; | |
| } | |
| alert.popoverPresentationController.sourceView = [tableView cellForRowAtIndexPath:indexPath]; | |
| alert.popoverPresentationController.sourceRect = [tableView cellForRowAtIndexPath:indexPath].bounds; | |
| dispatch_async(dispatch_get_main_queue(), ^{ | |
| [alert.view layoutIfNeeded]; | |
| [self presentViewController:alert animated:YES completion:nil]; | |
| }); | |
| } | |
| if (indexPath.section == 4){ | |
| UIAlertController *alert= [UIAlertController | |
| alertControllerWithTitle:@"Select Set" | |
| message:nil | |
| preferredStyle:UIAlertControllerStyleActionSheet]; | |
| UIAlertAction *option1 = [UIAlertAction | |
| actionWithTitle:@"Set 1" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 1"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option2 = [UIAlertAction | |
| actionWithTitle:@"Set 2" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 2"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option3 = [UIAlertAction | |
| actionWithTitle:@"Set 3" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 3"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option4 = [UIAlertAction | |
| actionWithTitle:@"Set 4" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 4"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option5 = [UIAlertAction | |
| actionWithTitle:@"Set 5" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 5"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option6 = [UIAlertAction | |
| actionWithTitle:@"Set 6" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 6"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option7 = [UIAlertAction | |
| actionWithTitle:@"Set 7" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 7"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option8 = [UIAlertAction | |
| actionWithTitle:@"Set 8" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 8"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option9 = [UIAlertAction | |
| actionWithTitle:@"Set 9" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 9"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option10 = [UIAlertAction | |
| actionWithTitle:@"Set 10" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 10"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option11 = [UIAlertAction | |
| actionWithTitle:@"Set 11" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 11"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option12 = [UIAlertAction | |
| actionWithTitle:@"Set 12" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 12"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option13 = [UIAlertAction | |
| actionWithTitle:@"Set 13" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 13"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option14 = [UIAlertAction | |
| actionWithTitle:@"Set 14" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 14"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option15 = [UIAlertAction | |
| actionWithTitle:@"Set 15" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 15"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option16 = [UIAlertAction | |
| actionWithTitle:@"Set 16" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 16"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option17 = [UIAlertAction | |
| actionWithTitle:@"Set 17" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 17"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option18 = [UIAlertAction | |
| actionWithTitle:@"Set 18" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 18"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option19 = [UIAlertAction | |
| actionWithTitle:@"Set 19" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 19"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option20 = [UIAlertAction | |
| actionWithTitle:@"Set 20" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 20"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option211 = [UIAlertAction | |
| actionWithTitle:@"Set 21" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 21"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option222 = [UIAlertAction | |
| actionWithTitle:@"Set 22" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 22"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option233 = [UIAlertAction | |
| actionWithTitle:@"Set 23" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 23"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option244 = [UIAlertAction | |
| actionWithTitle:@"Set 24" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 24"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option255 = [UIAlertAction | |
| actionWithTitle:@"Set 25" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 25"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option266 = [UIAlertAction | |
| actionWithTitle:@"Set 26" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 26"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option27 = [UIAlertAction | |
| actionWithTitle:@"Set 27" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 27"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option28 = [UIAlertAction | |
| actionWithTitle:@"Set 28" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 28"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option29 = [UIAlertAction | |
| actionWithTitle:@"Set 29" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 29"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option30 = [UIAlertAction | |
| actionWithTitle:@"Set 30" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 30"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option31 = [UIAlertAction | |
| actionWithTitle:@"Set 21" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 31"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option32 = [UIAlertAction | |
| actionWithTitle:@"Set 32" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 32"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option33 = [UIAlertAction | |
| actionWithTitle:@"Set 33" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 33"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option34 = [UIAlertAction | |
| actionWithTitle:@"Set 34" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 34"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option35 = [UIAlertAction | |
| actionWithTitle:@"Set 35" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 35"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option36 = [UIAlertAction | |
| actionWithTitle:@"Set 36" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 36"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option37 = [UIAlertAction | |
| actionWithTitle:@"Set 37" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 37"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option38 = [UIAlertAction | |
| actionWithTitle:@"Set 38" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 38"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option39 = [UIAlertAction | |
| actionWithTitle:@"Set 39" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 39"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option40 = [UIAlertAction | |
| actionWithTitle:@"Set 40" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 40"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *cancel = [UIAlertAction | |
| actionWithTitle:@"Cancel" | |
| style:UIAlertActionStyleCancel | |
| handler:^(UIAlertAction *action) | |
| { | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| }]; | |
| UIAlertAction *option21 = [UIAlertAction | |
| actionWithTitle:@"Set 1 OD" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 1 OD"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option22 = [UIAlertAction | |
| actionWithTitle:@"Set 2 OD" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 2 OD"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option23 = [UIAlertAction | |
| actionWithTitle:@"Set 3 OD" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 3 OD"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option24 = [UIAlertAction | |
| actionWithTitle:@"Set 1 OS" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 1 OS"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option25 = [UIAlertAction | |
| actionWithTitle:@"Set 2 OS" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 2 OS"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option26 = [UIAlertAction | |
| actionWithTitle:@"Set 3 OS" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.testSet = @"Set 3 OS"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| if ([self.testType isEqualToString:@"CS Peripheral Shape"] || [self.testType isEqualToString:@"VA Peripheral Timed Shape"]) { | |
| [alert addAction:option21]; | |
| [alert addAction:option22]; | |
| [alert addAction:option23]; | |
| [alert addAction:option24]; | |
| [alert addAction:option25]; | |
| [alert addAction:option26]; | |
| } else { | |
| [alert addAction:option1]; | |
| [alert addAction:option2]; | |
| [alert addAction:option3]; | |
| [alert addAction:option4]; | |
| [alert addAction:option5]; | |
| [alert addAction:option6]; | |
| [alert addAction:option7]; | |
| [alert addAction:option8]; | |
| [alert addAction:option9]; | |
| [alert addAction:option10]; | |
| [alert addAction:option11]; | |
| [alert addAction:option12]; | |
| [alert addAction:option13]; | |
| [alert addAction:option14]; | |
| [alert addAction:option15]; | |
| [alert addAction:option16]; | |
| [alert addAction:option17]; | |
| [alert addAction:option18]; | |
| [alert addAction:option19]; | |
| [alert addAction:option20]; | |
| [alert addAction:option211]; | |
| [alert addAction:option222]; | |
| [alert addAction:option233]; | |
| [alert addAction:option244]; | |
| [alert addAction:option255]; | |
| [alert addAction:option266]; | |
| [alert addAction:option27]; | |
| [alert addAction:option28]; | |
| [alert addAction:option29]; | |
| [alert addAction:option30]; | |
| [alert addAction:option31]; | |
| [alert addAction:option32]; | |
| [alert addAction:option33]; | |
| [alert addAction:option34]; | |
| [alert addAction:option35]; | |
| [alert addAction:option36]; | |
| [alert addAction:option37]; | |
| [alert addAction:option38]; | |
| [alert addAction:option39]; | |
| [alert addAction:option40]; | |
| } | |
| if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone ) { | |
| [alert addAction:cancel]; | |
| } | |
| alert.popoverPresentationController.sourceView = [tableView cellForRowAtIndexPath:indexPath]; | |
| alert.popoverPresentationController.sourceRect = [tableView cellForRowAtIndexPath:indexPath].bounds; | |
| dispatch_async(dispatch_get_main_queue(), ^{ | |
| [alert.view layoutIfNeeded]; | |
| [self presentViewController:alert animated:YES completion:nil]; | |
| }); | |
| } | |
| ///////TEST SET | |
| ///////LETTER SIZE | |
| if (indexPath.section == 5){ | |
| UIAlertController *alert= [UIAlertController | |
| alertControllerWithTitle:@"Select Letter Size" | |
| message:nil | |
| preferredStyle:UIAlertControllerStyleActionSheet]; | |
| UIAlertAction *option1 = [UIAlertAction | |
| actionWithTitle:@"-13" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.letterSize = @"-13"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option2 = [UIAlertAction | |
| actionWithTitle:@"-12" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.letterSize = @"-12"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option3 = [UIAlertAction | |
| actionWithTitle:@"-11" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.letterSize = @"-11"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option4 = [UIAlertAction | |
| actionWithTitle:@"-10" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.letterSize = @"-10"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option5 = [UIAlertAction | |
| actionWithTitle:@"-9" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.letterSize = @"-9"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option6 = [UIAlertAction | |
| actionWithTitle:@"-8" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.letterSize = @"-8"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option7 = [UIAlertAction | |
| actionWithTitle:@"-7" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.letterSize = @"-7"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option8 = [UIAlertAction | |
| actionWithTitle:@"-6" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.letterSize = @"-6"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option9 = [UIAlertAction | |
| actionWithTitle:@"-5" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.letterSize = @"-5"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option10 = [UIAlertAction | |
| actionWithTitle:@"-4" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.letterSize = @"-4"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option11 = [UIAlertAction | |
| actionWithTitle:@"-3" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.letterSize = @"-3"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option12 = [UIAlertAction | |
| actionWithTitle:@"-2" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.letterSize = @"-2"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option13 = [UIAlertAction | |
| actionWithTitle:@"-1" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.letterSize = @"-1"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option14 = [UIAlertAction | |
| actionWithTitle:@"0" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.letterSize = @"0"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option15 = [UIAlertAction | |
| actionWithTitle:@"+1" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.letterSize = @"+1"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option16 = [UIAlertAction | |
| actionWithTitle:@"+2" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.letterSize = @"+2"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option17 = [UIAlertAction | |
| actionWithTitle:@"+3" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) | |
| { | |
| self.letterSize = @"+3"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *cancel = [UIAlertAction | |
| actionWithTitle:@"Cancel" | |
| style:UIAlertActionStyleCancel | |
| handler:^(UIAlertAction *action) | |
| { | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| }]; | |
| [alert addAction:option1]; | |
| [alert addAction:option2]; | |
| [alert addAction:option3]; | |
| [alert addAction:option4]; | |
| [alert addAction:option5]; | |
| [alert addAction:option6]; | |
| [alert addAction:option7]; | |
| [alert addAction:option8]; | |
| [alert addAction:option9]; | |
| [alert addAction:option10]; | |
| [alert addAction:option11]; | |
| [alert addAction:option12]; | |
| [alert addAction:option13]; | |
| [alert addAction:option14]; | |
| [alert addAction:option15]; | |
| [alert addAction:option16]; | |
| [alert addAction:option17]; | |
| if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone ) { | |
| [alert addAction:cancel]; | |
| } | |
| alert.popoverPresentationController.sourceView = [tableView cellForRowAtIndexPath:indexPath]; | |
| alert.popoverPresentationController.sourceRect = [tableView cellForRowAtIndexPath:indexPath].bounds; | |
| dispatch_async(dispatch_get_main_queue(), ^{ | |
| [alert.view layoutIfNeeded]; | |
| [self presentViewController:alert animated:YES completion:nil]; | |
| }); | |
| } | |
| ///////LETTER SIZE | |
| ///////EXPOSURE AND Inter Optotype | |
| if (indexPath.section == 6 && | |
| ([self.testType isEqualToString:@"Country Driving"] || | |
| [self.testType isEqualToString:@"In Town Driving No Glare"] || | |
| [self.testType isEqualToString:@"In Town Driving Glare 1"] || | |
| [self.testType isEqualToString:@"In Town Driving Glare 2"])) { | |
| UIAlertController *alert = [UIAlertController | |
| alertControllerWithTitle:@"Inter Optotype Time" | |
| message:nil | |
| preferredStyle:UIAlertControllerStyleActionSheet]; | |
| UIAlertAction *option = [UIAlertAction | |
| actionWithTitle:@"1000ms" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) { | |
| self.dynamicTime = @"1000ms"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *cancel = [UIAlertAction | |
| actionWithTitle:@"Cancel" | |
| style:UIAlertActionStyleCancel | |
| handler:^(UIAlertAction *action) { | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| }]; | |
| [alert addAction:option]; | |
| if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { | |
| [alert addAction:cancel]; | |
| } | |
| alert.popoverPresentationController.sourceView = [tableView cellForRowAtIndexPath:indexPath]; | |
| alert.popoverPresentationController.sourceRect = [tableView cellForRowAtIndexPath:indexPath].bounds; | |
| dispatch_async(dispatch_get_main_queue(), ^{ | |
| [alert.view layoutIfNeeded]; | |
| [self presentViewController:alert animated:YES completion:nil]; | |
| }); | |
| } | |
| else if (indexPath.section == 6 && | |
| ([self.testType isEqualToString:@"Country Driving"] || | |
| [self.testType isEqualToString:@"In Town Driving No Glare"] || | |
| [self.testType isEqualToString:@"In Town Driving Glare 1"] || | |
| [self.testType isEqualToString:@"In Town Driving Glare 2"] || | |
| [self.testType isEqualToString:@"Extra 1"] || | |
| [self.testType isEqualToString:@"Extra 2"] || | |
| [self.testType isEqualToString:@"Extra 3"] || | |
| [self.testType isEqualToString:@"Extra 4"] || | |
| [self.testType isEqualToString:@"Extra 5"] || | |
| [self.testType isEqualToString:@"City Night Driving 10% Glare Off"] || | |
| [self.testType isEqualToString:@"City Night Driving 25% Glare Off"] || | |
| [self.testType isEqualToString:@"City Night Driving 100% Glare Off"])) { | |
| UIAlertController *alert = [UIAlertController | |
| alertControllerWithTitle:@"Select Inter Optotype Time" | |
| message:nil | |
| preferredStyle:UIAlertControllerStyleActionSheet]; | |
| UIAlertAction *option1 = [UIAlertAction | |
| actionWithTitle:@"500ms" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) { | |
| self.dynamicTime = @"500ms"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option2 = [UIAlertAction | |
| actionWithTitle:@"1000ms" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) { | |
| self.dynamicTime = @"1000ms"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *cancel = [UIAlertAction | |
| actionWithTitle:@"Cancel" | |
| style:UIAlertActionStyleCancel | |
| handler:^(UIAlertAction *action) { | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| }]; | |
| [alert addAction:option1]; | |
| [alert addAction:option2]; | |
| if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { | |
| [alert addAction:cancel]; | |
| } | |
| alert.popoverPresentationController.sourceView = [tableView cellForRowAtIndexPath:indexPath]; | |
| alert.popoverPresentationController.sourceRect = [tableView cellForRowAtIndexPath:indexPath].bounds; | |
| dispatch_async(dispatch_get_main_queue(), ^{ | |
| [alert.view layoutIfNeeded]; | |
| [self presentViewController:alert animated:YES completion:nil]; | |
| }); | |
| } | |
| if (indexPath.section == 6) { | |
| UIAlertController *alert = [UIAlertController | |
| alertControllerWithTitle:@"Select Exposure" | |
| message:nil | |
| preferredStyle:UIAlertControllerStyleActionSheet]; | |
| UIAlertAction *option1 = [UIAlertAction | |
| actionWithTitle:@"360ms" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) { | |
| self.dynamicTime = @"360ms"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *option2 = [UIAlertAction | |
| actionWithTitle:@"390ms" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction *action) { | |
| self.dynamicTime = @"390ms"; | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| [self.tableView reloadData]; | |
| }]; | |
| UIAlertAction *cancel = [UIAlertAction | |
| actionWithTitle:@"Cancel" | |
| style:UIAlertActionStyleCancel | |
| handler:^(UIAlertAction *action) { | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| }]; | |
| [alert addAction:option1]; | |
| [alert addAction:option2]; | |
| if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { | |
| [alert addAction:cancel]; | |
| } | |
| alert.popoverPresentationController.sourceView = [tableView cellForRowAtIndexPath:indexPath]; | |
| alert.popoverPresentationController.sourceRect = [tableView cellForRowAtIndexPath:indexPath].bounds; | |
| dispatch_async(dispatch_get_main_queue(), ^{ | |
| [alert.view layoutIfNeeded]; | |
| [self presentViewController:alert animated:YES completion:nil]; | |
| }); | |
| } | |
| ///////EXPOSURE | |
| } | |
| -(void)beginTest{ | |
| self.fileName = [[NSString alloc]init]; | |
| NSString *filePath = [[NSString alloc]init]; | |
| NSString *fileNameContrast = [[NSString alloc]init]; | |
| fileNameContrast = self.contrast; | |
| if ([fileNameContrast isEqualToString:@"High"]){ | |
| fileNameContrast = @"H"; | |
| } else if ([fileNameContrast isEqualToString:@"Low"]){ | |
| fileNameContrast = @"L"; | |
| } | |
| // Handle the new driving test types | |
| if ([self.testType isEqualToString:@"Country Driving"] || | |
| [self.testType isEqualToString:@"In Town Driving No Glare"] || | |
| [self.testType isEqualToString:@"In Town Driving Glare 1"] || | |
| [self.testType isEqualToString:@"In Town Driving Glare 2"]) { | |
| NSString *timeString = [self.dynamicTime stringByReplacingOccurrencesOfString:@"ms" withString:@""]; | |
| filePath = [NSString stringWithFormat:@"%@ %@ %@ %@ %@ms %@", | |
| self.testDistance, | |
| self.contrast, | |
| self.letterSize, | |
| self.testType, | |
| timeString, | |
| self.testSet]; | |
| } else if ([self.testType isEqualToString:@"Extra 1"] || | |
| [self.testType isEqualToString:@"Extra 2"] || | |
| [self.testType isEqualToString:@"Extra 3"] || | |
| [self.testType isEqualToString:@"Extra 4"] || | |
| [self.testType isEqualToString:@"Extra 5"]) { | |
| NSString *timeString = [self.dynamicTime stringByReplacingOccurrencesOfString:@"ms" withString:@""]; | |
| if ([self.testType isEqualToString:@"Extra 1"] || [self.testType isEqualToString:@"Extra 4"]) { | |
| filePath = [NSString stringWithFormat:@"%@ %@ %@ Narrow Glare %@ms %@", | |
| self.testDistance, | |
| self.contrast, | |
| self.letterSize, | |
| timeString, | |
| self.testSet]; | |
| } else if ([self.testType isEqualToString:@"Extra 2"] || [self.testType isEqualToString:@"Extra 5"]) { | |
| filePath = [NSString stringWithFormat:@"%@ %@ %@ Wide Glare %@ms %@", | |
| self.testDistance, | |
| self.contrast, | |
| self.letterSize, | |
| timeString, | |
| self.testSet]; | |
| } else if ([self.testType isEqualToString:@"Extra 3"]) { | |
| filePath = [NSString stringWithFormat:@"%@ %@ %@ Wide Glare %@ms %@", | |
| self.testDistance, | |
| self.contrast, | |
| self.letterSize, | |
| timeString, | |
| self.testSet]; | |
| } | |
| } else if ([self.testType isEqualToString:@"City Night Driving 10% Glare Off"] || | |
| [self.testType isEqualToString:@"City Night Driving 25% Glare Off"] || | |
| [self.testType isEqualToString:@"City Night Driving 100% Glare Off"]) { | |
| NSString *timeString = [self.dynamicTime stringByReplacingOccurrencesOfString:@"ms" withString:@""]; | |
| filePath = [NSString stringWithFormat:@"%@ %@ +1 Glare Off %@ms %@", | |
| self.testDistance, | |
| self.contrast, | |
| timeString, | |
| self.testSet]; | |
| } else if ([self.testType isEqualToString:@"VA Paracentral Timed Landolt"] || | |
| [self.testType isEqualToString:@"VA Alternate Two Landolt"] || | |
| [self.testType isEqualToString:@"CS Timed Landolt"]){ | |
| self.exposureOdd = 300; | |
| filePath = [NSString stringWithFormat:@"%@ %@ %@ %@",self.testDistance, fileNameContrast, self.letterSize, self.testSet]; | |
| } else if ([self.testType isEqualToString:@"VA Peripheral Timed Shape"]){ | |
| if ([self.dynamicTime isEqualToString:@"360ms"]){ | |
| self.exposureOdd = 360; | |
| } else if ([self.dynamicTime isEqualToString:@"390ms"]){ | |
| self.exposureOdd = 390; | |
| } | |
| filePath = [NSString stringWithFormat:@"%@ %@ %@ %@",self.testDistance, fileNameContrast, self.letterSize, self.testSet]; | |
| } else if ([self.testType isEqualToString:@"CS Peripheral Shape"]){ | |
| self.exposureOdd = 390; | |
| filePath = [NSString stringWithFormat:@"%@ %@ %@",self.testDistance, fileNameContrast, self.testSet]; | |
| } else if ([self.testType isEqualToString:@"Reading Test A"] || | |
| [self.testType isEqualToString:@"Reading Test B"] || | |
| [self.testType isEqualToString:@"Reading Test C"] || | |
| [self.testType isEqualToString:@"VA Timed Letter"]) { | |
| filePath = [NSString stringWithFormat:@"%@ %@ %@",self.testDistance, fileNameContrast, self.testSet]; | |
| } | |
| // TESTING - Override for development | |
| if (useTestSet == true){ | |
| filePath = @"400cm 60% +10 Set 1"; | |
| } | |
| self.fileName = filePath; | |
| if ([self.testType isEqualToString:@"VA Alternate Two Landolt"]){ | |
| [self dynamicAlternateSlideshowiPads]; | |
| } | |
| self.hud = [MBProgressHUD showHUDAddedTo:self.view.window animated:YES]; | |
| self.hud.labelText = @"0%"; | |
| filePath = [[NSBundle mainBundle] pathForResource:filePath ofType:@"pdf"]; | |
| NSLog(@"Path to load PDF: %@.pdf", filePath); | |
| NSLog(@"Attempting to load PDF: %@.pdf", self.fileName); | |
| if (filePath == nil) { | |
| [MBProgressHUD hideHUDForView:self.view.window animated:YES]; | |
| UIAlertController * alert= [UIAlertController | |
| alertControllerWithTitle:@"Selection Error" | |
| message:[NSString stringWithFormat:@"Selection error for current device.\n\nError Code: %@\n\nPlease review.", self.fileName] | |
| preferredStyle:UIAlertControllerStyleAlert]; | |
| UIAlertAction* cancel = [UIAlertAction | |
| actionWithTitle:@"OK" | |
| style:UIAlertActionStyleCancel | |
| handler:^(UIAlertAction * action) | |
| { | |
| }]; | |
| [alert addAction:cancel]; | |
| [alert.view layoutIfNeeded]; | |
| [self presentViewController:alert animated:YES completion:nil]; | |
| } else { | |
| NSURL *pdfUrl = [NSURL fileURLWithPath:filePath]; | |
| CGPDFDocumentRef document = CGPDFDocumentCreateWithURL((CFURLRef)pdfUrl); | |
| int pageCount = (int)CGPDFDocumentGetNumberOfPages(document); | |
| if (pageCount <= 0) { | |
| UIAlertController * alert= [UIAlertController | |
| alertControllerWithTitle:@"PDF Read Error" | |
| message:@"Document says it has 0 pages" | |
| preferredStyle:UIAlertControllerStyleAlert]; | |
| UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:nil]; | |
| [alert addAction:cancel]; | |
| [self presentViewController:alert animated:YES completion:nil]; | |
| [MBProgressHUD hideHUDForView:self.view.window animated:YES]; | |
| return; | |
| } | |
| self.totalPages = pageCount - 1; | |
| self.testSlides = [NSMutableArray array]; | |
| for (int i = 1; i < pageCount + 1; i++) { | |
| UIImage *testSlide = [UIImage originalSizeImageWithPDFNamed:[NSString stringWithFormat:@"%@.pdf", self.fileName] atPage:i]; | |
| if (testSlide == nil) { | |
| UIAlertController * alert= [UIAlertController | |
| alertControllerWithTitle:@"PDF Parse Error" | |
| message:[NSString stringWithFormat:@"Error parsing page %d.\nDocument should have %d pages in total.", i, pageCount] | |
| preferredStyle:UIAlertControllerStyleAlert]; | |
| UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:nil]; | |
| [alert addAction:cancel]; | |
| [self presentViewController:alert animated:YES completion:nil]; | |
| [MBProgressHUD hideHUDForView:self.view.window animated:YES]; | |
| return; | |
| } | |
| [self.testSlides addObject:UIImagePNGRepresentation(testSlide)]; | |
| double percentageLoaded = (double)i/(double)pageCount * 100.00; | |
| self.hud.labelText = [NSString stringWithFormat:@"%i%%", (int)percentageLoaded]; | |
| } | |
| [MBProgressHUD hideHUDForView:self.view.window animated:YES]; | |
| if ([[UIScreen screens] count] > 1) { | |
| [self externalScreenMountedGo]; | |
| } | |
| if ([self.testType isEqualToString:@"Reading Test A"] || | |
| [self.testType isEqualToString:@"Reading Test B"] || | |
| [self.testType isEqualToString:@"Reading Test C"]) { | |
| [self staticNYT]; | |
| } else if ([self.testType isEqualToString:@"VA Timed Letter"]) { | |
| [self staticTimedOpen]; | |
| } else if ([self.testType isEqualToString:@"VA Alternate Two Landolt"]) { | |
| [self dynamicAlternateSlideshow]; | |
| } else { | |
| [self dynamicSlideshow]; | |
| } | |
| } | |
| } | |
| - (void)staticNYT { | |
| TestViewController *testView = [[TestViewController alloc]init]; | |
| testView.totalPages = self.totalPages; | |
| testView.testSlides = [self.testSlides copy]; | |
| testView.view.backgroundColor = [self testSpecificBackgroundColor]; | |
| testView.modalPresentationStyle = UIModalPresentationFullScreen; | |
| [self presentViewController:testView animated:true completion:nil]; | |
| } | |
| - (void)staticTimedOpen { | |
| StaticTimedViewController *testView = [[StaticTimedViewController alloc]init]; | |
| testView.totalPages = self.totalPages; | |
| testView.testSlides = [self.testSlides copy]; | |
| testView.view.backgroundColor = [self testSpecificBackgroundColor]; | |
| testView.modalPresentationStyle = UIModalPresentationFullScreen; | |
| [self presentViewController:testView animated:true completion:nil]; | |
| } | |
| -(void)dynamicSlideshow { | |
| DynamicTestViewController *testView = [[DynamicTestViewController alloc]init]; | |
| testView.delayMS = self.exposureOdd; | |
| testView.totalPages = self.totalPages; | |
| testView.testSlides = [self.testSlides copy]; | |
| testView.testType = self.testType; | |
| NSString *timeString = [self.dynamicTime stringByReplacingOccurrencesOfString:@"ms" withString:@""]; | |
| testView.interOptotypeMS = [timeString integerValue]; | |
| testView.view.backgroundColor = [self testSpecificBackgroundColor]; | |
| testView.modalPresentationStyle = UIModalPresentationFullScreen; | |
| [self presentViewController:testView animated:true completion:nil]; | |
| } | |
| -(void)dynamicAlternateSlideshow { | |
| self.testViewController = [[DynamicAlternateViewController alloc]init]; | |
| self.testViewController.totalPages = self.totalPages; | |
| self.testViewController.testSlides = [self.testSlides copy]; | |
| self.testViewController.testType = self.testType; | |
| self.testViewController.peripheralManager = self.peripheralManager; | |
| self.testViewController.centralManager = self.centralManager; | |
| self.testViewController.transferMutableCharacteristic = self.transferCharacteristic; | |
| self.testViewController.alternateSmall = true; | |
| self.testViewController.view.backgroundColor = [self testSpecificBackgroundColor]; | |
| self.testViewController.modalPresentationStyle = UIModalPresentationFullScreen; | |
| [self presentViewController:self.testViewController animated:true completion:nil]; | |
| } | |
| -(void)dynamicAlternateSlideshowiPads { | |
| //Check Bluetooth is on | |
| [self.centralManager stopScan]; | |
| self.peripheralManager = [[CBPeripheralManager alloc] initWithDelegate:self queue:nil]; | |
| [self performSelector:@selector(startBroadcasting) withObject:nil afterDelay:0.7]; | |
| } | |
| -(UIColor*)testSpecificBackgroundColor { | |
| return [UIColor darkGrayColor]; | |
| } | |
| - (void)startBroadcasting{ | |
| if (self.peripheralManager.state == CBManagerStatePoweredOn) { | |
| [self.peripheralManager startAdvertising:@{ CBAdvertisementDataServiceUUIDsKey : @[[CBUUID UUIDWithString:TRANSFER_DISCOVERY_UUID]] }]; | |
| self.transferCharacteristic = [[CBMutableCharacteristic alloc] initWithType:[CBUUID UUIDWithString:TRANSFER_CHARACTER_UUID] properties:CBCharacteristicPropertyNotify | CBCharacteristicPropertyWrite value:nil permissions:CBAttributePermissionsReadable | CBAttributePermissionsWriteable]; | |
| CBMutableService *transferService = [[CBMutableService alloc] initWithType:[CBUUID UUIDWithString:TRANSFER_DISCOVERY_UUID] primary:YES]; | |
| transferService.characteristics = @[_transferCharacteristic]; | |
| [_peripheralManager addService:transferService]; | |
| [self performSelector:@selector(tooLateNoConnection) withObject:nil afterDelay:5.0]; | |
| } | |
| if (self.peripheralManager.state == CBManagerStatePoweredOff) { | |
| if (self.testViewController){ | |
| [self.testViewController dismissViewControllerAnimated:true completion:nil]; | |
| } | |
| } | |
| } | |
| ////////CENTRAL///////////////////////////////////////////////////////////////////////// | |
| - (void)scanForBluetoothSignal{ | |
| self.discoveredPeripheral = nil; | |
| self.peripheralManager = nil; | |
| self.centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil]; | |
| self.bluetoothData = [[NSMutableData alloc] init]; | |
| [self performSelector:@selector(startScanning) withObject:nil afterDelay:0.7]; | |
| } | |
| -(void)startScanning{ | |
| if (self.centralManager.state == CBManagerStatePoweredOn){ | |
| [self.centralManager scanForPeripheralsWithServices:@[[CBUUID UUIDWithString:TRANSFER_DISCOVERY_UUID]] options:@{ CBCentralManagerScanOptionAllowDuplicatesKey : @YES }]; | |
| // Scan for devices | |
| NSLog(@"Scanning started"); | |
| self.receivingAlert = [UIAlertController | |
| alertControllerWithTitle:@"Bluetooth Active" | |
| message:@"Ready to Receive" | |
| preferredStyle:UIAlertControllerStyleAlert]; | |
| UIAlertAction* cancelButton = [UIAlertAction | |
| actionWithTitle:@"Cancel" | |
| style:UIAlertActionStyleCancel | |
| handler:^(UIAlertAction * action) { | |
| if (self.centralManager){ | |
| [self.centralManager stopScan]; | |
| } | |
| }]; | |
| [self.receivingAlert addAction:cancelButton]; | |
| [self.receivingAlert.view layoutIfNeeded]; | |
| [self presentViewController:self.receivingAlert animated:YES completion:nil]; | |
| } | |
| } | |
| - (void)centralManagerDidUpdateState:(CBCentralManager *)central | |
| { | |
| // NSString *stateString = nil; | |
| // switch(self.centralManager.state) | |
| // { | |
| // case CBCentralManagerStateResetting: stateString = @"The connection with the system service was momentarily lost, update imminent."; break; | |
| // case CBCentralManagerStateUnsupported: stateString = @"The platform doesn't support Bluetooth Low Energy."; break; | |
| // case CBCentralManagerStateUnauthorized: stateString = @"The app is not authorized to use Bluetooth Low Energy."; break; | |
| // case CBCentralManagerStatePoweredOff: stateString = @"Bluetooth is currently powered off."; break; | |
| // case CBCentralManagerStatePoweredOn: stateString = @"Bluetooth is currently powered on and available to use."; break; | |
| // default: stateString = @"State unknown, update imminent."; break; | |
| // } | |
| // NSLog(@"%@", stateString); | |
| } | |
| -(void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary<NSString *,id> *)advertisementData RSSI:(NSNumber *)RSSI{ | |
| //NSLog(@"Discovered %@ at %@", peripheral.name, RSSI); | |
| if (self.discoveredPeripheral != peripheral) { | |
| // Save a local copy of the peripheral, so CoreBluetooth doesn't get rid of it | |
| self.discoveredPeripheral = peripheral; | |
| // And connect | |
| NSLog(@"Connecting to peripheral %@", peripheral); | |
| [self.centralManager connectPeripheral:peripheral options:nil]; | |
| } | |
| } | |
| - (void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error { | |
| NSLog(@"Failed to connect"); | |
| [self cleanup]; | |
| } | |
| - (void)cleanup { | |
| NSLog(@"Clean Up"); | |
| // See if we are subscribed to a characteristic on the peripheral | |
| if (_discoveredPeripheral.services != nil) { | |
| for (CBService *service in _discoveredPeripheral.services) { | |
| if (service.characteristics != nil) { | |
| for (CBCharacteristic *characteristic in service.characteristics) { | |
| if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:TRANSFER_CHARACTER_UUID]]) { | |
| if (characteristic.isNotifying) { | |
| [_discoveredPeripheral setNotifyValue:NO forCharacteristic:characteristic]; | |
| return; | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| if (self.centralManager && self.discoveredPeripheral) { | |
| [self.centralManager cancelPeripheralConnection:self.discoveredPeripheral]; | |
| } | |
| } | |
| - (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral { | |
| NSLog(@"Connected"); | |
| [_centralManager stopScan]; | |
| NSLog(@"Scanning stopped"); | |
| [self.bluetoothData setLength:0]; | |
| peripheral.delegate = self; | |
| [peripheral discoverServices:@[[CBUUID UUIDWithString:TRANSFER_DISCOVERY_UUID]]]; | |
| } | |
| - (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error { | |
| if (error) { | |
| [self cleanup]; | |
| return; | |
| } | |
| for (CBService *service in peripheral.services) { | |
| [peripheral discoverCharacteristics:@[[CBUUID UUIDWithString:TRANSFER_CHARACTER_UUID]] forService:service]; | |
| } | |
| // Discover other characteristics | |
| } | |
| -(void)peripheral:(CBPeripheral *)peripheral didModifyServices:(NSArray<CBService *> *)invalidatedServices{ | |
| NSLog(@"Modified Services"); | |
| } | |
| - (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error { | |
| if (error) { | |
| [self cleanup]; | |
| return; | |
| } | |
| for (CBCharacteristic *characteristic in service.characteristics) { | |
| if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:TRANSFER_CHARACTER_UUID]]) { | |
| [peripheral setNotifyValue:YES forCharacteristic:characteristic]; | |
| } | |
| } | |
| } | |
| - (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error { | |
| if (error) { | |
| NSLog(@"Error didUpdateValueForCharacteristic"); | |
| NSLog(@"%@", error); | |
| return; | |
| } | |
| if (self.receivingAlert) { | |
| [self.receivingAlert dismissViewControllerAnimated:true completion:nil]; | |
| } | |
| NSString *stringFromData = [[NSString alloc] initWithData:characteristic.value encoding:NSUTF8StringEncoding]; | |
| if ([stringFromData isEqualToString:@"PeriSaysClose"]) { | |
| [[NSNotificationCenter defaultCenter] postNotificationName:@"closeTestBT" object:self]; | |
| [peripheral setNotifyValue:NO forCharacteristic:characteristic]; | |
| } | |
| if ([stringFromData isEqualToString:@"PeriSaysNext"]) { | |
| [[NSNotificationCenter defaultCenter] postNotificationName:@"bigButtonBT" object:self]; | |
| } | |
| if ([stringFromData isEqualToString:@"testCompleteBT"]) { | |
| [[NSNotificationCenter defaultCenter] postNotificationName:@"testCompleteBT" object:self]; | |
| } | |
| // Have we got everything we need? | |
| if ([stringFromData isEqualToString:@"EOM"]) { | |
| [self.centralManager stopScan]; | |
| NSString *receivedString = [[NSString alloc] initWithData:self.bluetoothData encoding:NSUTF8StringEncoding]; | |
| ///////////////////////////////////////LOAD SLIDES AND NOTIFY PERIPHERAL | |
| self.hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; | |
| self.hud.labelText = @"0%"; | |
| NSString *filePath = [[NSString alloc]init]; | |
| self.fileName = receivedString; | |
| filePath = [[NSBundle mainBundle] pathForResource:self.fileName ofType:@"pdf"]; | |
| if (filePath == nil) { | |
| [MBProgressHUD hideHUDForView:self.view animated:YES]; | |
| UIAlertController * alert= [UIAlertController | |
| alertControllerWithTitle:@"Selection Error" | |
| //message:@"Selection error for current device\n\nPlease review" | |
| message:[NSString stringWithFormat:@"Selection error for current device.\n\nError Code: %@\n\nPlease review.", self.fileName] | |
| preferredStyle:UIAlertControllerStyleAlert]; | |
| UIAlertAction* cancel = [UIAlertAction | |
| actionWithTitle:@"OK" | |
| style:UIAlertActionStyleCancel | |
| handler:^(UIAlertAction * action) | |
| { | |
| }]; | |
| [alert addAction:cancel]; | |
| [alert.view layoutIfNeeded]; | |
| [self presentViewController:alert animated:YES completion:nil]; | |
| } else { | |
| dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0ul); | |
| dispatch_async(queue, ^{ | |
| NSURL *pdfUrl = [NSURL fileURLWithPath:filePath]; | |
| CGPDFDocumentRef document = CGPDFDocumentCreateWithURL((CFURLRef)pdfUrl); | |
| int pageCount = (int)CGPDFDocumentGetNumberOfPages(document); | |
| self.totalPages = pageCount - 1; | |
| self.testSlides = [NSMutableArray array]; | |
| int i = 1; | |
| for (i = 1; i < pageCount + 1; i++) { | |
| UIImage *testSlide = [UIImage originalSizeImageWithPDFNamed:[NSString stringWithFormat:@"%@.pdf", self.fileName] atPage:i]; | |
| [self.testSlides addObject:UIImagePNGRepresentation(testSlide)]; | |
| double percentageLoaded = (double)i/(double)pageCount * 100.00; | |
| self.hud.labelText = [NSString stringWithFormat:@"%i%%", (int)percentageLoaded]; | |
| } | |
| dispatch_sync(dispatch_get_main_queue(), ^{ | |
| [MBProgressHUD hideHUDForView:self.view.window animated:YES]; | |
| [peripheral writeValue: [@"Confirm Received" dataUsingEncoding:NSUTF8StringEncoding] | |
| forCharacteristic:characteristic | |
| type:CBCharacteristicWriteWithResponse]; | |
| if ([[UIScreen screens] count] > 1) { | |
| [self externalScreenMountedGo]; | |
| } | |
| DynamicAlternateViewController *testView = [[DynamicAlternateViewController alloc]init]; | |
| testView.totalPages = self.totalPages; | |
| testView.testSlides = [self.testSlides copy]; | |
| testView.testType = self.testType; | |
| testView.discoveredPeripheral = peripheral; | |
| testView.transferCharacteristic = characteristic; | |
| testView.peripheralManager = self.peripheralManager; | |
| testView.centralManager = self.centralManager; | |
| testView.transferMutableCharacteristic = self.transferCharacteristic; | |
| testView.alternateSmall = false; | |
| testView.modalPresentationStyle = UIModalPresentationFullScreen; | |
| [self presentViewController:testView animated:true completion:nil]; | |
| }); | |
| }); | |
| } | |
| ///////////////////////////////////////LOAD SLIDES AND NOTIFY PERIPHERAL | |
| } | |
| [self.bluetoothData appendData:characteristic.value]; | |
| } | |
| - (void)peripheral:(CBPeripheral *)peripheral didUpdateNotificationStateForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error { | |
| if (![characteristic.UUID isEqual:[CBUUID UUIDWithString:TRANSFER_CHARACTER_UUID]]) { | |
| return; | |
| } | |
| if (characteristic.isNotifying) { | |
| NSLog(@"Notification began on %@", characteristic); | |
| } else { | |
| // Notification has stopped | |
| } | |
| } | |
| - (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error { | |
| _discoveredPeripheral = nil; | |
| NSLog(@"Did Disconnect"); | |
| } | |
| ////////PERIPHERAL///////////////////////////////////////////////////////////////////////// | |
| - (void)peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheral { | |
| if (peripheral.state != CBManagerStatePoweredOn) { | |
| return; | |
| } | |
| } | |
| - (void)tooLateNoConnection { | |
| [MBProgressHUD hideHUDForView:self.view.window animated:YES]; | |
| [self.peripheralManager stopAdvertising]; | |
| // UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Connection" | |
| // message:@"Please ensure receiving mode is activiated on the other iPad before broadcasting from this device.\n\nPlease ensure Bluetooth is turned on for both iPads" | |
| // delegate:nil | |
| // cancelButtonTitle:@"OK" otherButtonTitles: nil]; | |
| // | |
| // if (self.testViewController){ | |
| // [self.testViewController dismissViewControllerAnimated:true completion:nil]; | |
| // } | |
| // | |
| // [alert show]; | |
| UIAlertController * alert = [UIAlertController | |
| alertControllerWithTitle:@"No Connection" | |
| message:@"Please ensure receiving mode is activiated on the other iPad before broadcasting from this device.\n\nPlease ensure Bluetooth is turned on for both iPads" | |
| preferredStyle:UIAlertControllerStyleAlert]; | |
| UIAlertAction* yesButton = [UIAlertAction | |
| actionWithTitle:@"OK" | |
| style:UIAlertActionStyleDefault | |
| handler:^(UIAlertAction * action) { | |
| //Handle your yes please button action here | |
| if (self.testViewController){ | |
| [self.testViewController dismissViewControllerAnimated:true completion:nil]; | |
| } | |
| }]; | |
| [alert addAction:yesButton]; | |
| [self presentViewController:alert animated:YES completion:nil]; | |
| } | |
| - (void)peripheralManager:(CBPeripheralManager *)peripheral central:(CBCentral *)central didSubscribeToCharacteristic:(CBCharacteristic *)characteristic { | |
| [NSObject cancelPreviousPerformRequestsWithTarget: self selector:@selector(tooLateNoConnection) object:nil]; | |
| [self.peripheralManager stopAdvertising]; | |
| self.dataToSend = [self.fileName dataUsingEncoding:NSUTF8StringEncoding]; | |
| self.sendDataIndex = 0; | |
| [self sendData]; | |
| } | |
| - (void)sendData { | |
| static BOOL sendingEOM = NO; | |
| // end of message? | |
| if (sendingEOM) { | |
| BOOL didSend = [self.peripheralManager updateValue:[@"EOM" dataUsingEncoding:NSUTF8StringEncoding] forCharacteristic:self.transferCharacteristic onSubscribedCentrals:nil]; | |
| if (didSend) { | |
| // It did, so mark it as sent | |
| sendingEOM = NO; | |
| } | |
| // didn't send, so we'll exit and wait for peripheralManagerIsReadyToUpdateSubscribers to call sendData again | |
| return; | |
| } | |
| // We're sending data | |
| // Is there any left to send? | |
| if (self.sendDataIndex >= self.dataToSend.length) { | |
| // No data left. Do nothing | |
| return; | |
| } | |
| // There's data left, so send until the callback fails, or we're done. | |
| BOOL didSend = YES; | |
| while (didSend) { | |
| // Work out how big it should be | |
| NSInteger amountToSend = self.dataToSend.length - self.sendDataIndex; | |
| // Can't be longer than 20 bytes | |
| if (amountToSend > NOTIFY_MTU) amountToSend = NOTIFY_MTU; | |
| // Copy out the data we want | |
| NSData *chunk = [NSData dataWithBytes:self.dataToSend.bytes+self.sendDataIndex length:amountToSend]; | |
| didSend = [self.peripheralManager updateValue:chunk forCharacteristic:self.transferCharacteristic onSubscribedCentrals:nil]; | |
| // If it didn't work, drop out and wait for the callback | |
| if (!didSend) { | |
| return; | |
| } | |
| NSString *stringFromData = [[NSString alloc] initWithData:chunk encoding:NSUTF8StringEncoding]; | |
| NSLog(@"Sent: %@", stringFromData); | |
| // It did send, so update our index | |
| self.sendDataIndex += amountToSend; | |
| // Was it the last one? | |
| if (self.sendDataIndex >= self.dataToSend.length) { | |
| // Set this so if the send fails, we'll send it next time | |
| sendingEOM = YES; | |
| BOOL eomSent = [self.peripheralManager updateValue:[@"EOM" dataUsingEncoding:NSUTF8StringEncoding] forCharacteristic:self.transferCharacteristic onSubscribedCentrals:nil]; | |
| if (eomSent) { | |
| // It sent, we're all done | |
| sendingEOM = NO; | |
| NSLog(@"Sent: EOM"); | |
| } | |
| return; | |
| } | |
| } | |
| } | |
| - (void) peripheralManager:(CBPeripheralManager *)peripheral | |
| didReceiveWriteRequests:(NSArray *)requests | |
| { | |
| for (CBATTRequest *aRequest in requests) | |
| { | |
| NSString *dataValue = [[NSString alloc] initWithData:aRequest.value encoding:NSUTF8StringEncoding]; | |
| if ([dataValue isEqualToString:@"Close Test"]){ | |
| [[NSNotificationCenter defaultCenter] postNotificationName:@"closeTestBT" object:self]; | |
| } | |
| if ([dataValue isEqualToString:@"Big Button"]){ | |
| [[NSNotificationCenter defaultCenter] postNotificationName:@"bigButtonBT" object:self]; | |
| } | |
| if ([dataValue isEqualToString:@"testCompleteBT"]){ | |
| [[NSNotificationCenter defaultCenter] postNotificationName:@"testCompleteBT" object:self]; | |
| } | |
| } | |
| [self.peripheralManager respondToRequest:requests[0] | |
| withResult:CBATTErrorSuccess]; | |
| } | |
| - (void)peripheralManagerIsReadyToUpdateSubscribers:(CBPeripheralManager *)peripheral { | |
| [self sendData]; | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment