UIViewController+Alerts.h 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <UIKit/UIKit.h>
  17. NS_ASSUME_NONNULL_BEGIN
  18. /*! @typedef AlertPromptCompletionBlock
  19. @brief The type of callback used to report text input prompt results.
  20. */
  21. typedef void (^AlertPromptCompletionBlock)(BOOL userPressedOK, NSString *_Nullable userInput);
  22. /*! @category UIViewController(Alerts)
  23. @brief Wrapper for @c UIAlertController and @c UIAlertView for backwards compatability with
  24. iOS 6+.
  25. */
  26. @interface UIViewController (Alerts)
  27. /*! @property useStatusBarSpinner
  28. @brief Uses the status bar to indicate work is occuring instead of a modal "please wait" dialog.
  29. This is generally useful for allowing user interaction while things are happening.
  30. */
  31. @property(nonatomic, assign) BOOL useStatusBarSpinner;
  32. /*! @fn showMessagePrompt:
  33. @brief Displays an alert with an 'OK' button and a message.
  34. @param message The message to display.
  35. @remarks The message is also copied to the pasteboard.
  36. */
  37. - (void)showMessagePrompt:(NSString *)message;
  38. /*! @fn showMessagePromptWithTitle:message:
  39. @brief Displays a titled alert with an 'OK' button and a message.
  40. @param title The title of the alert if it exists.
  41. @param message The message to display.
  42. @param showCancelButton A flag indicating whether or not a cancel option is available.
  43. @param completion The completion block to be executed after the alert is dismissed, if it
  44. exists.
  45. @remarks The message is also copied to the pasteboard.
  46. */
  47. - (void)showMessagePromptWithTitle:(nullable NSString *)title
  48. message:(NSString *)message
  49. showCancelButton:(BOOL)showCancelButton
  50. completion:(nullable AlertPromptCompletionBlock)completion;
  51. /*! @fn showTextInputPromptWithMessage:keyboardType:completionBlock:
  52. @brief Shows a prompt with a text field and 'OK'/'Cancel' buttons.
  53. @param message The message to display.
  54. @param keyboardType The type of keyboard to display for the UITextView in the prompt.
  55. @param completion A block to call when the user taps 'OK' or 'Cancel'.
  56. */
  57. - (void)showTextInputPromptWithMessage:(NSString *)message
  58. keyboardType:(UIKeyboardType)keyboardType
  59. completionBlock:(AlertPromptCompletionBlock)completion;
  60. /*! @fn showTextInputPromptWithMessage:completionBlock:
  61. @brief Shows a prompt with a text field and 'OK'/'Cancel' buttons.
  62. @param message The message to display.
  63. @param completion A block to call when the user taps 'OK' or 'Cancel'.
  64. */
  65. - (void)showTextInputPromptWithMessage:(NSString *)message
  66. completionBlock:(AlertPromptCompletionBlock)completion;
  67. /*! @fn showSpinner
  68. @brief Shows the please wait spinner.
  69. @param completion Called after the spinner has been hidden.
  70. */
  71. - (void)showSpinner:(nullable void(^)(void))completion;
  72. /*! @fn hideSpinner
  73. @brief Hides the please wait spinner.
  74. @param completion Called after the spinner has been hidden.
  75. */
  76. - (void)hideSpinner:(nullable void(^)(void))completion;
  77. @end
  78. NS_ASSUME_NONNULL_END