FBAlertViewController.m 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
  33. [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound|UNAuthorizationOptionAlert|UNAuthorizationOptionBadge)
  34. completionHandler:^(BOOL granted, NSError * _Nullable error)
  35. {
  36. dispatch_async(dispatch_get_main_queue(), ^{
  37. [[UIApplication sharedApplication] registerForRemoteNotifications];
  38. });
  39. }];
  40. }
  41. - (IBAction)createCameraRollAccessAlert:(UIButton *)sender
  42. {
  43. [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
  44. }];
  45. }
  46. - (IBAction)createGPSAccessAlert:(UIButton *)sender
  47. {
  48. self.locationManager = [CLLocationManager new];
  49. [self.locationManager requestAlwaysAuthorization];
  50. }
  51. - (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
  52. {
  53. [super touchesMoved:touches withEvent:event];
  54. for (UITouch *touch in touches) {
  55. if (fabs(touch.maximumPossibleForce - touch.force) < 0.0001) {
  56. [self presentAlertController];
  57. return;
  58. }
  59. }
  60. }
  61. - (void)presentAlertController
  62. {
  63. UIAlertController *alerController =
  64. [UIAlertController alertControllerWithTitle:@"Magic"
  65. message:@"Should read"
  66. preferredStyle:UIAlertControllerStyleAlert];
  67. [alerController addAction:[UIAlertAction actionWithTitle:@"Will do" style:UIAlertActionStyleDefault handler:nil]];
  68. [self presentViewController:alerController animated:YES completion:nil];
  69. }
  70. @end