Эх сурвалжийг харах

Adding documentation for UIAlertView category

Mattt Thompson 12 жил өмнө
parent
commit
34f8cd1114

+ 29 - 7
UIKit+AFNetworking/UIAlertView+AFNetworking.h

@@ -20,13 +20,18 @@
 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 // THE SOFTWARE.
 
+#import <Foundation/Foundation.h>
+
+#import <Availability.h>
+
+#if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
+
 #import <UIKit/UIKit.h>
 
-#import "AFURLConnectionOperation.h"
-#import "AFURLSessionManager.h"
+@class AFURLConnectionOperation;
 
 /**
- 
+ 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.
  */
 @interface UIAlertView (AFNetworking)
 
@@ -35,32 +40,47 @@
 ///-------------------------------------
 
 /**
-
+ Shows an alert view with the error of the specified session task, if any.
+ 
+ @param task The session task.
+ @param delegate The alert view delegate.
  */
 + (void)showAlertViewForTaskWithErrorOnCompletion:(NSURLSessionTask *)task
                                          delegate:(id)delegate;
 
 /**
+ Shows an alert view with the error of the specified session task, if any, with a custom cancel button title and other button titles.
  
+ @param task The session task.
+ @param delegate The alert view delegate.
+ @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.
+ @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`.
  */
 + (void)showAlertViewForTaskWithErrorOnCompletion:(NSURLSessionTask *)task
                                          delegate:(id)delegate
                                 cancelButtonTitle:(NSString *)cancelButtonTitle
                                 otherButtonTitles:(NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION;
 
-
 ///------------------------------------------
 /// @name Showing Alert for Request Operation
 ///------------------------------------------
 
 /**
- 
+ Shows an alert view with the error of the specified request operation, if any.
+
+ @param operation The request operation.
+ @param delegate The alert view delegate.
  */
 + (void)showAlertViewForRequestOperationWithErrorOnCompletion:(AFURLConnectionOperation *)operation
                                                      delegate:(id)delegate;
 
 /**
- 
+ Shows an alert view with the error of the specified request operation, if any, with a custom cancel button title and other button titles.
+
+ @param operation The request operation.
+ @param delegate The alert view delegate.
+ @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.
+ @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`.
  */
 + (void)showAlertViewForRequestOperationWithErrorOnCompletion:(AFURLConnectionOperation *)operation
                                                      delegate:(id)delegate
@@ -68,3 +88,5 @@
                                             otherButtonTitles:(NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION;
 
 @end
+
+#endif

+ 12 - 0
UIKit+AFNetworking/UIAlertView+AFNetworking.m

@@ -22,6 +22,14 @@
 
 #import "UIAlertView+AFNetworking.h"
 
+#if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
+
+#import "AFURLConnectionOperation.h"
+
+#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000
+#import "AFURLSessionManager.h"
+#endif
+
 static void AFGetAlertViewTitleAndMessageFromError(NSError *error, NSString * __autoreleasing *title, NSString * __autoreleasing *message) {
     if (error.localizedDescription && (error.localizedRecoverySuggestion || error.localizedFailureReason)) {
         *title = error.localizedDescription;
@@ -42,6 +50,7 @@ static void AFGetAlertViewTitleAndMessageFromError(NSError *error, NSString * __
 
 @implementation UIAlertView (AFNetworking)
 
+#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000
 + (void)showAlertViewForTaskWithErrorOnCompletion:(NSURLSessionTask *)task
                                          delegate:(id)delegate
 {
@@ -66,6 +75,7 @@ static void AFGetAlertViewTitleAndMessageFromError(NSError *error, NSString * __
         [[NSNotificationCenter defaultCenter] removeObserver:observer name:AFNetworkingTaskDidFinishNotification object:notification.object];
     }];
 }
+#endif
 
 #pragma mark -
 
@@ -97,3 +107,5 @@ static void AFGetAlertViewTitleAndMessageFromError(NSError *error, NSString * __
 }
 
 @end
+
+#endif