Advertisement
Guest User

SettingsViewController.m

a guest
Jul 16th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.18 KB | None | 0 0
  1. #import "SettingsViewController.h"
  2.  
  3. #define RGB(r, g, b) [UIColor colorWithRed:(float)r / 255.0 green:(float)g / 255.0 blue:(float)b / 255.0 alpha:1.0]
  4. #define RGBA(r, g, b, a) [UIColor colorWithRed:(float)r / 255.0 green:(float)g / 255.0 blue:(float)b / 255.0 alpha:a]
  5.  
  6.  
  7.  
  8. @implementation SettingsViewController
  9. NSString *selectedItem;
  10. UITextField *textField;
  11.  
  12. - (void)loadView {
  13. [super loadView];
  14. }
  15.  
  16. -(void)dismissKeyboard {
  17. [UITextField resignFirstResponder];
  18. }
  19.  
  20.  
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23.  
  24. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboard)];
  25. [self.view addGestureRecognizer:tap];
  26.  
  27.  
  28. NSString *devicesPath = [[NSBundle bundleWithPath:@"/var/mobile/Library/Application Support/MakeCydiaBuyAgain"] pathForResource:@"Devices" ofType:@"plist"];
  29. NSArray *deviceList = [NSArray arrayWithContentsOfFile:devicesPath];
  30.  
  31. CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width; // screen width
  32. CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height; // screen height
  33. CGFloat toolbarHeight = 44;
  34. CGFloat statusBarHeight = 44;
  35. CGFloat startPosition = statusBarHeight + toolbarHeight;
  36. CGFloat padding = 10;
  37.  
  38. NSDictionary *deviceRow = deviceList[0];
  39. NSString *val = [deviceRow valueForKeyPath: @"val"];
  40.  
  41. selectedItem = val;
  42.  
  43. self.view.backgroundColor = [UIColor whiteColor]; // view container
  44.  
  45. UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, statusBarHeight, screenWidth, toolbarHeight)];
  46. [toolBar setBarStyle:UIBarStyleDefault];
  47. [toolBar setBarTintColor:RGBA(255,255,255,0)];
  48. toolBar.clipsToBounds = YES;
  49.  
  50. UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
  51.  
  52. // Done Button Start
  53. UIBarButtonItem *buttonDone = [
  54. [UIBarButtonItem alloc] initWithTitle:@"Done"
  55. style:UIBarButtonItemStyleBordered
  56. target:self
  57. action:@selector(doneTap)
  58. ];
  59.  
  60. [buttonDone setTitleTextAttributes:
  61. [
  62. NSDictionary dictionaryWithObjectsAndKeys:
  63. RGB(0,122,255),
  64. NSForegroundColorAttributeName,nil
  65. ]
  66. forState:UIControlStateNormal
  67. ];
  68.  
  69. // Done Button End
  70.  
  71.  
  72.  
  73.  
  74. UILabel *toolbarLabel = [[UILabel alloc] initWithFrame:CGRectZero];
  75. toolbarLabel.text = @"Device Settings";
  76. toolbarLabel.font = [UIFont systemFontOfSize:17 weight:UIFontWeightSemibold];
  77. toolbarLabel.backgroundColor = [UIColor clearColor];
  78. toolbarLabel.textColor = [UIColor blackColor];
  79. toolbarLabel.textAlignment = NSTextAlignmentCenter;
  80. [toolbarLabel sizeToFit];
  81.  
  82.  
  83. UIBarButtonItem *labelItem = [[UIBarButtonItem alloc] initWithCustomView:toolbarLabel];
  84.  
  85. toolBar.items = @[flexibleSpace, labelItem, flexibleSpace, buttonDone];
  86.  
  87.  
  88.  
  89. UILabel *devicePickerLabel = [[UILabel alloc] initWithFrame:CGRectMake(padding, startPosition + padding , screenWidth - padding, 50.0)];
  90. devicePickerLabel.text = @"Device Model";
  91. devicePickerLabel.font = [UIFont systemFontOfSize:17 weight:UIFontWeightSemibold];
  92. devicePickerLabel.backgroundColor = [UIColor clearColor];
  93. devicePickerLabel.textColor = [UIColor blackColor];
  94. devicePickerLabel.textAlignment = NSTextAlignmentCenter;
  95. [devicePickerLabel sizeToFit];
  96.  
  97.  
  98. UIPickerView *picker = [[UIPickerView alloc] initWithFrame:CGRectMake(padding, startPosition + devicePickerLabel.frame.size.height + padding, screenWidth - padding, 216)];
  99. picker.delegate = self;
  100. picker.dataSource = self;
  101. picker.showsSelectionIndicator = YES;
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108. UILabel *iosVersionLabel = [[UILabel alloc] initWithFrame:CGRectMake(padding, 0, screenWidth - padding, 50.0)];
  109. iosVersionLabel.text = @"iOS Version";
  110. iosVersionLabel.font = [UIFont systemFontOfSize:17 weight:UIFontWeightSemibold];
  111. iosVersionLabel.backgroundColor = [UIColor clearColor];
  112. iosVersionLabel.textColor = [UIColor blackColor];
  113. iosVersionLabel.textAlignment = NSTextAlignmentCenter;
  114. [iosVersionLabel sizeToFit];
  115.  
  116.  
  117.  
  118. textField = [
  119. [UITextField alloc] initWithFrame:CGRectMake(padding, iosVersionLabel.frame.size.height + padding, screenWidth - padding, 50.0)
  120. ];
  121.  
  122. textField.borderStyle = UITextBorderStyleRoundedRect;
  123. textField.font = [UIFont systemFontOfSize:15];
  124. textField.placeholder = @"11.3.1 or 10.0";
  125. textField.autocorrectionType = UITextAutocorrectionTypeNo;
  126. textField.keyboardType = UIKeyboardTypeDecimalPad;
  127. textField.returnKeyType = UIReturnKeyDone;
  128. textField.clearButtonMode = UITextFieldViewModeWhileEditing;
  129. textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
  130. textField.delegate = self;
  131.  
  132.  
  133.  
  134. UIView* view = [
  135. [UIView alloc] initWithFrame:CGRectMake(0, startPosition + devicePickerLabel.frame.size.height + picker.frame.size.height + padding + iosVersionLabel.frame.size.height + padding, screenWidth, 55.0)
  136. ];
  137. view.backgroundColor = [UIColor clearColor];
  138. [view addSubview:iosVersionLabel];
  139. [view addSubview:textField];
  140.  
  141. UIView *inputView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screenWidth,screenHeight)];
  142. inputView.backgroundColor = [UIColor clearColor];
  143. [inputView addSubview:devicePickerLabel];
  144. [inputView addSubview:picker];
  145. [inputView addSubview:toolBar];
  146. [inputView addSubview:view];
  147.  
  148. [self.view addSubview:inputView];
  149.  
  150. }
  151.  
  152. -(void) doneTap {
  153. @try {
  154. NSLog(@"%@",selectedItem) ;
  155. NSString* settingsPath = [[NSBundle bundleWithPath:@"/var/mobile/Library/Preferences"] pathForResource:@"com.aids.makecydiabuyagain" ofType:@"plist"];
  156. NSMutableDictionary *settingsDict = [NSMutableDictionary dictionaryWithContentsOfFile:settingsPath];
  157.  
  158. //NSLog(@"doneTap: Got Settings Path: %@", settingsPath);
  159. //NSLog( selectedItem);
  160.  
  161. [settingsDict setObject:selectedItem forKey:@"hardware"];
  162. //NSLog(@"doneTap: setObject forKey hardware %@", selectedItem);
  163.  
  164. NSString *firmwarePeriod = [textField.text stringByReplacingOccurrencesOfString:@"," withString:@"."];
  165.  
  166. [settingsDict setObject:firmwarePeriod forKey:@"firmware"];
  167. //NSLog(@"doneTap: forKey firmware");
  168. [settingsDict writeToFile:settingsPath atomically:YES];
  169. //NSLog(@"doneTap: write to file");
  170.  
  171. //NSLog(@"doneTap: setup uialert");
  172. UIAlertView *alert = [
  173. [UIAlertView alloc] initWithTitle:@"Changes Saved"
  174. message:[NSString stringWithFormat:@"You are now spoofing as an %@ on iOS %@", selectedItem, textField.text]
  175. delegate:self
  176. cancelButtonTitle:@"Ok"
  177. otherButtonTitles:nil
  178. ];
  179. //NSLog(@"doneTap: uialert alloced");
  180. //NSLog(@"doneTap: show uialert");
  181. [alert show];
  182. //NSLog(@"doneTap: uialert should show");
  183. [self resignFirstResponder];
  184. [self dismissViewControllerAnimated:YES completion:nil];
  185. //NSLog(@"doneTap: doneTapped!");
  186. }
  187. @catch (NSException * e) {
  188. NSLog(@"titleForRow %@", e);
  189. }
  190.  
  191. }
  192.  
  193. - (BOOL)shouldAutorotate { return NO; }
  194. - (BOOL)prefersStatusBarHidden{ return NO; }
  195. - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView { return 1; }
  196.  
  197.  
  198. - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
  199. @try {
  200.  
  201. NSString *devicesPath = [[NSBundle bundleWithPath:@"/var/mobile/Library/Application Support/MakeCydiaBuyAgain"] pathForResource:@"Devices" ofType:@"plist"];
  202. NSArray *deviceList = [NSArray arrayWithContentsOfFile:devicesPath];
  203.  
  204. NSLog(@"didSelectRow: %d", row);
  205. NSDictionary *deviceRow = deviceList[row];
  206. NSLog(@"didSelectRow: %@",deviceRow);
  207. NSString *val = [deviceRow valueForKeyPath: @"val"];
  208. NSLog(@"didSelectRow: %@",val);
  209.  
  210. selectedItem = val;
  211. NSLog(@"%@",selectedItem) ;
  212. }
  213. @catch (NSException * e) {
  214. NSLog(@"didSelectRow Exception: %@", e);
  215. }
  216.  
  217. }
  218.  
  219.  
  220. - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
  221. NSString *devicesPath = [[NSBundle bundleWithPath:@"/var/mobile/Library/Application Support/MakeCydiaBuyAgain"] pathForResource:@"Devices" ofType:@"plist"];
  222. NSArray *deviceList = [NSArray arrayWithContentsOfFile:devicesPath];
  223.  
  224. NSInteger num = (int)[deviceList count];
  225. NSLog(@"numberOfRowsInComponent: %d", num);
  226. NSLog(@"%@",selectedItem) ;
  227. return num;
  228. }
  229.  
  230.  
  231. - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
  232. @try {
  233. NSString *devicesPath = [[NSBundle bundleWithPath:@"/var/mobile/Library/Application Support/MakeCydiaBuyAgain"] pathForResource:@"Devices" ofType:@"plist"];
  234. NSArray *deviceList = [NSArray arrayWithContentsOfFile:devicesPath];
  235.  
  236. NSDictionary *deviceRow = deviceList[row];
  237. NSString *title =[deviceRow valueForKeyPath: @"name"];
  238. return title;
  239. }
  240. @catch (NSException * e) {
  241. NSLog(@"titleForRow %@", e);
  242. }
  243. NSLog(@"%@",selectedItem) ;
  244. return @"title" ;
  245. }
  246.  
  247. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement