UIAlertView+AFNetworking.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // UIAlertView+AFNetworking.h
  2. // Copyright (c) 2011–2015 Alamofire Software Foundation (http://alamofire.org/)
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. #import <Foundation/Foundation.h>
  22. #import <Availability.h>
  23. #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
  24. #import <UIKit/UIKit.h>
  25. NS_ASSUME_NONNULL_BEGIN
  26. @class AFURLConnectionOperation;
  27. /**
  28. This category adds methods to the UIKit framework's `UIAlertView` class. The methods in this category provide support for automatically showing an alert if a session task or request operation finishes with an error. Alert title and message are filled from the corresponding `localizedDescription` & `localizedRecoverySuggestion` or `localizedFailureReason` of the error.
  29. */
  30. @interface UIAlertView (AFNetworking)
  31. ///-------------------------------------
  32. /// @name Showing Alert for Session Task
  33. ///-------------------------------------
  34. /**
  35. Shows an alert view with the error of the specified session task, if any.
  36. @param task The session task.
  37. @param delegate The alert view delegate.
  38. */
  39. #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000
  40. + (void)showAlertViewForTaskWithErrorOnCompletion:(NSURLSessionTask *)task
  41. delegate:(nullable id)delegate NS_EXTENSION_UNAVAILABLE_IOS("Not available in app extensions.");
  42. #endif
  43. /**
  44. Shows an alert view with the error of the specified session task, if any, with a custom cancel button title and other button titles.
  45. @param task The session task.
  46. @param delegate The alert view delegate.
  47. @param cancelButtonTitle The title of the cancel button or nil if there is no cancel button. Using this argument is equivalent to setting the cancel button index to the value returned by invoking addButtonWithTitle: specifying this title.
  48. @param otherButtonTitles The title of another button. Using this argument is equivalent to invoking addButtonWithTitle: with this title to add more buttons. Too many buttons can cause the alert view to scroll. For guidelines on the best ways to use an alert in an app, see "Temporary Views". Titles of additional buttons to add to the receiver, terminated with `nil`.
  49. */
  50. #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000
  51. + (void)showAlertViewForTaskWithErrorOnCompletion:(NSURLSessionTask *)task
  52. delegate:(nullable id)delegate
  53. cancelButtonTitle:(nullable NSString *)cancelButtonTitle
  54. otherButtonTitles:(nullable NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION NS_EXTENSION_UNAVAILABLE_IOS("Not available in app extensions.");
  55. #endif
  56. ///------------------------------------------
  57. /// @name Showing Alert for Request Operation
  58. ///------------------------------------------
  59. /**
  60. Shows an alert view with the error of the specified request operation, if any.
  61. @param operation The request operation.
  62. @param delegate The alert view delegate.
  63. */
  64. + (void)showAlertViewForRequestOperationWithErrorOnCompletion:(AFURLConnectionOperation *)operation
  65. delegate:(nullable id)delegate NS_EXTENSION_UNAVAILABLE_IOS("Not available in app extensions.");
  66. /**
  67. Shows an alert view with the error of the specified request operation, if any, with a custom cancel button title and other button titles.
  68. @param operation The request operation.
  69. @param delegate The alert view delegate.
  70. @param cancelButtonTitle The title of the cancel button or nil if there is no cancel button. Using this argument is equivalent to setting the cancel button index to the value returned by invoking addButtonWithTitle: specifying this title.
  71. @param otherButtonTitles The title of another button. Using this argument is equivalent to invoking addButtonWithTitle: with this title to add more buttons. Too many buttons can cause the alert view to scroll. For guidelines on the best ways to use an alert in an app, see "Temporary Views". Titles of additional buttons to add to the receiver, terminated with `nil`.
  72. */
  73. + (void)showAlertViewForRequestOperationWithErrorOnCompletion:(AFURLConnectionOperation *)operation
  74. delegate:(nullable id)delegate
  75. cancelButtonTitle:(nullable NSString *)cancelButtonTitle
  76. otherButtonTitles:(nullable NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION NS_EXTENSION_UNAVAILABLE_IOS("Not available in app extensions.");
  77. @end
  78. NS_ASSUME_NONNULL_END
  79. #endif