FBAlertViewController.m 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /**
  2. * Copyright (c) 2015-present, Facebook, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. */
  9. #import "FBAlertViewController.h"
  10. #import <Photos/Photos.h>
  11. #import <CoreLocation/CoreLocation.h>
  12. @interface FBAlertViewController ()
  13. @property (nonatomic, strong) CLLocationManager *locationManager;
  14. @end
  15. @implementation FBAlertViewController
  16. - (IBAction)createAppAlert:(UIButton *)sender
  17. {
  18. [self presentAlertController];
  19. }
  20. - (IBAction)createAppSheet:(UIButton *)sender
  21. {
  22. UIAlertController *alerController =
  23. [UIAlertController alertControllerWithTitle:@"Magic Sheet"
  24. message:@"Should read"
  25. preferredStyle:UIAlertControllerStyleActionSheet];
  26. UIPopoverPresentationController *popPresenter = [alerController popoverPresentationController];
  27. popPresenter.sourceView = sender;
  28. [self presentViewController:alerController animated:YES completion:nil];
  29. }
  30. - (IBAction)createNotificationAlert:(UIButton *)sender
  31. {
  32. [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert categories:nil]];
  33. }
  34. - (IBAction)createCameraRollAccessAlert:(UIButton *)sender
  35. {
  36. [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
  37. }];
  38. }
  39. - (IBAction)createGPSAccessAlert:(UIButton *)sender
  40. {
  41. self.locationManager = [CLLocationManager new];
  42. [self.locationManager requestAlwaysAuthorization];
  43. }
  44. - (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
  45. {
  46. [super touchesMoved:touches withEvent:event];
  47. for (UITouch *touch in touches) {
  48. if (fabs(touch.maximumPossibleForce - touch.force) < 0.0001) {
  49. [self presentAlertController];
  50. return;
  51. }
  52. }
  53. }
  54. - (void)presentAlertController
  55. {
  56. UIAlertController *alerController =
  57. [UIAlertController alertControllerWithTitle:@"Magic"
  58. message:@"Should read"
  59. preferredStyle:UIAlertControllerStyleAlert];
  60. [alerController addAction:[UIAlertAction actionWithTitle:@"Will do" style:UIAlertActionStyleDefault handler:nil]];
  61. [self presentViewController:alerController animated:YES completion:nil];
  62. }
  63. @end