Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import "SettingsViewController.h"
- #define RGB(r, g, b) [UIColor colorWithRed:(float)r / 255.0 green:(float)g / 255.0 blue:(float)b / 255.0 alpha:1.0]
- #define RGBA(r, g, b, a) [UIColor colorWithRed:(float)r / 255.0 green:(float)g / 255.0 blue:(float)b / 255.0 alpha:a]
- @implementation SettingsViewController
- NSString *selectedItem;
- UITextField *textField;
- - (void)loadView {
- [super loadView];
- }
- -(void)dismissKeyboard {
- [UITextField resignFirstResponder];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboard)];
- [self.view addGestureRecognizer:tap];
- NSString *devicesPath = [[NSBundle bundleWithPath:@"/var/mobile/Library/Application Support/MakeCydiaBuyAgain"] pathForResource:@"Devices" ofType:@"plist"];
- NSArray *deviceList = [NSArray arrayWithContentsOfFile:devicesPath];
- CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width; // screen width
- CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height; // screen height
- CGFloat toolbarHeight = 44;
- CGFloat statusBarHeight = 44;
- CGFloat startPosition = statusBarHeight + toolbarHeight;
- CGFloat padding = 10;
- NSDictionary *deviceRow = deviceList[0];
- NSString *val = [deviceRow valueForKeyPath: @"val"];
- selectedItem = val;
- self.view.backgroundColor = [UIColor whiteColor]; // view container
- UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, statusBarHeight, screenWidth, toolbarHeight)];
- [toolBar setBarStyle:UIBarStyleDefault];
- [toolBar setBarTintColor:RGBA(255,255,255,0)];
- toolBar.clipsToBounds = YES;
- UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
- // Done Button Start
- UIBarButtonItem *buttonDone = [
- [UIBarButtonItem alloc] initWithTitle:@"Done"
- style:UIBarButtonItemStyleBordered
- target:self
- action:@selector(doneTap)
- ];
- [buttonDone setTitleTextAttributes:
- [
- NSDictionary dictionaryWithObjectsAndKeys:
- RGB(0,122,255),
- NSForegroundColorAttributeName,nil
- ]
- forState:UIControlStateNormal
- ];
- // Done Button End
- UILabel *toolbarLabel = [[UILabel alloc] initWithFrame:CGRectZero];
- toolbarLabel.text = @"Device Settings";
- toolbarLabel.font = [UIFont systemFontOfSize:17 weight:UIFontWeightSemibold];
- toolbarLabel.backgroundColor = [UIColor clearColor];
- toolbarLabel.textColor = [UIColor blackColor];
- toolbarLabel.textAlignment = NSTextAlignmentCenter;
- [toolbarLabel sizeToFit];
- UIBarButtonItem *labelItem = [[UIBarButtonItem alloc] initWithCustomView:toolbarLabel];
- toolBar.items = @[flexibleSpace, labelItem, flexibleSpace, buttonDone];
- UILabel *devicePickerLabel = [[UILabel alloc] initWithFrame:CGRectMake(padding, startPosition + padding , screenWidth - padding, 50.0)];
- devicePickerLabel.text = @"Device Model";
- devicePickerLabel.font = [UIFont systemFontOfSize:17 weight:UIFontWeightSemibold];
- devicePickerLabel.backgroundColor = [UIColor clearColor];
- devicePickerLabel.textColor = [UIColor blackColor];
- devicePickerLabel.textAlignment = NSTextAlignmentCenter;
- [devicePickerLabel sizeToFit];
- UIPickerView *picker = [[UIPickerView alloc] initWithFrame:CGRectMake(padding, startPosition + devicePickerLabel.frame.size.height + padding, screenWidth - padding, 216)];
- picker.delegate = self;
- picker.dataSource = self;
- picker.showsSelectionIndicator = YES;
- UILabel *iosVersionLabel = [[UILabel alloc] initWithFrame:CGRectMake(padding, 0, screenWidth - padding, 50.0)];
- iosVersionLabel.text = @"iOS Version";
- iosVersionLabel.font = [UIFont systemFontOfSize:17 weight:UIFontWeightSemibold];
- iosVersionLabel.backgroundColor = [UIColor clearColor];
- iosVersionLabel.textColor = [UIColor blackColor];
- iosVersionLabel.textAlignment = NSTextAlignmentCenter;
- [iosVersionLabel sizeToFit];
- textField = [
- [UITextField alloc] initWithFrame:CGRectMake(padding, iosVersionLabel.frame.size.height + padding, screenWidth - padding, 50.0)
- ];
- textField.borderStyle = UITextBorderStyleRoundedRect;
- textField.font = [UIFont systemFontOfSize:15];
- textField.placeholder = @"11.3.1 or 10.0";
- textField.autocorrectionType = UITextAutocorrectionTypeNo;
- textField.keyboardType = UIKeyboardTypeDecimalPad;
- textField.returnKeyType = UIReturnKeyDone;
- textField.clearButtonMode = UITextFieldViewModeWhileEditing;
- textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
- textField.delegate = self;
- UIView* view = [
- [UIView alloc] initWithFrame:CGRectMake(0, startPosition + devicePickerLabel.frame.size.height + picker.frame.size.height + padding + iosVersionLabel.frame.size.height + padding, screenWidth, 55.0)
- ];
- view.backgroundColor = [UIColor clearColor];
- [view addSubview:iosVersionLabel];
- [view addSubview:textField];
- UIView *inputView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screenWidth,screenHeight)];
- inputView.backgroundColor = [UIColor clearColor];
- [inputView addSubview:devicePickerLabel];
- [inputView addSubview:picker];
- [inputView addSubview:toolBar];
- [inputView addSubview:view];
- [self.view addSubview:inputView];
- }
- -(void) doneTap {
- @try {
- NSLog(@"%@",selectedItem) ;
- NSString* settingsPath = [[NSBundle bundleWithPath:@"/var/mobile/Library/Preferences"] pathForResource:@"com.aids.makecydiabuyagain" ofType:@"plist"];
- NSMutableDictionary *settingsDict = [NSMutableDictionary dictionaryWithContentsOfFile:settingsPath];
- //NSLog(@"doneTap: Got Settings Path: %@", settingsPath);
- //NSLog( selectedItem);
- [settingsDict setObject:selectedItem forKey:@"hardware"];
- //NSLog(@"doneTap: setObject forKey hardware %@", selectedItem);
- NSString *firmwarePeriod = [textField.text stringByReplacingOccurrencesOfString:@"," withString:@"."];
- [settingsDict setObject:firmwarePeriod forKey:@"firmware"];
- //NSLog(@"doneTap: forKey firmware");
- [settingsDict writeToFile:settingsPath atomically:YES];
- //NSLog(@"doneTap: write to file");
- //NSLog(@"doneTap: setup uialert");
- UIAlertView *alert = [
- [UIAlertView alloc] initWithTitle:@"Changes Saved"
- message:[NSString stringWithFormat:@"You are now spoofing as an %@ on iOS %@", selectedItem, textField.text]
- delegate:self
- cancelButtonTitle:@"Ok"
- otherButtonTitles:nil
- ];
- //NSLog(@"doneTap: uialert alloced");
- //NSLog(@"doneTap: show uialert");
- [alert show];
- //NSLog(@"doneTap: uialert should show");
- [self resignFirstResponder];
- [self dismissViewControllerAnimated:YES completion:nil];
- //NSLog(@"doneTap: doneTapped!");
- }
- @catch (NSException * e) {
- NSLog(@"titleForRow %@", e);
- }
- }
- - (BOOL)shouldAutorotate { return NO; }
- - (BOOL)prefersStatusBarHidden{ return NO; }
- - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView { return 1; }
- - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
- @try {
- NSString *devicesPath = [[NSBundle bundleWithPath:@"/var/mobile/Library/Application Support/MakeCydiaBuyAgain"] pathForResource:@"Devices" ofType:@"plist"];
- NSArray *deviceList = [NSArray arrayWithContentsOfFile:devicesPath];
- NSLog(@"didSelectRow: %d", row);
- NSDictionary *deviceRow = deviceList[row];
- NSLog(@"didSelectRow: %@",deviceRow);
- NSString *val = [deviceRow valueForKeyPath: @"val"];
- NSLog(@"didSelectRow: %@",val);
- selectedItem = val;
- NSLog(@"%@",selectedItem) ;
- }
- @catch (NSException * e) {
- NSLog(@"didSelectRow Exception: %@", e);
- }
- }
- - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
- NSString *devicesPath = [[NSBundle bundleWithPath:@"/var/mobile/Library/Application Support/MakeCydiaBuyAgain"] pathForResource:@"Devices" ofType:@"plist"];
- NSArray *deviceList = [NSArray arrayWithContentsOfFile:devicesPath];
- NSInteger num = (int)[deviceList count];
- NSLog(@"numberOfRowsInComponent: %d", num);
- NSLog(@"%@",selectedItem) ;
- return num;
- }
- - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
- @try {
- NSString *devicesPath = [[NSBundle bundleWithPath:@"/var/mobile/Library/Application Support/MakeCydiaBuyAgain"] pathForResource:@"Devices" ofType:@"plist"];
- NSArray *deviceList = [NSArray arrayWithContentsOfFile:devicesPath];
- NSDictionary *deviceRow = deviceList[row];
- NSString *title =[deviceRow valueForKeyPath: @"name"];
- return title;
- }
- @catch (NSException * e) {
- NSLog(@"titleForRow %@", e);
- }
- NSLog(@"%@",selectedItem) ;
- return @"title" ;
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement