Commit 648d0c2e45dd6baa3846e121f8cac7eafda1cbda

Authored by “张旭”
1 parent c98d37b5

no message

Too many changes to show.

To preserve performance only 14 of 1547 files are displayed.

Example/CNLivePayCostModule.xcworkspace/contents.xcworkspacedata 0 → 100644
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<Workspace
  3 + version = "1.0">
  4 + <FileRef
  5 + location = "group:CNLivePayCostModule.xcodeproj">
  6 + </FileRef>
  7 + <FileRef
  8 + location = "group:Pods/Pods.xcodeproj">
  9 + </FileRef>
  10 +</Workspace>
... ...
Example/CNLivePayCostModule.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist 0 → 100644
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  3 +<plist version="1.0">
  4 +<dict>
  5 + <key>IDEDidComputeMac32BitWarning</key>
  6 + <true/>
  7 +</dict>
  8 +</plist>
... ...
Example/Podfile.lock 0 → 100644
  1 +PODS:
  2 + - AFNetworking (4.0.1):
  3 + - AFNetworking/NSURLSession (= 4.0.1)
  4 + - AFNetworking/Reachability (= 4.0.1)
  5 + - AFNetworking/Security (= 4.0.1)
  6 + - AFNetworking/Serialization (= 4.0.1)
  7 + - AFNetworking/UIKit (= 4.0.1)
  8 + - AFNetworking/NSURLSession (4.0.1):
  9 + - AFNetworking/Reachability
  10 + - AFNetworking/Security
  11 + - AFNetworking/Serialization
  12 + - AFNetworking/Reachability (4.0.1)
  13 + - AFNetworking/Security (4.0.1)
  14 + - AFNetworking/Serialization (4.0.1)
  15 + - AFNetworking/UIKit (4.0.1):
  16 + - AFNetworking/NSURLSession
  17 + - CNLiveBaseKit (0.1.29):
  18 + - CNLiveNewTripartiteManagement/MJExtension
  19 + - CNLiveBaseTools (0.0.9):
  20 + - CNLiveBaseKit
  21 + - CNLiveBeeHive
  22 + - CNLiveNewTripartiteManagement/QMUIKit
  23 + - CNLiveNewTripartiteManagement/SDWebImage
  24 + - CNLiveNewTripartiteManagement/SSZipArchive
  25 + - CNLiveNewTripartiteManagement/YYCategories
  26 + - CNLiveNewTripartiteManagement/YYImage
  27 + - CNLiveBeeHive (0.1.9)
  28 + - CNLiveBusinessTools (0.1.32):
  29 + - CNLiveBaseKit
  30 + - CNLiveEnvironment
  31 + - CNLiveNewTripartiteManagement/QMUIKit
  32 + - CNLiveNewTripartiteManagement/YYAsyncLayer
  33 + - CNLiveNewTripartiteManagement/YYCache
  34 + - CNLiveNewTripartiteManagement/YYCategories
  35 + - CNLiveNewTripartiteManagement/YYDispatchQueuePool
  36 + - CNLiveNewTripartiteManagement/YYImage
  37 + - CNLiveNewTripartiteManagement/YYModel
  38 + - CNLiveNewTripartiteManagement/YYText
  39 + - CNLiveNewTripartiteManagement/YYWebImage
  40 + - CNLiveRequestBastKit
  41 + - CNLiveUserManagement
  42 + - CNLiveCommonCategory (0.5.2):
  43 + - CNLiveCommonCategory/ARC (= 0.5.2)
  44 + - CNLiveCommonCategory/ImageInBundle (= 0.5.2)
  45 + - CNLiveCommonCategory/ARC (0.5.2)
  46 + - CNLiveCommonCategory/ImageInBundle (0.5.2)
  47 + - CNLiveCustomUI/CNLiveBasicsUI (0.6.2):
  48 + - CNLiveBaseKit
  49 + - CNLiveBeeHive
  50 + - CNLiveBusinessTools
  51 + - CNLiveCommonCategory
  52 + - CNLiveCustomUI/CNLiveGetImage
  53 + - CNLiveNewTripartiteManagement/Masonry
  54 + - CNLiveNewTripartiteManagement/QMUIKit
  55 + - CNLiveNewTripartiteManagement/YYAsyncLayer
  56 + - CNLiveNewTripartiteManagement/YYCache
  57 + - CNLiveNewTripartiteManagement/YYCategories
  58 + - CNLiveNewTripartiteManagement/YYDispatchQueuePool
  59 + - CNLiveNewTripartiteManagement/YYImage
  60 + - CNLiveNewTripartiteManagement/YYKeyboardManager
  61 + - CNLiveNewTripartiteManagement/YYModel
  62 + - CNLiveNewTripartiteManagement/YYText
  63 + - CNLiveNewTripartiteManagement/YYWebImage
  64 + - TZImagePickerController
  65 + - CNLiveCustomUI/CNLiveGetImage (0.6.2):
  66 + - CNLiveBaseKit
  67 + - CNLiveBeeHive
  68 + - CNLiveBusinessTools
  69 + - CNLiveEnvironment (0.5.2)
  70 + - CNLiveNewTripartiteManagement/Masonry (0.2.1.1):
  71 + - Masonry (= 1.1.0)
  72 + - CNLiveNewTripartiteManagement/MJExtension (0.2.1.1):
  73 + - MJExtension (= 3.2.1)
  74 + - CNLiveNewTripartiteManagement/QMUIKit (0.2.1.1):
  75 + - QMUIKit (= 4.2.1)
  76 + - CNLiveNewTripartiteManagement/SDWebImage (0.2.1.1):
  77 + - SDWebImage (= 5.2.3)
  78 + - CNLiveNewTripartiteManagement/SSZipArchive (0.2.1.1):
  79 + - SSZipArchive (= 2.1.5)
  80 + - CNLiveNewTripartiteManagement/YYAsyncLayer (0.2.1.1):
  81 + - YYAsyncLayer (= 1.0)
  82 + - CNLiveNewTripartiteManagement/YYCache (0.2.1.1):
  83 + - YYCache (= 1.0.4)
  84 + - CNLiveNewTripartiteManagement/YYCategories (0.2.1.1):
  85 + - YYCategories (= 1.0.4)
  86 + - CNLiveNewTripartiteManagement/YYDispatchQueuePool (0.2.1.1):
  87 + - YYDispatchQueuePool (= 1.0)
  88 + - CNLiveNewTripartiteManagement/YYImage (0.2.1.1):
  89 + - YYImage (= 1.0.4)
  90 + - CNLiveNewTripartiteManagement/YYKeyboardManager (0.2.1.1):
  91 + - YYKeyboardManager (= 1.0.1)
  92 + - CNLiveNewTripartiteManagement/YYModel (0.2.1.1):
  93 + - YYModel (= 1.0.4)
  94 + - CNLiveNewTripartiteManagement/YYText (0.2.1.1):
  95 + - YYText (= 1.0.7)
  96 + - CNLiveNewTripartiteManagement/YYWebImage (0.2.1.1):
  97 + - YYWebImage (= 1.0.5)
  98 + - CNLivePayCostModule (0.1.4):
  99 + - CNLiveBaseKit
  100 + - CNLiveBaseTools
  101 + - CNLiveCommonCategory
  102 + - CNLiveCustomUI/CNLiveBasicsUI
  103 + - CNLiveNewTripartiteManagement/Masonry
  104 + - CNLiveRequestBastKit
  105 + - CNLiveSDK/CNLiveEncryptSDK
  106 + - CNLiveSDK/CNLivePaySDK
  107 + - CNLiveUserManagement
  108 + - UMCCommon
  109 + - WechatOpenSDK
  110 + - CNLiveRequestBastKit (0.2.6.1):
  111 + - AFNetworking
  112 + - CNLiveSDK/CNLiveEncryptSDK (0.3.5.2)
  113 + - CNLiveSDK/CNLivePaySDK (0.3.5.2)
  114 + - CNLiveUserManagement (0.1.7):
  115 + - CNLiveEnvironment
  116 + - CNLiveNewTripartiteManagement/MJExtension
  117 + - Masonry (1.1.0)
  118 + - MJExtension (3.2.1)
  119 + - QMUIKit (4.2.1):
  120 + - QMUIKit/QMUIComponents (= 4.2.1)
  121 + - QMUIKit/QMUICore (= 4.2.1)
  122 + - QMUIKit/QMUILog (= 4.2.1)
  123 + - QMUIKit/QMUIMainFrame (= 4.2.1)
  124 + - QMUIKit/QMUIResources (= 4.2.1)
  125 + - QMUIKit/QMUIWeakObjectContainer (= 4.2.1)
  126 + - QMUIKit/QMUIComponents (4.2.1):
  127 + - QMUIKit/QMUIComponents/NavigationBarTransition (= 4.2.1)
  128 + - QMUIKit/QMUIComponents/QMUIAlertController (= 4.2.1)
  129 + - QMUIKit/QMUIComponents/QMUIAnimation (= 4.2.1)
  130 + - QMUIKit/QMUIComponents/QMUIAppearance (= 4.2.1)
  131 + - QMUIKit/QMUIComponents/QMUIAssetLibrary (= 4.2.1)
  132 + - QMUIKit/QMUIComponents/QMUIBadge (= 4.2.1)
  133 + - QMUIKit/QMUIComponents/QMUIButton (= 4.2.1)
  134 + - QMUIKit/QMUIComponents/QMUICAAnimationExtension (= 4.2.1)
  135 + - QMUIKit/QMUIComponents/QMUICALayerExtension (= 4.2.1)
  136 + - QMUIKit/QMUIComponents/QMUICellHeightCache (= 4.2.1)
  137 + - QMUIKit/QMUIComponents/QMUICellHeightKeyCache (= 4.2.1)
  138 + - QMUIKit/QMUIComponents/QMUICellSizeKeyCache (= 4.2.1)
  139 + - QMUIKit/QMUIComponents/QMUICollectionViewPagingLayout (= 4.2.1)
  140 + - QMUIKit/QMUIComponents/QMUIConsole (= 4.2.1)
  141 + - QMUIKit/QMUIComponents/QMUIDialogViewController (= 4.2.1)
  142 + - QMUIKit/QMUIComponents/QMUIEmotionInputManager (= 4.2.1)
  143 + - QMUIKit/QMUIComponents/QMUIEmotionView (= 4.2.1)
  144 + - QMUIKit/QMUIComponents/QMUIEmptyView (= 4.2.1)
  145 + - QMUIKit/QMUIComponents/QMUIFillButton (= 4.2.1)
  146 + - QMUIKit/QMUIComponents/QMUIFloatLayoutView (= 4.2.1)
  147 + - QMUIKit/QMUIComponents/QMUIGhostButton (= 4.2.1)
  148 + - QMUIKit/QMUIComponents/QMUIGridView (= 4.2.1)
  149 + - QMUIKit/QMUIComponents/QMUIImagePickerLibrary (= 4.2.1)
  150 + - QMUIKit/QMUIComponents/QMUIImagePreviewView (= 4.2.1)
  151 + - QMUIKit/QMUIComponents/QMUIKeyboardManager (= 4.2.1)
  152 + - QMUIKit/QMUIComponents/QMUILabel (= 4.2.1)
  153 + - QMUIKit/QMUIComponents/QMUILinkButton (= 4.2.1)
  154 + - QMUIKit/QMUIComponents/QMUILogManagerViewController (= 4.2.1)
  155 + - QMUIKit/QMUIComponents/QMUILogWithConfigurationSupported (= 4.2.1)
  156 + - QMUIKit/QMUIComponents/QMUIMarqueeLabel (= 4.2.1)
  157 + - QMUIKit/QMUIComponents/QMUIModalPresentationViewController (= 4.2.1)
  158 + - QMUIKit/QMUIComponents/QMUIMoreOperationController (= 4.2.1)
  159 + - QMUIKit/QMUIComponents/QMUIMultipleDelegates (= 4.2.1)
  160 + - QMUIKit/QMUIComponents/QMUINavigationButton (= 4.2.1)
  161 + - QMUIKit/QMUIComponents/QMUINavigationTitleView (= 4.2.1)
  162 + - QMUIKit/QMUIComponents/QMUIOrderedDictionary (= 4.2.1)
  163 + - QMUIKit/QMUIComponents/QMUIPieProgressView (= 4.2.1)
  164 + - QMUIKit/QMUIComponents/QMUIPopupContainerView (= 4.2.1)
  165 + - QMUIKit/QMUIComponents/QMUIPopupMenuView (= 4.2.1)
  166 + - QMUIKit/QMUIComponents/QMUIScrollAnimator (= 4.2.1)
  167 + - QMUIKit/QMUIComponents/QMUISearchBar (= 4.2.1)
  168 + - QMUIKit/QMUIComponents/QMUISearchController (= 4.2.1)
  169 + - QMUIKit/QMUIComponents/QMUISegmentedControl (= 4.2.1)
  170 + - QMUIKit/QMUIComponents/QMUISlider (= 4.2.1)
  171 + - QMUIKit/QMUIComponents/QMUIStaticTableView (= 4.2.1)
  172 + - QMUIKit/QMUIComponents/QMUITableView (= 4.2.1)
  173 + - QMUIKit/QMUIComponents/QMUITableViewCell (= 4.2.1)
  174 + - QMUIKit/QMUIComponents/QMUITableViewHeaderFooterView (= 4.2.1)
  175 + - QMUIKit/QMUIComponents/QMUITableViewProtocols (= 4.2.1)
  176 + - QMUIKit/QMUIComponents/QMUITestView (= 4.2.1)
  177 + - QMUIKit/QMUIComponents/QMUITextField (= 4.2.1)
  178 + - QMUIKit/QMUIComponents/QMUITextView (= 4.2.1)
  179 + - QMUIKit/QMUIComponents/QMUITheme (= 4.2.1)
  180 + - QMUIKit/QMUIComponents/QMUITips (= 4.2.1)
  181 + - QMUIKit/QMUIComponents/QMUIToastView (= 4.2.1)
  182 + - QMUIKit/QMUIComponents/QMUIToolbarButton (= 4.2.1)
  183 + - QMUIKit/QMUIComponents/QMUIVisualEffectView (= 4.2.1)
  184 + - QMUIKit/QMUIComponents/QMUIWindowSizeMonitor (= 4.2.1)
  185 + - QMUIKit/QMUIComponents/QMUIZoomImageView (= 4.2.1)
  186 + - QMUIKit/QMUICore
  187 + - QMUIKit/QMUIComponents/NavigationBarTransition (4.2.1):
  188 + - QMUIKit/QMUIComponents/QMUINavigationTitleView
  189 + - QMUIKit/QMUICore
  190 + - QMUIKit/QMUIMainFrame
  191 + - QMUIKit/QMUIComponents/QMUIAlertController (4.2.1):
  192 + - QMUIKit/QMUIComponents/QMUIAppearance
  193 + - QMUIKit/QMUIComponents/QMUIButton
  194 + - QMUIKit/QMUIComponents/QMUIKeyboardManager
  195 + - QMUIKit/QMUIComponents/QMUIModalPresentationViewController
  196 + - QMUIKit/QMUIComponents/QMUITextField
  197 + - QMUIKit/QMUICore
  198 + - QMUIKit/QMUIComponents/QMUIAnimation (4.2.1):
  199 + - QMUIKit/QMUICore
  200 + - QMUIKit/QMUIComponents/QMUIAppearance (4.2.1):
  201 + - QMUIKit/QMUICore
  202 + - QMUIKit/QMUIComponents/QMUIAssetLibrary (4.2.1):
  203 + - QMUIKit/QMUICore
  204 + - QMUIKit/QMUIComponents/QMUIBadge (4.2.1):
  205 + - QMUIKit/QMUIComponents/QMUILabel
  206 + - QMUIKit/QMUICore
  207 + - QMUIKit/QMUIComponents/QMUIButton (4.2.1):
  208 + - QMUIKit/QMUICore
  209 + - QMUIKit/QMUIComponents/QMUICAAnimationExtension (4.2.1):
  210 + - QMUIKit/QMUIComponents/QMUIMultipleDelegates
  211 + - QMUIKit/QMUICore
  212 + - QMUIKit/QMUIComponents/QMUICALayerExtension (4.2.1):
  213 + - QMUIKit/QMUIComponents/QMUIMultipleDelegates
  214 + - QMUIKit/QMUICore
  215 + - QMUIKit/QMUIComponents/QMUICellHeightCache (4.2.1):
  216 + - QMUIKit/QMUIComponents/QMUITableViewProtocols
  217 + - QMUIKit/QMUICore
  218 + - QMUIKit/QMUIComponents/QMUICellHeightKeyCache (4.2.1):
  219 + - QMUIKit/QMUIComponents/QMUIMultipleDelegates
  220 + - QMUIKit/QMUIComponents/QMUITableViewProtocols
  221 + - QMUIKit/QMUICore
  222 + - QMUIKit/QMUIComponents/QMUICellSizeKeyCache (4.2.1):
  223 + - QMUIKit/QMUIComponents/QMUIMultipleDelegates
  224 + - QMUIKit/QMUICore
  225 + - QMUIKit/QMUIComponents/QMUICollectionViewPagingLayout (4.2.1):
  226 + - QMUIKit/QMUICore
  227 + - QMUIKit/QMUIComponents/QMUIConsole (4.2.1):
  228 + - QMUIKit/QMUIComponents/QMUIButton
  229 + - QMUIKit/QMUIComponents/QMUICAAnimationExtension
  230 + - QMUIKit/QMUIComponents/QMUIPopupMenuView
  231 + - QMUIKit/QMUIComponents/QMUITextField
  232 + - QMUIKit/QMUIComponents/QMUITextView
  233 + - QMUIKit/QMUICore
  234 + - QMUIKit/QMUIResources
  235 + - QMUIKit/QMUIComponents/QMUIDialogViewController (4.2.1):
  236 + - QMUIKit/QMUIComponents/QMUIAppearance
  237 + - QMUIKit/QMUIComponents/QMUIButton
  238 + - QMUIKit/QMUIComponents/QMUILabel
  239 + - QMUIKit/QMUIComponents/QMUIModalPresentationViewController
  240 + - QMUIKit/QMUIComponents/QMUINavigationTitleView
  241 + - QMUIKit/QMUIComponents/QMUITableView
  242 + - QMUIKit/QMUIComponents/QMUITableViewCell
  243 + - QMUIKit/QMUIComponents/QMUITextField
  244 + - QMUIKit/QMUICore
  245 + - QMUIKit/QMUIMainFrame
  246 + - QMUIKit/QMUIComponents/QMUIEmotionInputManager (4.2.1):
  247 + - QMUIKit/QMUIComponents/QMUIEmotionView
  248 + - QMUIKit/QMUICore
  249 + - QMUIKit/QMUIComponents/QMUIEmotionView (4.2.1):
  250 + - QMUIKit/QMUIComponents/QMUIButton
  251 + - QMUIKit/QMUICore
  252 + - QMUIKit/QMUIResources
  253 + - QMUIKit/QMUIComponents/QMUIEmptyView (4.2.1):
  254 + - QMUIKit/QMUIComponents/QMUIAppearance
  255 + - QMUIKit/QMUIComponents/QMUIButton
  256 + - QMUIKit/QMUICore
  257 + - QMUIKit/QMUIComponents/QMUIFillButton (4.2.1):
  258 + - QMUIKit/QMUIComponents/QMUIButton
  259 + - QMUIKit/QMUICore
  260 + - QMUIKit/QMUIComponents/QMUIFloatLayoutView (4.2.1):
  261 + - QMUIKit/QMUICore
  262 + - QMUIKit/QMUIComponents/QMUIGhostButton (4.2.1):
  263 + - QMUIKit/QMUIComponents/QMUIButton
  264 + - QMUIKit/QMUICore
  265 + - QMUIKit/QMUIComponents/QMUIGridView (4.2.1):
  266 + - QMUIKit/QMUICore
  267 + - QMUIKit/QMUIComponents/QMUIImagePickerLibrary (4.2.1):
  268 + - QMUIKit/QMUIComponents/QMUIAlertController
  269 + - QMUIKit/QMUIComponents/QMUIAppearance
  270 + - QMUIKit/QMUIComponents/QMUIAssetLibrary
  271 + - QMUIKit/QMUIComponents/QMUIButton
  272 + - QMUIKit/QMUIComponents/QMUIEmptyView
  273 + - QMUIKit/QMUIComponents/QMUIImagePreviewView
  274 + - QMUIKit/QMUIComponents/QMUINavigationButton
  275 + - QMUIKit/QMUIComponents/QMUITableViewCell
  276 + - QMUIKit/QMUIComponents/QMUIZoomImageView
  277 + - QMUIKit/QMUICore
  278 + - QMUIKit/QMUIMainFrame
  279 + - QMUIKit/QMUIResources
  280 + - QMUIKit/QMUIComponents/QMUIImagePreviewView (4.2.1):
  281 + - QMUIKit/QMUIComponents/QMUIAppearance
  282 + - QMUIKit/QMUIComponents/QMUIButton
  283 + - QMUIKit/QMUIComponents/QMUICollectionViewPagingLayout
  284 + - QMUIKit/QMUIComponents/QMUIEmptyView
  285 + - QMUIKit/QMUIComponents/QMUIPieProgressView
  286 + - QMUIKit/QMUIComponents/QMUIZoomImageView
  287 + - QMUIKit/QMUICore
  288 + - QMUIKit/QMUIMainFrame
  289 + - QMUIKit/QMUIComponents/QMUIKeyboardManager (4.2.1):
  290 + - QMUIKit/QMUIComponents/QMUIAppearance
  291 + - QMUIKit/QMUICore
  292 + - QMUIKit/QMUIComponents/QMUILabel (4.2.1):
  293 + - QMUIKit/QMUICore
  294 + - QMUIKit/QMUIComponents/QMUILinkButton (4.2.1):
  295 + - QMUIKit/QMUIComponents/QMUIButton
  296 + - QMUIKit/QMUICore
  297 + - QMUIKit/QMUIComponents/QMUILogManagerViewController (4.2.1):
  298 + - QMUIKit/QMUIComponents/QMUIPopupMenuView
  299 + - QMUIKit/QMUIComponents/QMUISearchController
  300 + - QMUIKit/QMUIComponents/QMUIStaticTableView
  301 + - QMUIKit/QMUIComponents/QMUITableView
  302 + - QMUIKit/QMUICore
  303 + - QMUIKit/QMUIMainFrame
  304 + - QMUIKit/QMUIComponents/QMUILogWithConfigurationSupported (4.2.1):
  305 + - QMUIKit/QMUICore
  306 + - QMUIKit/QMUIComponents/QMUIMarqueeLabel (4.2.1):
  307 + - QMUIKit/QMUICore
  308 + - QMUIKit/QMUIComponents/QMUIModalPresentationViewController (4.2.1):
  309 + - QMUIKit/QMUIComponents/QMUIAppearance
  310 + - QMUIKit/QMUIComponents/QMUIKeyboardManager
  311 + - QMUIKit/QMUICore
  312 + - QMUIKit/QMUIComponents/QMUIMoreOperationController (4.2.1):
  313 + - QMUIKit/QMUIComponents/QMUIAppearance
  314 + - QMUIKit/QMUIComponents/QMUIButton
  315 + - QMUIKit/QMUIComponents/QMUIModalPresentationViewController
  316 + - QMUIKit/QMUICore
  317 + - QMUIKit/QMUIComponents/QMUIMultipleDelegates (4.2.1):
  318 + - QMUIKit/QMUICore
  319 + - QMUIKit/QMUIComponents/QMUINavigationButton (4.2.1):
  320 + - QMUIKit/QMUICore
  321 + - QMUIKit/QMUIMainFrame
  322 + - QMUIKit/QMUIComponents/QMUINavigationTitleView (4.2.1):
  323 + - QMUIKit/QMUIComponents/QMUIAppearance
  324 + - QMUIKit/QMUIComponents/QMUIButton
  325 + - QMUIKit/QMUICore
  326 + - QMUIKit/QMUIComponents/QMUIOrderedDictionary (4.2.1):
  327 + - QMUIKit/QMUICore
  328 + - QMUIKit/QMUIComponents/QMUIPieProgressView (4.2.1):
  329 + - QMUIKit/QMUICore
  330 + - QMUIKit/QMUIComponents/QMUIPopupContainerView (4.2.1):
  331 + - QMUIKit/QMUIComponents/QMUIAppearance
  332 + - QMUIKit/QMUICore
  333 + - QMUIKit/QMUIMainFrame
  334 + - QMUIKit/QMUIComponents/QMUIPopupMenuView (4.2.1):
  335 + - QMUIKit/QMUIComponents/QMUIButton
  336 + - QMUIKit/QMUIComponents/QMUIPopupContainerView
  337 + - QMUIKit/QMUICore
  338 + - QMUIKit/QMUIComponents/QMUIScrollAnimator (4.2.1):
  339 + - QMUIKit/QMUIComponents/QMUIMultipleDelegates
  340 + - QMUIKit/QMUICore
  341 + - QMUIKit/QMUIComponents/QMUISearchBar (4.2.1):
  342 + - QMUIKit/QMUICore
  343 + - QMUIKit/QMUIComponents/QMUISearchController (4.2.1):
  344 + - QMUIKit/QMUIComponents/QMUIEmptyView
  345 + - QMUIKit/QMUIComponents/QMUISearchBar
  346 + - QMUIKit/QMUICore
  347 + - QMUIKit/QMUIMainFrame
  348 + - QMUIKit/QMUIComponents/QMUISegmentedControl (4.2.1):
  349 + - QMUIKit/QMUICore
  350 + - QMUIKit/QMUIComponents/QMUISlider (4.2.1):
  351 + - QMUIKit/QMUICore
  352 + - QMUIKit/QMUIComponents/QMUIStaticTableView (4.2.1):
  353 + - QMUIKit/QMUIComponents/QMUIMultipleDelegates
  354 + - QMUIKit/QMUIComponents/QMUITableViewCell
  355 + - QMUIKit/QMUICore
  356 + - QMUIKit/QMUIComponents/QMUITableView (4.2.1):
  357 + - QMUIKit/QMUIComponents/QMUITableViewProtocols
  358 + - QMUIKit/QMUICore
  359 + - QMUIKit/QMUIComponents/QMUITableViewCell (4.2.1):
  360 + - QMUIKit/QMUIComponents/QMUIButton
  361 + - QMUIKit/QMUICore
  362 + - QMUIKit/QMUIComponents/QMUITableViewHeaderFooterView (4.2.1):
  363 + - QMUIKit/QMUICore
  364 + - QMUIKit/QMUIComponents/QMUITableViewProtocols (4.2.1):
  365 + - QMUIKit/QMUICore
  366 + - QMUIKit/QMUIComponents/QMUITestView (4.2.1):
  367 + - QMUIKit/QMUICore
  368 + - QMUIKit/QMUIComponents/QMUITextField (4.2.1):
  369 + - QMUIKit/QMUIComponents/QMUIMultipleDelegates
  370 + - QMUIKit/QMUICore
  371 + - QMUIKit/QMUIComponents/QMUITextView (4.2.1):
  372 + - QMUIKit/QMUIComponents/QMUILabel
  373 + - QMUIKit/QMUIComponents/QMUIMultipleDelegates
  374 + - QMUIKit/QMUICore
  375 + - QMUIKit/QMUIComponents/QMUITheme (4.2.1):
  376 + - QMUIKit/QMUIComponents/QMUIAlertController
  377 + - QMUIKit/QMUIComponents/QMUIBadge
  378 + - QMUIKit/QMUIComponents/QMUIButton
  379 + - QMUIKit/QMUIComponents/QMUIConsole
  380 + - QMUIKit/QMUIComponents/QMUIEmotionView
  381 + - QMUIKit/QMUIComponents/QMUIEmptyView
  382 + - QMUIKit/QMUIComponents/QMUIFillButton
  383 + - QMUIKit/QMUIComponents/QMUIGhostButton
  384 + - QMUIKit/QMUIComponents/QMUIGridView
  385 + - QMUIKit/QMUIComponents/QMUIImagePickerLibrary
  386 + - QMUIKit/QMUIComponents/QMUIImagePreviewView
  387 + - QMUIKit/QMUIComponents/QMUILabel
  388 + - QMUIKit/QMUIComponents/QMUILinkButton
  389 + - QMUIKit/QMUIComponents/QMUIModalPresentationViewController
  390 + - QMUIKit/QMUIComponents/QMUIPopupContainerView
  391 + - QMUIKit/QMUIComponents/QMUIPopupMenuView
  392 + - QMUIKit/QMUIComponents/QMUISlider
  393 + - QMUIKit/QMUIComponents/QMUITextField
  394 + - QMUIKit/QMUIComponents/QMUITextView
  395 + - QMUIKit/QMUIComponents/QMUIToastView
  396 + - QMUIKit/QMUIComponents/QMUIVisualEffectView
  397 + - QMUIKit/QMUICore
  398 + - QMUIKit/QMUIComponents/QMUITips (4.2.1):
  399 + - QMUIKit/QMUIComponents/QMUIToastView
  400 + - QMUIKit/QMUICore
  401 + - QMUIKit/QMUIResources
  402 + - QMUIKit/QMUIComponents/QMUIToastView (4.2.1):
  403 + - QMUIKit/QMUIComponents/QMUIKeyboardManager
  404 + - QMUIKit/QMUIComponents/QMUIVisualEffectView
  405 + - QMUIKit/QMUICore
  406 + - QMUIKit/QMUIComponents/QMUIToolbarButton (4.2.1):
  407 + - QMUIKit/QMUICore
  408 + - QMUIKit/QMUIComponents/QMUIVisualEffectView (4.2.1):
  409 + - QMUIKit/QMUIComponents/QMUICALayerExtension
  410 + - QMUIKit/QMUICore
  411 + - QMUIKit/QMUIComponents/QMUIWindowSizeMonitor (4.2.1):
  412 + - QMUIKit/QMUICore
  413 + - QMUIKit/QMUIComponents/QMUIZoomImageView (4.2.1):
  414 + - QMUIKit/QMUIComponents/QMUIAssetLibrary
  415 + - QMUIKit/QMUIComponents/QMUIButton
  416 + - QMUIKit/QMUIComponents/QMUIEmptyView
  417 + - QMUIKit/QMUIComponents/QMUIPieProgressView
  418 + - QMUIKit/QMUIComponents/QMUISlider
  419 + - QMUIKit/QMUICore
  420 + - QMUIKit/QMUIResources
  421 + - QMUIKit/QMUICore (4.2.1):
  422 + - QMUIKit/QMUILog
  423 + - QMUIKit/QMUIWeakObjectContainer
  424 + - QMUIKit/QMUILog (4.2.1)
  425 + - QMUIKit/QMUIMainFrame (4.2.1):
  426 + - QMUIKit/QMUIComponents/QMUIEmptyView
  427 + - QMUIKit/QMUIComponents/QMUIKeyboardManager
  428 + - QMUIKit/QMUIComponents/QMUIMultipleDelegates
  429 + - QMUIKit/QMUIComponents/QMUINavigationTitleView
  430 + - QMUIKit/QMUIComponents/QMUITableView
  431 + - QMUIKit/QMUIComponents/QMUITableViewHeaderFooterView
  432 + - QMUIKit/QMUICore
  433 + - QMUIKit/QMUILog
  434 + - QMUIKit/QMUIResources (4.2.1)
  435 + - QMUIKit/QMUIWeakObjectContainer (4.2.1)
  436 + - SDWebImage (5.2.3):
  437 + - SDWebImage/Core (= 5.2.3)
  438 + - SDWebImage/Core (5.2.3)
  439 + - SSZipArchive (2.1.5)
  440 + - TZImagePickerController (3.8.4):
  441 + - TZImagePickerController/Basic (= 3.8.4)
  442 + - TZImagePickerController/Location (= 3.8.4)
  443 + - TZImagePickerController/Basic (3.8.4)
  444 + - TZImagePickerController/Location (3.8.4)
  445 + - UMAPM (1.9.1)
  446 + - UMCCommon (7.3.7):
  447 + - UMAPM
  448 + - UMDevice
  449 + - UMDevice (3.4.0)
  450 + - WechatOpenSDK (2.0.4)
  451 + - YYAsyncLayer (1.0)
  452 + - YYCache (1.0.4)
  453 + - YYCategories (1.0.4):
  454 + - YYCategories/no-arc (= 1.0.4)
  455 + - YYCategories/no-arc (1.0.4)
  456 + - YYDispatchQueuePool (1.0)
  457 + - YYImage (1.0.4):
  458 + - YYImage/Core (= 1.0.4)
  459 + - YYImage/Core (1.0.4)
  460 + - YYKeyboardManager (1.0.1)
  461 + - YYModel (1.0.4)
  462 + - YYText (1.0.7)
  463 + - YYWebImage (1.0.5):
  464 + - YYCache
  465 + - YYImage
  466 +
  467 +DEPENDENCIES:
  468 + - CNLivePayCostModule (from `../`)
  469 +
  470 +SPEC REPOS:
  471 + http://bj.gitlab.cnlive.com/ios-team/CNLiveRepos.git:
  472 + - CNLiveBaseKit
  473 + - CNLiveBaseTools
  474 + - CNLiveBeeHive
  475 + - CNLiveBusinessTools
  476 + - CNLiveCommonCategory
  477 + - CNLiveCustomUI
  478 + - CNLiveEnvironment
  479 + - CNLiveNewTripartiteManagement
  480 + - CNLiveRequestBastKit
  481 + - CNLiveUserManagement
  482 + https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git:
  483 + - AFNetworking
  484 + - CNLiveSDK
  485 + - Masonry
  486 + - MJExtension
  487 + - QMUIKit
  488 + - SDWebImage
  489 + - SSZipArchive
  490 + - TZImagePickerController
  491 + - UMAPM
  492 + - UMCCommon
  493 + - UMDevice
  494 + - WechatOpenSDK
  495 + - YYAsyncLayer
  496 + - YYCache
  497 + - YYCategories
  498 + - YYDispatchQueuePool
  499 + - YYImage
  500 + - YYKeyboardManager
  501 + - YYModel
  502 + - YYText
  503 + - YYWebImage
  504 +
  505 +EXTERNAL SOURCES:
  506 + CNLivePayCostModule:
  507 + :path: "../"
  508 +
  509 +SPEC CHECKSUMS:
  510 + AFNetworking: 3bd23d814e976cd148d7d44c3ab78017b744cd58
  511 + CNLiveBaseKit: 6f1fbe1b4f501f7102d0ee4864b1c21ca93b24e6
  512 + CNLiveBaseTools: 063db5132ffb117628e3d79c34477a0eab630aca
  513 + CNLiveBeeHive: 1e105b15b6ccaad546258fcf91231563beb853d4
  514 + CNLiveBusinessTools: 67358bb3f6e914ee32b8572cc2fdf0122ad95094
  515 + CNLiveCommonCategory: 22c9842b31f2087803ae69e983b2c944fb80eae1
  516 + CNLiveCustomUI: b5fb09a8514cf5aa07ba13e6282f3d1c8d554a46
  517 + CNLiveEnvironment: 58db88eb40e856413e21feca39011f085724179d
  518 + CNLiveNewTripartiteManagement: 9f175b357771f36fdf00c8a5302306d129717b55
  519 + CNLivePayCostModule: 389511935296d6afb42980bf05930487e887a545
  520 + CNLiveRequestBastKit: d4c9364ec9cb0cdba2ae81f792a34f9d0c7a10d9
  521 + CNLiveSDK: 7a1fe52130343ddcc0b66adf40109fe916138bfa
  522 + CNLiveUserManagement: ce9078fdebb1692c4117e758b0e85463b45474b0
  523 + Masonry: 678fab65091a9290e40e2832a55e7ab731aad201
  524 + MJExtension: 635f2c663dcb1bf76fa4b715b2570a5710aec545
  525 + QMUIKit: 15294d6a350466e4a6f4df0333eac5bff474f995
  526 + SDWebImage: 46a7f73228f84ce80990c786e4372cf4db5875ce
  527 + SSZipArchive: cefe1364104a0231268a5deb8495bdf2861f52f0
  528 + TZImagePickerController: f1c9f1cae6ac0e30b31aaa9698f9bf4a7cf5b84f
  529 + UMAPM: dad298c296209d65da542f19ba701dfffc902139
  530 + UMCCommon: aac337052f23b0e08c0f3cf021d3bb209f2c49bd
  531 + UMDevice: dcdf7ec167387837559d149fbc7d793d984faf82
  532 + WechatOpenSDK: 290989072e87b79d52225a01bb4e5e58f6f88593
  533 + YYAsyncLayer: df6b01ebc695c5f6b4c15dd5c23fa3e081eb25c0
  534 + YYCache: 8105b6638f5e849296c71f331ff83891a4942952
  535 + YYCategories: 6bcd4314c6661a561410dce4a793379ebd306abd
  536 + YYDispatchQueuePool: 3dfb2274bcc74207688dde8ac6f7bdd46871dd7b
  537 + YYImage: 1e1b62a9997399593e4b9c4ecfbbabbf1d3f3b54
  538 + YYKeyboardManager: ff53d2e80d1808567a7f004028bd200d9469a89f
  539 + YYModel: 2a7fdd96aaa4b86a824e26d0c517de8928c04b30
  540 + YYText: 5c461d709e24d55a182d1441c41dc639a18a4849
  541 + YYWebImage: 5f7f36aee2ae293f016d418c7d6ba05c4863e928
  542 +
  543 +PODFILE CHECKSUM: afc1492e19830325d0810a9045a4b2f26a7ca63f
  544 +
  545 +COCOAPODS: 1.12.1
... ...
Example/Pods/AFNetworking/AFNetworking/AFCompatibilityMacros.h 0 → 100644
  1 +// AFCompatibilityMacros.h
  2 +// Copyright (c) 2011–2016 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 +
  22 +#ifndef AFCompatibilityMacros_h
  23 +#define AFCompatibilityMacros_h
  24 +
  25 +#ifdef API_AVAILABLE
  26 + #define AF_API_AVAILABLE(...) API_AVAILABLE(__VA_ARGS__)
  27 +#else
  28 + #define AF_API_AVAILABLE(...)
  29 +#endif // API_AVAILABLE
  30 +
  31 +#ifdef API_UNAVAILABLE
  32 + #define AF_API_UNAVAILABLE(...) API_UNAVAILABLE(__VA_ARGS__)
  33 +#else
  34 + #define AF_API_UNAVAILABLE(...)
  35 +#endif // API_UNAVAILABLE
  36 +
  37 +#if __has_warning("-Wunguarded-availability-new")
  38 + #define AF_CAN_USE_AT_AVAILABLE 1
  39 +#else
  40 + #define AF_CAN_USE_AT_AVAILABLE 0
  41 +#endif
  42 +
  43 +#if ((__IPHONE_OS_VERSION_MAX_ALLOWED && __IPHONE_OS_VERSION_MAX_ALLOWED < 100000) || (__MAC_OS_VERSION_MAX_ALLOWED && __MAC_OS_VERSION_MAX_ALLOWED < 101200) ||(__WATCH_OS_MAX_VERSION_ALLOWED && __WATCH_OS_MAX_VERSION_ALLOWED < 30000) ||(__TV_OS_MAX_VERSION_ALLOWED && __TV_OS_MAX_VERSION_ALLOWED < 100000))
  44 + #define AF_CAN_INCLUDE_SESSION_TASK_METRICS 0
  45 +#else
  46 + #define AF_CAN_INCLUDE_SESSION_TASK_METRICS 1
  47 +#endif
  48 +
  49 +#endif /* AFCompatibilityMacros_h */
... ...
Example/Pods/AFNetworking/AFNetworking/AFHTTPSessionManager.h 0 → 100644
  1 +// AFHTTPSessionManager.h
  2 +// Copyright (c) 2011–2016 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 +
  22 +#import <Foundation/Foundation.h>
  23 +#if !TARGET_OS_WATCH
  24 +#import <SystemConfiguration/SystemConfiguration.h>
  25 +#endif
  26 +#import <TargetConditionals.h>
  27 +
  28 +#import "AFURLSessionManager.h"
  29 +
  30 +/**
  31 + `AFHTTPSessionManager` is a subclass of `AFURLSessionManager` with convenience methods for making HTTP requests. When a `baseURL` is provided, requests made with the `GET` / `POST` / et al. convenience methods can be made with relative paths.
  32 +
  33 + ## Subclassing Notes
  34 +
  35 + Developers targeting iOS 7 or Mac OS X 10.9 or later that deal extensively with a web service are encouraged to subclass `AFHTTPSessionManager`, providing a class method that returns a shared singleton object on which authentication and other configuration can be shared across the application.
  36 +
  37 + ## Methods to Override
  38 +
  39 + To change the behavior of all data task operation construction, which is also used in the `GET` / `POST` / et al. convenience methods, override `dataTaskWithRequest:uploadProgress:downloadProgress:completionHandler:`.
  40 +
  41 + ## Serialization
  42 +
  43 + Requests created by an HTTP client will contain default headers and encode parameters according to the `requestSerializer` property, which is an object conforming to `<AFURLRequestSerialization>`.
  44 +
  45 + Responses received from the server are automatically validated and serialized by the `responseSerializers` property, which is an object conforming to `<AFURLResponseSerialization>`
  46 +
  47 + ## URL Construction Using Relative Paths
  48 +
  49 + For HTTP convenience methods, the request serializer constructs URLs from the path relative to the `-baseURL`, using `NSURL +URLWithString:relativeToURL:`, when provided. If `baseURL` is `nil`, `path` needs to resolve to a valid `NSURL` object using `NSURL +URLWithString:`.
  50 +
  51 + Below are a few examples of how `baseURL` and relative paths interact:
  52 +
  53 + NSURL *baseURL = [NSURL URLWithString:@"http://example.com/v1/"];
  54 + [NSURL URLWithString:@"foo" relativeToURL:baseURL]; // http://example.com/v1/foo
  55 + [NSURL URLWithString:@"foo?bar=baz" relativeToURL:baseURL]; // http://example.com/v1/foo?bar=baz
  56 + [NSURL URLWithString:@"/foo" relativeToURL:baseURL]; // http://example.com/foo
  57 + [NSURL URLWithString:@"foo/" relativeToURL:baseURL]; // http://example.com/v1/foo
  58 + [NSURL URLWithString:@"/foo/" relativeToURL:baseURL]; // http://example.com/foo/
  59 + [NSURL URLWithString:@"http://example2.com/" relativeToURL:baseURL]; // http://example2.com/
  60 +
  61 + Also important to note is that a trailing slash will be added to any `baseURL` without one. This would otherwise cause unexpected behavior when constructing URLs using paths without a leading slash.
  62 +
  63 + @warning Managers for background sessions must be owned for the duration of their use. This can be accomplished by creating an application-wide or shared singleton instance.
  64 + */
  65 +
  66 +NS_ASSUME_NONNULL_BEGIN
  67 +
  68 +@interface AFHTTPSessionManager : AFURLSessionManager <NSSecureCoding, NSCopying>
  69 +
  70 +/**
  71 + The URL used to construct requests from relative paths in methods like `requestWithMethod:URLString:parameters:`, and the `GET` / `POST` / et al. convenience methods.
  72 + */
  73 +@property (readonly, nonatomic, strong, nullable) NSURL *baseURL;
  74 +
  75 +/**
  76 + Requests created with `requestWithMethod:URLString:parameters:` & `multipartFormRequestWithMethod:URLString:parameters:constructingBodyWithBlock:` are constructed with a set of default headers using a parameter serialization specified by this property. By default, this is set to an instance of `AFHTTPRequestSerializer`, which serializes query string parameters for `GET`, `HEAD`, and `DELETE` requests, or otherwise URL-form-encodes HTTP message bodies.
  77 +
  78 + @warning `requestSerializer` must not be `nil`.
  79 + */
  80 +@property (nonatomic, strong) AFHTTPRequestSerializer <AFURLRequestSerialization> * requestSerializer;
  81 +
  82 +/**
  83 + Responses sent from the server in data tasks created with `dataTaskWithRequest:success:failure:` and run using the `GET` / `POST` / et al. convenience methods are automatically validated and serialized by the response serializer. By default, this property is set to an instance of `AFJSONResponseSerializer`.
  84 +
  85 + @warning `responseSerializer` must not be `nil`.
  86 + */
  87 +@property (nonatomic, strong) AFHTTPResponseSerializer <AFURLResponseSerialization> * responseSerializer;
  88 +
  89 +///-------------------------------
  90 +/// @name Managing Security Policy
  91 +///-------------------------------
  92 +
  93 +/**
  94 + The security policy used by created session to evaluate server trust for secure connections. `AFURLSessionManager` uses the `defaultPolicy` unless otherwise specified. A security policy configured with `AFSSLPinningModePublicKey` or `AFSSLPinningModeCertificate` can only be applied on a session manager initialized with a secure base URL (i.e. https). Applying a security policy with pinning enabled on an insecure session manager throws an `Invalid Security Policy` exception.
  95 + */
  96 +@property (nonatomic, strong) AFSecurityPolicy *securityPolicy;
  97 +
  98 +///---------------------
  99 +/// @name Initialization
  100 +///---------------------
  101 +
  102 +/**
  103 + Creates and returns an `AFHTTPSessionManager` object.
  104 + */
  105 ++ (instancetype)manager;
  106 +
  107 +/**
  108 + Initializes an `AFHTTPSessionManager` object with the specified base URL.
  109 +
  110 + @param url The base URL for the HTTP client.
  111 +
  112 + @return The newly-initialized HTTP client
  113 + */
  114 +- (instancetype)initWithBaseURL:(nullable NSURL *)url;
  115 +
  116 +/**
  117 + Initializes an `AFHTTPSessionManager` object with the specified base URL.
  118 +
  119 + This is the designated initializer.
  120 +
  121 + @param url The base URL for the HTTP client.
  122 + @param configuration The configuration used to create the managed session.
  123 +
  124 + @return The newly-initialized HTTP client
  125 + */
  126 +- (instancetype)initWithBaseURL:(nullable NSURL *)url
  127 + sessionConfiguration:(nullable NSURLSessionConfiguration *)configuration NS_DESIGNATED_INITIALIZER;
  128 +
  129 +///---------------------------
  130 +/// @name Making HTTP Requests
  131 +///---------------------------
  132 +
  133 +/**
  134 + Creates and runs an `NSURLSessionDataTask` with a `GET` request.
  135 +
  136 + @param URLString The URL string used to create the request URL.
  137 + @param parameters The parameters to be encoded according to the client request serializer.
  138 + @param headers The headers appended to the default headers for this request.
  139 + @param downloadProgress A block object to be executed when the download progress is updated. Note this block is called on the session queue, not the main queue.
  140 + @param success A block object to be executed when the task finishes successfully. This block has no return value and takes two arguments: the data task, and the response object created by the client response serializer.
  141 + @param failure A block object to be executed when the task finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a two arguments: the data task and the error describing the network or parsing error that occurred.
  142 +
  143 + @see -dataTaskWithRequest:uploadProgress:downloadProgress:completionHandler:
  144 + */
  145 +- (nullable NSURLSessionDataTask *)GET:(NSString *)URLString
  146 + parameters:(nullable id)parameters
  147 + headers:(nullable NSDictionary <NSString *, NSString *> *)headers
  148 + progress:(nullable void (^)(NSProgress *downloadProgress))downloadProgress
  149 + success:(nullable void (^)(NSURLSessionDataTask *task, id _Nullable responseObject))success
  150 + failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError *error))failure;
  151 +
  152 +/**
  153 + Creates and runs an `NSURLSessionDataTask` with a `HEAD` request.
  154 +
  155 + @param URLString The URL string used to create the request URL.
  156 + @param parameters The parameters to be encoded according to the client request serializer.
  157 + @param headers The headers appended to the default headers for this request.
  158 + @param success A block object to be executed when the task finishes successfully. This block has no return value and takes a single arguments: the data task.
  159 + @param failure A block object to be executed when the task finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a two arguments: the data task and the error describing the network or parsing error that occurred.
  160 +
  161 + @see -dataTaskWithRequest:completionHandler:
  162 + */
  163 +- (nullable NSURLSessionDataTask *)HEAD:(NSString *)URLString
  164 + parameters:(nullable id)parameters
  165 + headers:(nullable NSDictionary <NSString *, NSString *> *)headers
  166 + success:(nullable void (^)(NSURLSessionDataTask *task))success
  167 + failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError *error))failure;
  168 +
  169 +/**
  170 + Creates and runs an `NSURLSessionDataTask` with a `POST` request.
  171 +
  172 + @param URLString The URL string used to create the request URL.
  173 + @param parameters The parameters to be encoded according to the client request serializer.
  174 + @param headers The headers appended to the default headers for this request.
  175 + @param uploadProgress A block object to be executed when the upload progress is updated. Note this block is called on the session queue, not the main queue.
  176 + @param success A block object to be executed when the task finishes successfully. This block has no return value and takes two arguments: the data task, and the response object created by the client response serializer.
  177 + @param failure A block object to be executed when the task finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a two arguments: the data task and the error describing the network or parsing error that occurred.
  178 +
  179 + @see -dataTaskWithRequest:uploadProgress:downloadProgress:completionHandler:
  180 + */
  181 +- (nullable NSURLSessionDataTask *)POST:(NSString *)URLString
  182 + parameters:(nullable id)parameters
  183 + headers:(nullable NSDictionary <NSString *, NSString *> *)headers
  184 + progress:(nullable void (^)(NSProgress *uploadProgress))uploadProgress
  185 + success:(nullable void (^)(NSURLSessionDataTask *task, id _Nullable responseObject))success
  186 + failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError *error))failure;
  187 +
  188 +/**
  189 + Creates and runs an `NSURLSessionDataTask` with a multipart `POST` request.
  190 +
  191 + @param URLString The URL string used to create the request URL.
  192 + @param parameters The parameters to be encoded according to the client request serializer.
  193 + @param headers The headers appended to the default headers for this request.
  194 + @param block A block that takes a single argument and appends data to the HTTP body. The block argument is an object adopting the `AFMultipartFormData` protocol.
  195 + @param uploadProgress A block object to be executed when the upload progress is updated. Note this block is called on the session queue, not the main queue.
  196 + @param success A block object to be executed when the task finishes successfully. This block has no return value and takes two arguments: the data task, and the response object created by the client response serializer.
  197 + @param failure A block object to be executed when the task finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a two arguments: the data task and the error describing the network or parsing error that occurred.
  198 +
  199 + @see -dataTaskWithRequest:uploadProgress:downloadProgress:completionHandler:
  200 + */
  201 +- (nullable NSURLSessionDataTask *)POST:(NSString *)URLString
  202 + parameters:(nullable id)parameters
  203 + headers:(nullable NSDictionary <NSString *, NSString *> *)headers
  204 + constructingBodyWithBlock:(nullable void (^)(id <AFMultipartFormData> formData))block
  205 + progress:(nullable void (^)(NSProgress *uploadProgress))uploadProgress
  206 + success:(nullable void (^)(NSURLSessionDataTask *task, id _Nullable responseObject))success
  207 + failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError *error))failure;
  208 +
  209 +/**
  210 + Creates and runs an `NSURLSessionDataTask` with a `PUT` request.
  211 +
  212 + @param URLString The URL string used to create the request URL.
  213 + @param parameters The parameters to be encoded according to the client request serializer.
  214 + @param headers The headers appended to the default headers for this request.
  215 + @param success A block object to be executed when the task finishes successfully. This block has no return value and takes two arguments: the data task, and the response object created by the client response serializer.
  216 + @param failure A block object to be executed when the task finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a two arguments: the data task and the error describing the network or parsing error that occurred.
  217 +
  218 + @see -dataTaskWithRequest:completionHandler:
  219 + */
  220 +- (nullable NSURLSessionDataTask *)PUT:(NSString *)URLString
  221 + parameters:(nullable id)parameters
  222 + headers:(nullable NSDictionary <NSString *, NSString *> *)headers
  223 + success:(nullable void (^)(NSURLSessionDataTask *task, id _Nullable responseObject))success
  224 + failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError *error))failure;
  225 +
  226 +/**
  227 + Creates and runs an `NSURLSessionDataTask` with a `PATCH` request.
  228 +
  229 + @param URLString The URL string used to create the request URL.
  230 + @param parameters The parameters to be encoded according to the client request serializer.
  231 + @param headers The headers appended to the default headers for this request.
  232 + @param success A block object to be executed when the task finishes successfully. This block has no return value and takes two arguments: the data task, and the response object created by the client response serializer.
  233 + @param failure A block object to be executed when the task finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a two arguments: the data task and the error describing the network or parsing error that occurred.
  234 +
  235 + @see -dataTaskWithRequest:completionHandler:
  236 + */
  237 +- (nullable NSURLSessionDataTask *)PATCH:(NSString *)URLString
  238 + parameters:(nullable id)parameters
  239 + headers:(nullable NSDictionary <NSString *, NSString *> *)headers
  240 + success:(nullable void (^)(NSURLSessionDataTask *task, id _Nullable responseObject))success
  241 + failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError *error))failure;
  242 +
  243 +/**
  244 + Creates and runs an `NSURLSessionDataTask` with a `DELETE` request.
  245 +
  246 + @param URLString The URL string used to create the request URL.
  247 + @param parameters The parameters to be encoded according to the client request serializer.
  248 + @param headers The headers appended to the default headers for this request.
  249 + @param success A block object to be executed when the task finishes successfully. This block has no return value and takes two arguments: the data task, and the response object created by the client response serializer.
  250 + @param failure A block object to be executed when the task finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a two arguments: the data task and the error describing the network or parsing error that occurred.
  251 +
  252 + @see -dataTaskWithRequest:completionHandler:
  253 + */
  254 +- (nullable NSURLSessionDataTask *)DELETE:(NSString *)URLString
  255 + parameters:(nullable id)parameters
  256 + headers:(nullable NSDictionary <NSString *, NSString *> *)headers
  257 + success:(nullable void (^)(NSURLSessionDataTask *task, id _Nullable responseObject))success
  258 + failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError *error))failure;
  259 +
  260 +/**
  261 + Creates an `NSURLSessionDataTask` with a custom `HTTPMethod` request.
  262 +
  263 + @param method The HTTPMethod string used to create the request.
  264 + @param URLString The URL string used to create the request URL.
  265 + @param parameters The parameters to be encoded according to the client request serializer.
  266 + @param headers The headers appended to the default headers for this request.
  267 + @param uploadProgress A block object to be executed when the upload progress is updated. Note this block is called on the session queue, not the main queue.
  268 + @param downloadProgress A block object to be executed when the download progress is updated. Note this block is called on the session queue, not the main queue.
  269 + @param success A block object to be executed when the task finishes successfully. This block has no return value and takes two arguments: the data task, and the response object created by the client response serializer.
  270 + @param failure A block object to be executed when the task finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a two arguments: the data task and the error describing the network or parsing error that occurred.
  271 +
  272 + @see -dataTaskWithRequest:uploadProgress:downloadProgress:completionHandler:
  273 + */
  274 +- (nullable NSURLSessionDataTask *)dataTaskWithHTTPMethod:(NSString *)method
  275 + URLString:(NSString *)URLString
  276 + parameters:(nullable id)parameters
  277 + headers:(nullable NSDictionary <NSString *, NSString *> *)headers
  278 + uploadProgress:(nullable void (^)(NSProgress *uploadProgress))uploadProgress
  279 + downloadProgress:(nullable void (^)(NSProgress *downloadProgress))downloadProgress
  280 + success:(nullable void (^)(NSURLSessionDataTask *task, id _Nullable responseObject))success
  281 + failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError *error))failure;
  282 +
  283 +@end
  284 +
  285 +NS_ASSUME_NONNULL_END
... ...
Example/Pods/AFNetworking/AFNetworking/AFHTTPSessionManager.m 0 → 100644
  1 +// AFHTTPSessionManager.m
  2 +// Copyright (c) 2011–2016 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 +
  22 +#import "AFHTTPSessionManager.h"
  23 +
  24 +#import "AFURLRequestSerialization.h"
  25 +#import "AFURLResponseSerialization.h"
  26 +
  27 +#import <Availability.h>
  28 +#import <TargetConditionals.h>
  29 +#import <Security/Security.h>
  30 +
  31 +#import <netinet/in.h>
  32 +#import <netinet6/in6.h>
  33 +#import <arpa/inet.h>
  34 +#import <ifaddrs.h>
  35 +#import <netdb.h>
  36 +
  37 +#if TARGET_OS_IOS || TARGET_OS_TV
  38 +#import <UIKit/UIKit.h>
  39 +#elif TARGET_OS_WATCH
  40 +#import <WatchKit/WatchKit.h>
  41 +#endif
  42 +
  43 +@interface AFHTTPSessionManager ()
  44 +@property (readwrite, nonatomic, strong) NSURL *baseURL;
  45 +@end
  46 +
  47 +@implementation AFHTTPSessionManager
  48 +@dynamic responseSerializer;
  49 +
  50 ++ (instancetype)manager {
  51 + return [[[self class] alloc] initWithBaseURL:nil];
  52 +}
  53 +
  54 +- (instancetype)init {
  55 + return [self initWithBaseURL:nil];
  56 +}
  57 +
  58 +- (instancetype)initWithBaseURL:(NSURL *)url {
  59 + return [self initWithBaseURL:url sessionConfiguration:nil];
  60 +}
  61 +
  62 +- (instancetype)initWithSessionConfiguration:(NSURLSessionConfiguration *)configuration {
  63 + return [self initWithBaseURL:nil sessionConfiguration:configuration];
  64 +}
  65 +
  66 +- (instancetype)initWithBaseURL:(NSURL *)url
  67 + sessionConfiguration:(NSURLSessionConfiguration *)configuration
  68 +{
  69 + self = [super initWithSessionConfiguration:configuration];
  70 + if (!self) {
  71 + return nil;
  72 + }
  73 +
  74 + // Ensure terminal slash for baseURL path, so that NSURL +URLWithString:relativeToURL: works as expected
  75 + if ([[url path] length] > 0 && ![[url absoluteString] hasSuffix:@"/"]) {
  76 + url = [url URLByAppendingPathComponent:@""];
  77 + }
  78 +
  79 + self.baseURL = url;
  80 +
  81 + self.requestSerializer = [AFHTTPRequestSerializer serializer];
  82 + self.responseSerializer = [AFJSONResponseSerializer serializer];
  83 +
  84 + return self;
  85 +}
  86 +
  87 +#pragma mark -
  88 +
  89 +- (void)setRequestSerializer:(AFHTTPRequestSerializer <AFURLRequestSerialization> *)requestSerializer {
  90 + NSParameterAssert(requestSerializer);
  91 +
  92 + _requestSerializer = requestSerializer;
  93 +}
  94 +
  95 +- (void)setResponseSerializer:(AFHTTPResponseSerializer <AFURLResponseSerialization> *)responseSerializer {
  96 + NSParameterAssert(responseSerializer);
  97 +
  98 + [super setResponseSerializer:responseSerializer];
  99 +}
  100 +
  101 +@dynamic securityPolicy;
  102 +
  103 +- (void)setSecurityPolicy:(AFSecurityPolicy *)securityPolicy {
  104 + if (securityPolicy.SSLPinningMode != AFSSLPinningModeNone && ![self.baseURL.scheme isEqualToString:@"https"]) {
  105 + NSString *pinningMode = @"Unknown Pinning Mode";
  106 + switch (securityPolicy.SSLPinningMode) {
  107 + case AFSSLPinningModeNone: pinningMode = @"AFSSLPinningModeNone"; break;
  108 + case AFSSLPinningModeCertificate: pinningMode = @"AFSSLPinningModeCertificate"; break;
  109 + case AFSSLPinningModePublicKey: pinningMode = @"AFSSLPinningModePublicKey"; break;
  110 + }
  111 + NSString *reason = [NSString stringWithFormat:@"A security policy configured with `%@` can only be applied on a manager with a secure base URL (i.e. https)", pinningMode];
  112 + @throw [NSException exceptionWithName:@"Invalid Security Policy" reason:reason userInfo:nil];
  113 + }
  114 +
  115 + [super setSecurityPolicy:securityPolicy];
  116 +}
  117 +
  118 +#pragma mark -
  119 +
  120 +- (NSURLSessionDataTask *)GET:(NSString *)URLString
  121 + parameters:(nullable id)parameters
  122 + headers:(nullable NSDictionary <NSString *, NSString *> *)headers
  123 + progress:(nullable void (^)(NSProgress * _Nonnull))downloadProgress
  124 + success:(nullable void (^)(NSURLSessionDataTask * _Nonnull, id _Nullable))success
  125 + failure:(nullable void (^)(NSURLSessionDataTask * _Nullable, NSError * _Nonnull))failure
  126 +{
  127 +
  128 + NSURLSessionDataTask *dataTask = [self dataTaskWithHTTPMethod:@"GET"
  129 + URLString:URLString
  130 + parameters:parameters
  131 + headers:headers
  132 + uploadProgress:nil
  133 + downloadProgress:downloadProgress
  134 + success:success
  135 + failure:failure];
  136 +
  137 + [dataTask resume];
  138 +
  139 + return dataTask;
  140 +}
  141 +
  142 +- (NSURLSessionDataTask *)HEAD:(NSString *)URLString
  143 + parameters:(nullable id)parameters
  144 + headers:(nullable NSDictionary<NSString *,NSString *> *)headers
  145 + success:(nullable void (^)(NSURLSessionDataTask * _Nonnull))success
  146 + failure:(nullable void (^)(NSURLSessionDataTask * _Nullable, NSError * _Nonnull))failure
  147 +{
  148 + NSURLSessionDataTask *dataTask = [self dataTaskWithHTTPMethod:@"HEAD" URLString:URLString parameters:parameters headers:headers uploadProgress:nil downloadProgress:nil success:^(NSURLSessionDataTask *task, __unused id responseObject) {
  149 + if (success) {
  150 + success(task);
  151 + }
  152 + } failure:failure];
  153 +
  154 + [dataTask resume];
  155 +
  156 + return dataTask;
  157 +}
  158 +
  159 +- (nullable NSURLSessionDataTask *)POST:(NSString *)URLString
  160 + parameters:(nullable id)parameters
  161 + headers:(nullable NSDictionary <NSString *, NSString *> *)headers
  162 + progress:(nullable void (^)(NSProgress *uploadProgress))uploadProgress
  163 + success:(nullable void (^)(NSURLSessionDataTask *task, id _Nullable responseObject))success
  164 + failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError *error))failure
  165 +{
  166 + NSURLSessionDataTask *dataTask = [self dataTaskWithHTTPMethod:@"POST" URLString:URLString parameters:parameters headers:headers uploadProgress:uploadProgress downloadProgress:nil success:success failure:failure];
  167 +
  168 + [dataTask resume];
  169 +
  170 + return dataTask;
  171 +}
  172 +
  173 +- (NSURLSessionDataTask *)POST:(NSString *)URLString
  174 + parameters:(nullable id)parameters
  175 + headers:(nullable NSDictionary<NSString *,NSString *> *)headers
  176 + constructingBodyWithBlock:(nullable void (^)(id<AFMultipartFormData> _Nonnull))block
  177 + progress:(nullable void (^)(NSProgress * _Nonnull))uploadProgress
  178 + success:(nullable void (^)(NSURLSessionDataTask * _Nonnull, id _Nullable))success failure:(void (^)(NSURLSessionDataTask * _Nullable, NSError * _Nonnull))failure
  179 +{
  180 + NSError *serializationError = nil;
  181 + NSMutableURLRequest *request = [self.requestSerializer multipartFormRequestWithMethod:@"POST" URLString:[[NSURL URLWithString:URLString relativeToURL:self.baseURL] absoluteString] parameters:parameters constructingBodyWithBlock:block error:&serializationError];
  182 + for (NSString *headerField in headers.keyEnumerator) {
  183 + [request setValue:headers[headerField] forHTTPHeaderField:headerField];
  184 + }
  185 + if (serializationError) {
  186 + if (failure) {
  187 + dispatch_async(self.completionQueue ?: dispatch_get_main_queue(), ^{
  188 + failure(nil, serializationError);
  189 + });
  190 + }
  191 +
  192 + return nil;
  193 + }
  194 +
  195 + __block NSURLSessionDataTask *task = [self uploadTaskWithStreamedRequest:request progress:uploadProgress completionHandler:^(NSURLResponse * __unused response, id responseObject, NSError *error) {
  196 + if (error) {
  197 + if (failure) {
  198 + failure(task, error);
  199 + }
  200 + } else {
  201 + if (success) {
  202 + success(task, responseObject);
  203 + }
  204 + }
  205 + }];
  206 +
  207 + [task resume];
  208 +
  209 + return task;
  210 +}
  211 +
  212 +- (NSURLSessionDataTask *)PUT:(NSString *)URLString
  213 + parameters:(nullable id)parameters
  214 + headers:(nullable NSDictionary<NSString *,NSString *> *)headers
  215 + success:(nullable void (^)(NSURLSessionDataTask *task, id responseObject))success
  216 + failure:(nullable void (^)(NSURLSessionDataTask *task, NSError *error))failure
  217 +{
  218 + NSURLSessionDataTask *dataTask = [self dataTaskWithHTTPMethod:@"PUT" URLString:URLString parameters:parameters headers:headers uploadProgress:nil downloadProgress:nil success:success failure:failure];
  219 +
  220 + [dataTask resume];
  221 +
  222 + return dataTask;
  223 +}
  224 +
  225 +- (NSURLSessionDataTask *)PATCH:(NSString *)URLString
  226 + parameters:(nullable id)parameters
  227 + headers:(nullable NSDictionary<NSString *,NSString *> *)headers
  228 + success:(nullable void (^)(NSURLSessionDataTask *task, id responseObject))success
  229 + failure:(nullable void (^)(NSURLSessionDataTask *task, NSError *error))failure
  230 +{
  231 + NSURLSessionDataTask *dataTask = [self dataTaskWithHTTPMethod:@"PATCH" URLString:URLString parameters:parameters headers:headers uploadProgress:nil downloadProgress:nil success:success failure:failure];
  232 +
  233 + [dataTask resume];
  234 +
  235 + return dataTask;
  236 +}
  237 +
  238 +- (NSURLSessionDataTask *)DELETE:(NSString *)URLString
  239 + parameters:(nullable id)parameters
  240 + headers:(nullable NSDictionary<NSString *,NSString *> *)headers
  241 + success:(nullable void (^)(NSURLSessionDataTask *task, id responseObject))success
  242 + failure:(nullable void (^)(NSURLSessionDataTask *task, NSError *error))failure
  243 +{
  244 + NSURLSessionDataTask *dataTask = [self dataTaskWithHTTPMethod:@"DELETE" URLString:URLString parameters:parameters headers:headers uploadProgress:nil downloadProgress:nil success:success failure:failure];
  245 +
  246 + [dataTask resume];
  247 +
  248 + return dataTask;
  249 +}
  250 +
  251 +
  252 +- (NSURLSessionDataTask *)dataTaskWithHTTPMethod:(NSString *)method
  253 + URLString:(NSString *)URLString
  254 + parameters:(nullable id)parameters
  255 + headers:(nullable NSDictionary <NSString *, NSString *> *)headers
  256 + uploadProgress:(nullable void (^)(NSProgress *uploadProgress)) uploadProgress
  257 + downloadProgress:(nullable void (^)(NSProgress *downloadProgress)) downloadProgress
  258 + success:(nullable void (^)(NSURLSessionDataTask *task, id _Nullable responseObject))success
  259 + failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError *error))failure
  260 +{
  261 + NSError *serializationError = nil;
  262 + NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:method URLString:[[NSURL URLWithString:URLString relativeToURL:self.baseURL] absoluteString] parameters:parameters error:&serializationError];
  263 + for (NSString *headerField in headers.keyEnumerator) {
  264 + [request setValue:headers[headerField] forHTTPHeaderField:headerField];
  265 + }
  266 + if (serializationError) {
  267 + if (failure) {
  268 + dispatch_async(self.completionQueue ?: dispatch_get_main_queue(), ^{
  269 + failure(nil, serializationError);
  270 + });
  271 + }
  272 +
  273 + return nil;
  274 + }
  275 +
  276 + __block NSURLSessionDataTask *dataTask = nil;
  277 + dataTask = [self dataTaskWithRequest:request
  278 + uploadProgress:uploadProgress
  279 + downloadProgress:downloadProgress
  280 + completionHandler:^(NSURLResponse * __unused response, id responseObject, NSError *error) {
  281 + if (error) {
  282 + if (failure) {
  283 + failure(dataTask, error);
  284 + }
  285 + } else {
  286 + if (success) {
  287 + success(dataTask, responseObject);
  288 + }
  289 + }
  290 + }];
  291 +
  292 + return dataTask;
  293 +}
  294 +
  295 +#pragma mark - NSObject
  296 +
  297 +- (NSString *)description {
  298 + return [NSString stringWithFormat:@"<%@: %p, baseURL: %@, session: %@, operationQueue: %@>", NSStringFromClass([self class]), self, [self.baseURL absoluteString], self.session, self.operationQueue];
  299 +}
  300 +
  301 +#pragma mark - NSSecureCoding
  302 +
  303 ++ (BOOL)supportsSecureCoding {
  304 + return YES;
  305 +}
  306 +
  307 +- (instancetype)initWithCoder:(NSCoder *)decoder {
  308 + NSURL *baseURL = [decoder decodeObjectOfClass:[NSURL class] forKey:NSStringFromSelector(@selector(baseURL))];
  309 + NSURLSessionConfiguration *configuration = [decoder decodeObjectOfClass:[NSURLSessionConfiguration class] forKey:@"sessionConfiguration"];
  310 + if (!configuration) {
  311 + NSString *configurationIdentifier = [decoder decodeObjectOfClass:[NSString class] forKey:@"identifier"];
  312 + if (configurationIdentifier) {
  313 + configuration = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:configurationIdentifier];
  314 + }
  315 + }
  316 +
  317 + self = [self initWithBaseURL:baseURL sessionConfiguration:configuration];
  318 + if (!self) {
  319 + return nil;
  320 + }
  321 +
  322 + self.requestSerializer = [decoder decodeObjectOfClass:[AFHTTPRequestSerializer class] forKey:NSStringFromSelector(@selector(requestSerializer))];
  323 + self.responseSerializer = [decoder decodeObjectOfClass:[AFHTTPResponseSerializer class] forKey:NSStringFromSelector(@selector(responseSerializer))];
  324 + AFSecurityPolicy *decodedPolicy = [decoder decodeObjectOfClass:[AFSecurityPolicy class] forKey:NSStringFromSelector(@selector(securityPolicy))];
  325 + if (decodedPolicy) {
  326 + self.securityPolicy = decodedPolicy;
  327 + }
  328 +
  329 + return self;
  330 +}
  331 +
  332 +- (void)encodeWithCoder:(NSCoder *)coder {
  333 + [super encodeWithCoder:coder];
  334 +
  335 + [coder encodeObject:self.baseURL forKey:NSStringFromSelector(@selector(baseURL))];
  336 + if ([self.session.configuration conformsToProtocol:@protocol(NSCoding)]) {
  337 + [coder encodeObject:self.session.configuration forKey:@"sessionConfiguration"];
  338 + } else {
  339 + [coder encodeObject:self.session.configuration.identifier forKey:@"identifier"];
  340 + }
  341 + [coder encodeObject:self.requestSerializer forKey:NSStringFromSelector(@selector(requestSerializer))];
  342 + [coder encodeObject:self.responseSerializer forKey:NSStringFromSelector(@selector(responseSerializer))];
  343 + [coder encodeObject:self.securityPolicy forKey:NSStringFromSelector(@selector(securityPolicy))];
  344 +}
  345 +
  346 +#pragma mark - NSCopying
  347 +
  348 +- (instancetype)copyWithZone:(NSZone *)zone {
  349 + AFHTTPSessionManager *HTTPClient = [[[self class] allocWithZone:zone] initWithBaseURL:self.baseURL sessionConfiguration:self.session.configuration];
  350 +
  351 + HTTPClient.requestSerializer = [self.requestSerializer copyWithZone:zone];
  352 + HTTPClient.responseSerializer = [self.responseSerializer copyWithZone:zone];
  353 + HTTPClient.securityPolicy = [self.securityPolicy copyWithZone:zone];
  354 + return HTTPClient;
  355 +}
  356 +
  357 +@end
... ...
Example/Pods/AFNetworking/AFNetworking/AFNetworkReachabilityManager.h 0 → 100644
  1 +// AFNetworkReachabilityManager.h
  2 +// Copyright (c) 2011–2016 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 +
  22 +#import <Foundation/Foundation.h>
  23 +
  24 +#if !TARGET_OS_WATCH
  25 +#import <SystemConfiguration/SystemConfiguration.h>
  26 +
  27 +typedef NS_ENUM(NSInteger, AFNetworkReachabilityStatus) {
  28 + AFNetworkReachabilityStatusUnknown = -1,
  29 + AFNetworkReachabilityStatusNotReachable = 0,
  30 + AFNetworkReachabilityStatusReachableViaWWAN = 1,
  31 + AFNetworkReachabilityStatusReachableViaWiFi = 2,
  32 +};
  33 +
  34 +NS_ASSUME_NONNULL_BEGIN
  35 +
  36 +/**
  37 + `AFNetworkReachabilityManager` monitors the reachability of domains, and addresses for both WWAN and WiFi network interfaces.
  38 +
  39 + Reachability can be used to determine background information about why a network operation failed, or to trigger a network operation retrying when a connection is established. It should not be used to prevent a user from initiating a network request, as it's possible that an initial request may be required to establish reachability.
  40 +
  41 + See Apple's Reachability Sample Code ( https://developer.apple.com/library/ios/samplecode/reachability/ )
  42 +
  43 + @warning Instances of `AFNetworkReachabilityManager` must be started with `-startMonitoring` before reachability status can be determined.
  44 + */
  45 +@interface AFNetworkReachabilityManager : NSObject
  46 +
  47 +/**
  48 + The current network reachability status.
  49 + */
  50 +@property (readonly, nonatomic, assign) AFNetworkReachabilityStatus networkReachabilityStatus;
  51 +
  52 +/**
  53 + Whether or not the network is currently reachable.
  54 + */
  55 +@property (readonly, nonatomic, assign, getter = isReachable) BOOL reachable;
  56 +
  57 +/**
  58 + Whether or not the network is currently reachable via WWAN.
  59 + */
  60 +@property (readonly, nonatomic, assign, getter = isReachableViaWWAN) BOOL reachableViaWWAN;
  61 +
  62 +/**
  63 + Whether or not the network is currently reachable via WiFi.
  64 + */
  65 +@property (readonly, nonatomic, assign, getter = isReachableViaWiFi) BOOL reachableViaWiFi;
  66 +
  67 +///---------------------
  68 +/// @name Initialization
  69 +///---------------------
  70 +
  71 +/**
  72 + Returns the shared network reachability manager.
  73 + */
  74 ++ (instancetype)sharedManager;
  75 +
  76 +/**
  77 + Creates and returns a network reachability manager with the default socket address.
  78 +
  79 + @return An initialized network reachability manager, actively monitoring the default socket address.
  80 + */
  81 ++ (instancetype)manager;
  82 +
  83 +/**
  84 + Creates and returns a network reachability manager for the specified domain.
  85 +
  86 + @param domain The domain used to evaluate network reachability.
  87 +
  88 + @return An initialized network reachability manager, actively monitoring the specified domain.
  89 + */
  90 ++ (instancetype)managerForDomain:(NSString *)domain;
  91 +
  92 +/**
  93 + Creates and returns a network reachability manager for the socket address.
  94 +
  95 + @param address The socket address (`sockaddr_in6`) used to evaluate network reachability.
  96 +
  97 + @return An initialized network reachability manager, actively monitoring the specified socket address.
  98 + */
  99 ++ (instancetype)managerForAddress:(const void *)address;
  100 +
  101 +/**
  102 + Initializes an instance of a network reachability manager from the specified reachability object.
  103 +
  104 + @param reachability The reachability object to monitor.
  105 +
  106 + @return An initialized network reachability manager, actively monitoring the specified reachability.
  107 + */
  108 +- (instancetype)initWithReachability:(SCNetworkReachabilityRef)reachability NS_DESIGNATED_INITIALIZER;
  109 +
  110 +/**
  111 + * Unavailable initializer
  112 + */
  113 ++ (instancetype)new NS_UNAVAILABLE;
  114 +
  115 +/**
  116 + * Unavailable initializer
  117 + */
  118 +- (instancetype)init NS_UNAVAILABLE;
  119 +
  120 +///--------------------------------------------------
  121 +/// @name Starting & Stopping Reachability Monitoring
  122 +///--------------------------------------------------
  123 +
  124 +/**
  125 + Starts monitoring for changes in network reachability status.
  126 + */
  127 +- (void)startMonitoring;
  128 +
  129 +/**
  130 + Stops monitoring for changes in network reachability status.
  131 + */
  132 +- (void)stopMonitoring;
  133 +
  134 +///-------------------------------------------------
  135 +/// @name Getting Localized Reachability Description
  136 +///-------------------------------------------------
  137 +
  138 +/**
  139 + Returns a localized string representation of the current network reachability status.
  140 + */
  141 +- (NSString *)localizedNetworkReachabilityStatusString;
  142 +
  143 +///---------------------------------------------------
  144 +/// @name Setting Network Reachability Change Callback
  145 +///---------------------------------------------------
  146 +
  147 +/**
  148 + Sets a callback to be executed when the network availability of the `baseURL` host changes.
  149 +
  150 + @param block A block object to be executed when the network availability of the `baseURL` host changes.. This block has no return value and takes a single argument which represents the various reachability states from the device to the `baseURL`.
  151 + */
  152 +- (void)setReachabilityStatusChangeBlock:(nullable void (^)(AFNetworkReachabilityStatus status))block;
  153 +
  154 +@end
  155 +
  156 +///----------------
  157 +/// @name Constants
  158 +///----------------
  159 +
  160 +/**
  161 + ## Network Reachability
  162 +
  163 + The following constants are provided by `AFNetworkReachabilityManager` as possible network reachability statuses.
  164 +
  165 + enum {
  166 + AFNetworkReachabilityStatusUnknown,
  167 + AFNetworkReachabilityStatusNotReachable,
  168 + AFNetworkReachabilityStatusReachableViaWWAN,
  169 + AFNetworkReachabilityStatusReachableViaWiFi,
  170 + }
  171 +
  172 + `AFNetworkReachabilityStatusUnknown`
  173 + The `baseURL` host reachability is not known.
  174 +
  175 + `AFNetworkReachabilityStatusNotReachable`
  176 + The `baseURL` host cannot be reached.
  177 +
  178 + `AFNetworkReachabilityStatusReachableViaWWAN`
  179 + The `baseURL` host can be reached via a cellular connection, such as EDGE or GPRS.
  180 +
  181 + `AFNetworkReachabilityStatusReachableViaWiFi`
  182 + The `baseURL` host can be reached via a Wi-Fi connection.
  183 +
  184 + ### Keys for Notification UserInfo Dictionary
  185 +
  186 + Strings that are used as keys in a `userInfo` dictionary in a network reachability status change notification.
  187 +
  188 + `AFNetworkingReachabilityNotificationStatusItem`
  189 + A key in the userInfo dictionary in a `AFNetworkingReachabilityDidChangeNotification` notification.
  190 + The corresponding value is an `NSNumber` object representing the `AFNetworkReachabilityStatus` value for the current reachability status.
  191 + */
  192 +
  193 +///--------------------
  194 +/// @name Notifications
  195 +///--------------------
  196 +
  197 +/**
  198 + Posted when network reachability changes.
  199 + This notification assigns no notification object. The `userInfo` dictionary contains an `NSNumber` object under the `AFNetworkingReachabilityNotificationStatusItem` key, representing the `AFNetworkReachabilityStatus` value for the current network reachability.
  200 +
  201 + @warning In order for network reachability to be monitored, include the `SystemConfiguration` framework in the active target's "Link Binary With Library" build phase, and add `#import <SystemConfiguration/SystemConfiguration.h>` to the header prefix of the project (`Prefix.pch`).
  202 + */
  203 +FOUNDATION_EXPORT NSString * const AFNetworkingReachabilityDidChangeNotification;
  204 +FOUNDATION_EXPORT NSString * const AFNetworkingReachabilityNotificationStatusItem;
  205 +
  206 +///--------------------
  207 +/// @name Functions
  208 +///--------------------
  209 +
  210 +/**
  211 + Returns a localized string representation of an `AFNetworkReachabilityStatus` value.
  212 + */
  213 +FOUNDATION_EXPORT NSString * AFStringFromNetworkReachabilityStatus(AFNetworkReachabilityStatus status);
  214 +
  215 +NS_ASSUME_NONNULL_END
  216 +#endif
... ...
Example/Pods/AFNetworking/AFNetworking/AFNetworkReachabilityManager.m 0 → 100644
  1 +// AFNetworkReachabilityManager.m
  2 +// Copyright (c) 2011–2016 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 +
  22 +#import "AFNetworkReachabilityManager.h"
  23 +#if !TARGET_OS_WATCH
  24 +
  25 +#import <netinet/in.h>
  26 +#import <netinet6/in6.h>
  27 +#import <arpa/inet.h>
  28 +#import <ifaddrs.h>
  29 +#import <netdb.h>
  30 +
  31 +NSString * const AFNetworkingReachabilityDidChangeNotification = @"com.alamofire.networking.reachability.change";
  32 +NSString * const AFNetworkingReachabilityNotificationStatusItem = @"AFNetworkingReachabilityNotificationStatusItem";
  33 +
  34 +typedef void (^AFNetworkReachabilityStatusBlock)(AFNetworkReachabilityStatus status);
  35 +typedef AFNetworkReachabilityManager * (^AFNetworkReachabilityStatusCallback)(AFNetworkReachabilityStatus status);
  36 +
  37 +NSString * AFStringFromNetworkReachabilityStatus(AFNetworkReachabilityStatus status) {
  38 + switch (status) {
  39 + case AFNetworkReachabilityStatusNotReachable:
  40 + return NSLocalizedStringFromTable(@"Not Reachable", @"AFNetworking", nil);
  41 + case AFNetworkReachabilityStatusReachableViaWWAN:
  42 + return NSLocalizedStringFromTable(@"Reachable via WWAN", @"AFNetworking", nil);
  43 + case AFNetworkReachabilityStatusReachableViaWiFi:
  44 + return NSLocalizedStringFromTable(@"Reachable via WiFi", @"AFNetworking", nil);
  45 + case AFNetworkReachabilityStatusUnknown:
  46 + default:
  47 + return NSLocalizedStringFromTable(@"Unknown", @"AFNetworking", nil);
  48 + }
  49 +}
  50 +
  51 +static AFNetworkReachabilityStatus AFNetworkReachabilityStatusForFlags(SCNetworkReachabilityFlags flags) {
  52 + BOOL isReachable = ((flags & kSCNetworkReachabilityFlagsReachable) != 0);
  53 + BOOL needsConnection = ((flags & kSCNetworkReachabilityFlagsConnectionRequired) != 0);
  54 + BOOL canConnectionAutomatically = (((flags & kSCNetworkReachabilityFlagsConnectionOnDemand ) != 0) || ((flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) != 0));
  55 + BOOL canConnectWithoutUserInteraction = (canConnectionAutomatically && (flags & kSCNetworkReachabilityFlagsInterventionRequired) == 0);
  56 + BOOL isNetworkReachable = (isReachable && (!needsConnection || canConnectWithoutUserInteraction));
  57 +
  58 + AFNetworkReachabilityStatus status = AFNetworkReachabilityStatusUnknown;
  59 + if (isNetworkReachable == NO) {
  60 + status = AFNetworkReachabilityStatusNotReachable;
  61 + }
  62 +#if TARGET_OS_IPHONE
  63 + else if ((flags & kSCNetworkReachabilityFlagsIsWWAN) != 0) {
  64 + status = AFNetworkReachabilityStatusReachableViaWWAN;
  65 + }
  66 +#endif
  67 + else {
  68 + status = AFNetworkReachabilityStatusReachableViaWiFi;
  69 + }
  70 +
  71 + return status;
  72 +}
  73 +
  74 +/**
  75 + * Queue a status change notification for the main thread.
  76 + *
  77 + * This is done to ensure that the notifications are received in the same order
  78 + * as they are sent. If notifications are sent directly, it is possible that
  79 + * a queued notification (for an earlier status condition) is processed after
  80 + * the later update, resulting in the listener being left in the wrong state.
  81 + */
  82 +static void AFPostReachabilityStatusChange(SCNetworkReachabilityFlags flags, AFNetworkReachabilityStatusCallback block) {
  83 + AFNetworkReachabilityStatus status = AFNetworkReachabilityStatusForFlags(flags);
  84 + dispatch_async(dispatch_get_main_queue(), ^{
  85 + AFNetworkReachabilityManager *manager = nil;
  86 + if (block) {
  87 + manager = block(status);
  88 + }
  89 + NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
  90 + NSDictionary *userInfo = @{ AFNetworkingReachabilityNotificationStatusItem: @(status) };
  91 + [notificationCenter postNotificationName:AFNetworkingReachabilityDidChangeNotification object:manager userInfo:userInfo];
  92 + });
  93 +}
  94 +
  95 +static void AFNetworkReachabilityCallback(SCNetworkReachabilityRef __unused target, SCNetworkReachabilityFlags flags, void *info) {
  96 + AFPostReachabilityStatusChange(flags, (__bridge AFNetworkReachabilityStatusCallback)info);
  97 +}
  98 +
  99 +
  100 +static const void * AFNetworkReachabilityRetainCallback(const void *info) {
  101 + return Block_copy(info);
  102 +}
  103 +
  104 +static void AFNetworkReachabilityReleaseCallback(const void *info) {
  105 + if (info) {
  106 + Block_release(info);
  107 + }
  108 +}
  109 +
  110 +@interface AFNetworkReachabilityManager ()
  111 +@property (readonly, nonatomic, assign) SCNetworkReachabilityRef networkReachability;
  112 +@property (readwrite, nonatomic, assign) AFNetworkReachabilityStatus networkReachabilityStatus;
  113 +@property (readwrite, nonatomic, copy) AFNetworkReachabilityStatusBlock networkReachabilityStatusBlock;
  114 +@end
  115 +
  116 +@implementation AFNetworkReachabilityManager
  117 +
  118 ++ (instancetype)sharedManager {
  119 + static AFNetworkReachabilityManager *_sharedManager = nil;
  120 + static dispatch_once_t onceToken;
  121 + dispatch_once(&onceToken, ^{
  122 + _sharedManager = [self manager];
  123 + });
  124 +
  125 + return _sharedManager;
  126 +}
  127 +
  128 ++ (instancetype)managerForDomain:(NSString *)domain {
  129 + SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(kCFAllocatorDefault, [domain UTF8String]);
  130 +
  131 + AFNetworkReachabilityManager *manager = [[self alloc] initWithReachability:reachability];
  132 +
  133 + CFRelease(reachability);
  134 +
  135 + return manager;
  136 +}
  137 +
  138 ++ (instancetype)managerForAddress:(const void *)address {
  139 + SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr *)address);
  140 + AFNetworkReachabilityManager *manager = [[self alloc] initWithReachability:reachability];
  141 +
  142 + CFRelease(reachability);
  143 +
  144 + return manager;
  145 +}
  146 +
  147 ++ (instancetype)manager
  148 +{
  149 +#if (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 90000) || (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100)
  150 + struct sockaddr_in6 address;
  151 + bzero(&address, sizeof(address));
  152 + address.sin6_len = sizeof(address);
  153 + address.sin6_family = AF_INET6;
  154 +#else
  155 + struct sockaddr_in address;
  156 + bzero(&address, sizeof(address));
  157 + address.sin_len = sizeof(address);
  158 + address.sin_family = AF_INET;
  159 +#endif
  160 + return [self managerForAddress:&address];
  161 +}
  162 +
  163 +- (instancetype)initWithReachability:(SCNetworkReachabilityRef)reachability {
  164 + self = [super init];
  165 + if (!self) {
  166 + return nil;
  167 + }
  168 +
  169 + _networkReachability = CFRetain(reachability);
  170 + self.networkReachabilityStatus = AFNetworkReachabilityStatusUnknown;
  171 +
  172 + return self;
  173 +}
  174 +
  175 +- (instancetype)init
  176 +{
  177 + @throw [NSException exceptionWithName:NSGenericException
  178 + reason:@"`-init` unavailable. Use `-initWithReachability:` instead"
  179 + userInfo:nil];
  180 + return nil;
  181 +}
  182 +
  183 +- (void)dealloc {
  184 + [self stopMonitoring];
  185 +
  186 + if (_networkReachability != NULL) {
  187 + CFRelease(_networkReachability);
  188 + }
  189 +}
  190 +
  191 +#pragma mark -
  192 +
  193 +- (BOOL)isReachable {
  194 + return [self isReachableViaWWAN] || [self isReachableViaWiFi];
  195 +}
  196 +
  197 +- (BOOL)isReachableViaWWAN {
  198 + return self.networkReachabilityStatus == AFNetworkReachabilityStatusReachableViaWWAN;
  199 +}
  200 +
  201 +- (BOOL)isReachableViaWiFi {
  202 + return self.networkReachabilityStatus == AFNetworkReachabilityStatusReachableViaWiFi;
  203 +}
  204 +
  205 +#pragma mark -
  206 +
  207 +- (void)startMonitoring {
  208 + [self stopMonitoring];
  209 +
  210 + if (!self.networkReachability) {
  211 + return;
  212 + }
  213 +
  214 + __weak __typeof(self)weakSelf = self;
  215 + AFNetworkReachabilityStatusCallback callback = ^(AFNetworkReachabilityStatus status) {
  216 + __strong __typeof(weakSelf)strongSelf = weakSelf;
  217 +
  218 + strongSelf.networkReachabilityStatus = status;
  219 + if (strongSelf.networkReachabilityStatusBlock) {
  220 + strongSelf.networkReachabilityStatusBlock(status);
  221 + }
  222 +
  223 + return strongSelf;
  224 + };
  225 +
  226 + SCNetworkReachabilityContext context = {0, (__bridge void *)callback, AFNetworkReachabilityRetainCallback, AFNetworkReachabilityReleaseCallback, NULL};
  227 + SCNetworkReachabilitySetCallback(self.networkReachability, AFNetworkReachabilityCallback, &context);
  228 + SCNetworkReachabilityScheduleWithRunLoop(self.networkReachability, CFRunLoopGetMain(), kCFRunLoopCommonModes);
  229 +
  230 + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0),^{
  231 + SCNetworkReachabilityFlags flags;
  232 + if (SCNetworkReachabilityGetFlags(self.networkReachability, &flags)) {
  233 + AFPostReachabilityStatusChange(flags, callback);
  234 + }
  235 + });
  236 +}
  237 +
  238 +- (void)stopMonitoring {
  239 + if (!self.networkReachability) {
  240 + return;
  241 + }
  242 +
  243 + SCNetworkReachabilityUnscheduleFromRunLoop(self.networkReachability, CFRunLoopGetMain(), kCFRunLoopCommonModes);
  244 +}
  245 +
  246 +#pragma mark -
  247 +
  248 +- (NSString *)localizedNetworkReachabilityStatusString {
  249 + return AFStringFromNetworkReachabilityStatus(self.networkReachabilityStatus);
  250 +}
  251 +
  252 +#pragma mark -
  253 +
  254 +- (void)setReachabilityStatusChangeBlock:(void (^)(AFNetworkReachabilityStatus status))block {
  255 + self.networkReachabilityStatusBlock = block;
  256 +}
  257 +
  258 +#pragma mark - NSKeyValueObserving
  259 +
  260 ++ (NSSet *)keyPathsForValuesAffectingValueForKey:(NSString *)key {
  261 + if ([key isEqualToString:@"reachable"] || [key isEqualToString:@"reachableViaWWAN"] || [key isEqualToString:@"reachableViaWiFi"]) {
  262 + return [NSSet setWithObject:@"networkReachabilityStatus"];
  263 + }
  264 +
  265 + return [super keyPathsForValuesAffectingValueForKey:key];
  266 +}
  267 +
  268 +@end
  269 +#endif
... ...
Example/Pods/AFNetworking/AFNetworking/AFNetworking.h 0 → 100644
  1 +// AFNetworking.h
  2 +//
  3 +// Copyright (c) 2013 AFNetworking (http://afnetworking.com/)
  4 +//
  5 +// Permission is hereby granted, free of charge, to any person obtaining a copy
  6 +// of this software and associated documentation files (the "Software"), to deal
  7 +// in the Software without restriction, including without limitation the rights
  8 +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9 +// copies of the Software, and to permit persons to whom the Software is
  10 +// furnished to do so, subject to the following conditions:
  11 +//
  12 +// The above copyright notice and this permission notice shall be included in
  13 +// all copies or substantial portions of the Software.
  14 +//
  15 +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16 +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17 +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18 +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19 +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20 +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21 +// THE SOFTWARE.
  22 +
  23 +#import <Foundation/Foundation.h>
  24 +#import <Availability.h>
  25 +#import <TargetConditionals.h>
  26 +
  27 +#ifndef _AFNETWORKING_
  28 + #define _AFNETWORKING_
  29 +
  30 + #import "AFURLRequestSerialization.h"
  31 + #import "AFURLResponseSerialization.h"
  32 + #import "AFSecurityPolicy.h"
  33 +
  34 +#if !TARGET_OS_WATCH
  35 + #import "AFNetworkReachabilityManager.h"
  36 +#endif
  37 +
  38 + #import "AFURLSessionManager.h"
  39 + #import "AFHTTPSessionManager.h"
  40 +
  41 +#endif /* _AFNETWORKING_ */
... ...
Example/Pods/AFNetworking/AFNetworking/AFSecurityPolicy.h 0 → 100644
  1 +// AFSecurityPolicy.h
  2 +// Copyright (c) 2011–2016 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 +
  22 +#import <Foundation/Foundation.h>
  23 +#import <Security/Security.h>
  24 +
  25 +typedef NS_ENUM(NSUInteger, AFSSLPinningMode) {
  26 + AFSSLPinningModeNone,
  27 + AFSSLPinningModePublicKey,
  28 + AFSSLPinningModeCertificate,
  29 +};
  30 +
  31 +/**
  32 + `AFSecurityPolicy` evaluates server trust against pinned X.509 certificates and public keys over secure connections.
  33 +
  34 + Adding pinned SSL certificates to your app helps prevent man-in-the-middle attacks and other vulnerabilities. Applications dealing with sensitive customer data or financial information are strongly encouraged to route all communication over an HTTPS connection with SSL pinning configured and enabled.
  35 + */
  36 +
  37 +NS_ASSUME_NONNULL_BEGIN
  38 +
  39 +@interface AFSecurityPolicy : NSObject <NSSecureCoding, NSCopying>
  40 +
  41 +/**
  42 + The criteria by which server trust should be evaluated against the pinned SSL certificates. Defaults to `AFSSLPinningModeNone`.
  43 + */
  44 +@property (readonly, nonatomic, assign) AFSSLPinningMode SSLPinningMode;
  45 +
  46 +/**
  47 + The certificates used to evaluate server trust according to the SSL pinning mode.
  48 +
  49 + Note that if pinning is enabled, `evaluateServerTrust:forDomain:` will return true if any pinned certificate matches.
  50 +
  51 + @see policyWithPinningMode:withPinnedCertificates:
  52 + */
  53 +@property (nonatomic, strong, nullable) NSSet <NSData *> *pinnedCertificates;
  54 +
  55 +/**
  56 + Whether or not to trust servers with an invalid or expired SSL certificates. Defaults to `NO`.
  57 + */
  58 +@property (nonatomic, assign) BOOL allowInvalidCertificates;
  59 +
  60 +/**
  61 + Whether or not to validate the domain name in the certificate's CN field. Defaults to `YES`.
  62 + */
  63 +@property (nonatomic, assign) BOOL validatesDomainName;
  64 +
  65 +///-----------------------------------------
  66 +/// @name Getting Certificates from the Bundle
  67 +///-----------------------------------------
  68 +
  69 +/**
  70 + Returns any certificates included in the bundle. If you are using AFNetworking as an embedded framework, you must use this method to find the certificates you have included in your app bundle, and use them when creating your security policy by calling `policyWithPinningMode:withPinnedCertificates`.
  71 +
  72 + @return The certificates included in the given bundle.
  73 + */
  74 ++ (NSSet <NSData *> *)certificatesInBundle:(NSBundle *)bundle;
  75 +
  76 +///-----------------------------------------
  77 +/// @name Getting Specific Security Policies
  78 +///-----------------------------------------
  79 +
  80 +/**
  81 + Returns the shared default security policy, which does not allow invalid certificates, validates domain name, and does not validate against pinned certificates or public keys.
  82 +
  83 + @return The default security policy.
  84 + */
  85 ++ (instancetype)defaultPolicy;
  86 +
  87 +///---------------------
  88 +/// @name Initialization
  89 +///---------------------
  90 +
  91 +/**
  92 + Creates and returns a security policy with the specified pinning mode.
  93 +
  94 + Certificates with the `.cer` extension found in the main bundle will be pinned. If you want more control over which certificates are pinned, please use `policyWithPinningMode:withPinnedCertificates:` instead.
  95 +
  96 + @param pinningMode The SSL pinning mode.
  97 +
  98 + @return A new security policy.
  99 +
  100 + @see -policyWithPinningMode:withPinnedCertificates:
  101 + */
  102 ++ (instancetype)policyWithPinningMode:(AFSSLPinningMode)pinningMode;
  103 +
  104 +/**
  105 + Creates and returns a security policy with the specified pinning mode.
  106 +
  107 + @param pinningMode The SSL pinning mode.
  108 + @param pinnedCertificates The certificates to pin against.
  109 +
  110 + @return A new security policy.
  111 +
  112 + @see +certificatesInBundle:
  113 + @see -pinnedCertificates
  114 +*/
  115 ++ (instancetype)policyWithPinningMode:(AFSSLPinningMode)pinningMode withPinnedCertificates:(NSSet <NSData *> *)pinnedCertificates;
  116 +
  117 +///------------------------------
  118 +/// @name Evaluating Server Trust
  119 +///------------------------------
  120 +
  121 +/**
  122 + Whether or not the specified server trust should be accepted, based on the security policy.
  123 +
  124 + This method should be used when responding to an authentication challenge from a server.
  125 +
  126 + @param serverTrust The X.509 certificate trust of the server.
  127 + @param domain The domain of serverTrust. If `nil`, the domain will not be validated.
  128 +
  129 + @return Whether or not to trust the server.
  130 + */
  131 +- (BOOL)evaluateServerTrust:(SecTrustRef)serverTrust
  132 + forDomain:(nullable NSString *)domain;
  133 +
  134 +@end
  135 +
  136 +NS_ASSUME_NONNULL_END
  137 +
  138 +///----------------
  139 +/// @name Constants
  140 +///----------------
  141 +
  142 +/**
  143 + ## SSL Pinning Modes
  144 +
  145 + The following constants are provided by `AFSSLPinningMode` as possible SSL pinning modes.
  146 +
  147 + enum {
  148 + AFSSLPinningModeNone,
  149 + AFSSLPinningModePublicKey,
  150 + AFSSLPinningModeCertificate,
  151 + }
  152 +
  153 + `AFSSLPinningModeNone`
  154 + Do not used pinned certificates to validate servers.
  155 +
  156 + `AFSSLPinningModePublicKey`
  157 + Validate host certificates against public keys of pinned certificates.
  158 +
  159 + `AFSSLPinningModeCertificate`
  160 + Validate host certificates against pinned certificates.
  161 +*/
... ...
Example/Pods/AFNetworking/AFNetworking/AFSecurityPolicy.m 0 → 100644
  1 +// AFSecurityPolicy.m
  2 +// Copyright (c) 2011–2016 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 +
  22 +#import "AFSecurityPolicy.h"
  23 +
  24 +#import <AssertMacros.h>
  25 +
  26 +#if !TARGET_OS_IOS && !TARGET_OS_WATCH && !TARGET_OS_TV
  27 +static NSData * AFSecKeyGetData(SecKeyRef key) {
  28 + CFDataRef data = NULL;
  29 +
  30 + __Require_noErr_Quiet(SecItemExport(key, kSecFormatUnknown, kSecItemPemArmour, NULL, &data), _out);
  31 +
  32 + return (__bridge_transfer NSData *)data;
  33 +
  34 +_out:
  35 + if (data) {
  36 + CFRelease(data);
  37 + }
  38 +
  39 + return nil;
  40 +}
  41 +#endif
  42 +
  43 +static BOOL AFSecKeyIsEqualToKey(SecKeyRef key1, SecKeyRef key2) {
  44 +#if TARGET_OS_IOS || TARGET_OS_WATCH || TARGET_OS_TV
  45 + return [(__bridge id)key1 isEqual:(__bridge id)key2];
  46 +#else
  47 + return [AFSecKeyGetData(key1) isEqual:AFSecKeyGetData(key2)];
  48 +#endif
  49 +}
  50 +
  51 +static id AFPublicKeyForCertificate(NSData *certificate) {
  52 + id allowedPublicKey = nil;
  53 + SecCertificateRef allowedCertificate;
  54 + SecPolicyRef policy = nil;
  55 + SecTrustRef allowedTrust = nil;
  56 + SecTrustResultType result;
  57 +
  58 + allowedCertificate = SecCertificateCreateWithData(NULL, (__bridge CFDataRef)certificate);
  59 + __Require_Quiet(allowedCertificate != NULL, _out);
  60 +
  61 + policy = SecPolicyCreateBasicX509();
  62 + __Require_noErr_Quiet(SecTrustCreateWithCertificates(allowedCertificate, policy, &allowedTrust), _out);
  63 +#pragma clang diagnostic push
  64 +#pragma clang diagnostic ignored "-Wdeprecated-declarations"
  65 + __Require_noErr_Quiet(SecTrustEvaluate(allowedTrust, &result), _out);
  66 +#pragma clang diagnostic pop
  67 +
  68 + allowedPublicKey = (__bridge_transfer id)SecTrustCopyPublicKey(allowedTrust);
  69 +
  70 +_out:
  71 + if (allowedTrust) {
  72 + CFRelease(allowedTrust);
  73 + }
  74 +
  75 + if (policy) {
  76 + CFRelease(policy);
  77 + }
  78 +
  79 + if (allowedCertificate) {
  80 + CFRelease(allowedCertificate);
  81 + }
  82 +
  83 + return allowedPublicKey;
  84 +}
  85 +
  86 +static BOOL AFServerTrustIsValid(SecTrustRef serverTrust) {
  87 + BOOL isValid = NO;
  88 + SecTrustResultType result;
  89 +#pragma clang diagnostic push
  90 +#pragma clang diagnostic ignored "-Wdeprecated-declarations"
  91 + __Require_noErr_Quiet(SecTrustEvaluate(serverTrust, &result), _out);
  92 +#pragma clang diagnostic pop
  93 +
  94 + isValid = (result == kSecTrustResultUnspecified || result == kSecTrustResultProceed);
  95 +
  96 +_out:
  97 + return isValid;
  98 +}
  99 +
  100 +static NSArray * AFCertificateTrustChainForServerTrust(SecTrustRef serverTrust) {
  101 + CFIndex certificateCount = SecTrustGetCertificateCount(serverTrust);
  102 + NSMutableArray *trustChain = [NSMutableArray arrayWithCapacity:(NSUInteger)certificateCount];
  103 +
  104 + for (CFIndex i = 0; i < certificateCount; i++) {
  105 + SecCertificateRef certificate = SecTrustGetCertificateAtIndex(serverTrust, i);
  106 + [trustChain addObject:(__bridge_transfer NSData *)SecCertificateCopyData(certificate)];
  107 + }
  108 +
  109 + return [NSArray arrayWithArray:trustChain];
  110 +}
  111 +
  112 +static NSArray * AFPublicKeyTrustChainForServerTrust(SecTrustRef serverTrust) {
  113 + SecPolicyRef policy = SecPolicyCreateBasicX509();
  114 + CFIndex certificateCount = SecTrustGetCertificateCount(serverTrust);
  115 + NSMutableArray *trustChain = [NSMutableArray arrayWithCapacity:(NSUInteger)certificateCount];
  116 + for (CFIndex i = 0; i < certificateCount; i++) {
  117 + SecCertificateRef certificate = SecTrustGetCertificateAtIndex(serverTrust, i);
  118 +
  119 + SecCertificateRef someCertificates[] = {certificate};
  120 + CFArrayRef certificates = CFArrayCreate(NULL, (const void **)someCertificates, 1, NULL);
  121 +
  122 + SecTrustRef trust;
  123 + __Require_noErr_Quiet(SecTrustCreateWithCertificates(certificates, policy, &trust), _out);
  124 + SecTrustResultType result;
  125 +#pragma clang diagnostic push
  126 +#pragma clang diagnostic ignored "-Wdeprecated-declarations"
  127 + __Require_noErr_Quiet(SecTrustEvaluate(trust, &result), _out);
  128 +#pragma clang diagnostic pop
  129 + [trustChain addObject:(__bridge_transfer id)SecTrustCopyPublicKey(trust)];
  130 +
  131 + _out:
  132 + if (trust) {
  133 + CFRelease(trust);
  134 + }
  135 +
  136 + if (certificates) {
  137 + CFRelease(certificates);
  138 + }
  139 +
  140 + continue;
  141 + }
  142 + CFRelease(policy);
  143 +
  144 + return [NSArray arrayWithArray:trustChain];
  145 +}
  146 +
  147 +#pragma mark -
  148 +
  149 +@interface AFSecurityPolicy()
  150 +@property (readwrite, nonatomic, assign) AFSSLPinningMode SSLPinningMode;
  151 +@property (readwrite, nonatomic, strong) NSSet *pinnedPublicKeys;
  152 +@end
  153 +
  154 +@implementation AFSecurityPolicy
  155 +
  156 ++ (NSSet *)certificatesInBundle:(NSBundle *)bundle {
  157 + NSArray *paths = [bundle pathsForResourcesOfType:@"cer" inDirectory:@"."];
  158 +
  159 + NSMutableSet *certificates = [NSMutableSet setWithCapacity:[paths count]];
  160 + for (NSString *path in paths) {
  161 + NSData *certificateData = [NSData dataWithContentsOfFile:path];
  162 + [certificates addObject:certificateData];
  163 + }
  164 +
  165 + return [NSSet setWithSet:certificates];
  166 +}
  167 +
  168 ++ (instancetype)defaultPolicy {
  169 + AFSecurityPolicy *securityPolicy = [[self alloc] init];
  170 + securityPolicy.SSLPinningMode = AFSSLPinningModeNone;
  171 +
  172 + return securityPolicy;
  173 +}
  174 +
  175 ++ (instancetype)policyWithPinningMode:(AFSSLPinningMode)pinningMode {
  176 + NSSet <NSData *> *defaultPinnedCertificates = [self certificatesInBundle:[NSBundle mainBundle]];
  177 + return [self policyWithPinningMode:pinningMode withPinnedCertificates:defaultPinnedCertificates];
  178 +}
  179 +
  180 ++ (instancetype)policyWithPinningMode:(AFSSLPinningMode)pinningMode withPinnedCertificates:(NSSet *)pinnedCertificates {
  181 + AFSecurityPolicy *securityPolicy = [[self alloc] init];
  182 + securityPolicy.SSLPinningMode = pinningMode;
  183 +
  184 + [securityPolicy setPinnedCertificates:pinnedCertificates];
  185 +
  186 + return securityPolicy;
  187 +}
  188 +
  189 +- (instancetype)init {
  190 + self = [super init];
  191 + if (!self) {
  192 + return nil;
  193 + }
  194 +
  195 + self.validatesDomainName = YES;
  196 +
  197 + return self;
  198 +}
  199 +
  200 +- (void)setPinnedCertificates:(NSSet *)pinnedCertificates {
  201 + _pinnedCertificates = pinnedCertificates;
  202 +
  203 + if (self.pinnedCertificates) {
  204 + NSMutableSet *mutablePinnedPublicKeys = [NSMutableSet setWithCapacity:[self.pinnedCertificates count]];
  205 + for (NSData *certificate in self.pinnedCertificates) {
  206 + id publicKey = AFPublicKeyForCertificate(certificate);
  207 + if (!publicKey) {
  208 + continue;
  209 + }
  210 + [mutablePinnedPublicKeys addObject:publicKey];
  211 + }
  212 + self.pinnedPublicKeys = [NSSet setWithSet:mutablePinnedPublicKeys];
  213 + } else {
  214 + self.pinnedPublicKeys = nil;
  215 + }
  216 +}
  217 +
  218 +#pragma mark -
  219 +
  220 +- (BOOL)evaluateServerTrust:(SecTrustRef)serverTrust
  221 + forDomain:(NSString *)domain
  222 +{
  223 + if (domain && self.allowInvalidCertificates && self.validatesDomainName && (self.SSLPinningMode == AFSSLPinningModeNone || [self.pinnedCertificates count] == 0)) {
  224 + // https://developer.apple.com/library/mac/documentation/NetworkingInternet/Conceptual/NetworkingTopics/Articles/OverridingSSLChainValidationCorrectly.html
  225 + // According to the docs, you should only trust your provided certs for evaluation.
  226 + // Pinned certificates are added to the trust. Without pinned certificates,
  227 + // there is nothing to evaluate against.
  228 + //
  229 + // From Apple Docs:
  230 + // "Do not implicitly trust self-signed certificates as anchors (kSecTrustOptionImplicitAnchors).
  231 + // Instead, add your own (self-signed) CA certificate to the list of trusted anchors."
  232 + NSLog(@"In order to validate a domain name for self signed certificates, you MUST use pinning.");
  233 + return NO;
  234 + }
  235 +
  236 + NSMutableArray *policies = [NSMutableArray array];
  237 + if (self.validatesDomainName) {
  238 + [policies addObject:(__bridge_transfer id)SecPolicyCreateSSL(true, (__bridge CFStringRef)domain)];
  239 + } else {
  240 + [policies addObject:(__bridge_transfer id)SecPolicyCreateBasicX509()];
  241 + }
  242 +
  243 + SecTrustSetPolicies(serverTrust, (__bridge CFArrayRef)policies);
  244 +
  245 + if (self.SSLPinningMode == AFSSLPinningModeNone) {
  246 + return self.allowInvalidCertificates || AFServerTrustIsValid(serverTrust);
  247 + } else if (!self.allowInvalidCertificates && !AFServerTrustIsValid(serverTrust)) {
  248 + return NO;
  249 + }
  250 +
  251 + switch (self.SSLPinningMode) {
  252 + case AFSSLPinningModeCertificate: {
  253 + NSMutableArray *pinnedCertificates = [NSMutableArray array];
  254 + for (NSData *certificateData in self.pinnedCertificates) {
  255 + [pinnedCertificates addObject:(__bridge_transfer id)SecCertificateCreateWithData(NULL, (__bridge CFDataRef)certificateData)];
  256 + }
  257 + SecTrustSetAnchorCertificates(serverTrust, (__bridge CFArrayRef)pinnedCertificates);
  258 +
  259 + if (!AFServerTrustIsValid(serverTrust)) {
  260 + return NO;
  261 + }
  262 +
  263 + // obtain the chain after being validated, which *should* contain the pinned certificate in the last position (if it's the Root CA)
  264 + NSArray *serverCertificates = AFCertificateTrustChainForServerTrust(serverTrust);
  265 +
  266 + for (NSData *trustChainCertificate in [serverCertificates reverseObjectEnumerator]) {
  267 + if ([self.pinnedCertificates containsObject:trustChainCertificate]) {
  268 + return YES;
  269 + }
  270 + }
  271 +
  272 + return NO;
  273 + }
  274 + case AFSSLPinningModePublicKey: {
  275 + NSUInteger trustedPublicKeyCount = 0;
  276 + NSArray *publicKeys = AFPublicKeyTrustChainForServerTrust(serverTrust);
  277 +
  278 + for (id trustChainPublicKey in publicKeys) {
  279 + for (id pinnedPublicKey in self.pinnedPublicKeys) {
  280 + if (AFSecKeyIsEqualToKey((__bridge SecKeyRef)trustChainPublicKey, (__bridge SecKeyRef)pinnedPublicKey)) {
  281 + trustedPublicKeyCount += 1;
  282 + }
  283 + }
  284 + }
  285 + return trustedPublicKeyCount > 0;
  286 + }
  287 +
  288 + default:
  289 + return NO;
  290 + }
  291 +
  292 + return NO;
  293 +}
  294 +
  295 +#pragma mark - NSKeyValueObserving
  296 +
  297 ++ (NSSet *)keyPathsForValuesAffectingPinnedPublicKeys {
  298 + return [NSSet setWithObject:@"pinnedCertificates"];
  299 +}
  300 +
  301 +#pragma mark - NSSecureCoding
  302 +
  303 ++ (BOOL)supportsSecureCoding {
  304 + return YES;
  305 +}
  306 +
  307 +- (instancetype)initWithCoder:(NSCoder *)decoder {
  308 +
  309 + self = [self init];
  310 + if (!self) {
  311 + return nil;
  312 + }
  313 +
  314 + self.SSLPinningMode = [[decoder decodeObjectOfClass:[NSNumber class] forKey:NSStringFromSelector(@selector(SSLPinningMode))] unsignedIntegerValue];
  315 + self.allowInvalidCertificates = [decoder decodeBoolForKey:NSStringFromSelector(@selector(allowInvalidCertificates))];
  316 + self.validatesDomainName = [decoder decodeBoolForKey:NSStringFromSelector(@selector(validatesDomainName))];
  317 + self.pinnedCertificates = [decoder decodeObjectOfClass:[NSSet class] forKey:NSStringFromSelector(@selector(pinnedCertificates))];
  318 +
  319 + return self;
  320 +}
  321 +
  322 +- (void)encodeWithCoder:(NSCoder *)coder {
  323 + [coder encodeObject:[NSNumber numberWithUnsignedInteger:self.SSLPinningMode] forKey:NSStringFromSelector(@selector(SSLPinningMode))];
  324 + [coder encodeBool:self.allowInvalidCertificates forKey:NSStringFromSelector(@selector(allowInvalidCertificates))];
  325 + [coder encodeBool:self.validatesDomainName forKey:NSStringFromSelector(@selector(validatesDomainName))];
  326 + [coder encodeObject:self.pinnedCertificates forKey:NSStringFromSelector(@selector(pinnedCertificates))];
  327 +}
  328 +
  329 +#pragma mark - NSCopying
  330 +
  331 +- (instancetype)copyWithZone:(NSZone *)zone {
  332 + AFSecurityPolicy *securityPolicy = [[[self class] allocWithZone:zone] init];
  333 + securityPolicy.SSLPinningMode = self.SSLPinningMode;
  334 + securityPolicy.allowInvalidCertificates = self.allowInvalidCertificates;
  335 + securityPolicy.validatesDomainName = self.validatesDomainName;
  336 + securityPolicy.pinnedCertificates = [self.pinnedCertificates copyWithZone:zone];
  337 +
  338 + return securityPolicy;
  339 +}
  340 +
  341 +@end
... ...
Example/Pods/AFNetworking/AFNetworking/AFURLRequestSerialization.h 0 → 100644
  1 +// AFURLRequestSerialization.h
  2 +// Copyright (c) 2011–2016 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 +
  22 +#import <Foundation/Foundation.h>
  23 +#import <TargetConditionals.h>
  24 +
  25 +#if TARGET_OS_IOS || TARGET_OS_TV
  26 +#import <UIKit/UIKit.h>
  27 +#elif TARGET_OS_WATCH
  28 +#import <WatchKit/WatchKit.h>
  29 +#endif
  30 +
  31 +NS_ASSUME_NONNULL_BEGIN
  32 +
  33 +/**
  34 + Returns a percent-escaped string following RFC 3986 for a query string key or value.
  35 + RFC 3986 states that the following characters are "reserved" characters.
  36 + - General Delimiters: ":", "#", "[", "]", "@", "?", "/"
  37 + - Sub-Delimiters: "!", "$", "&", "'", "(", ")", "*", "+", ",", ";", "="
  38 +
  39 + In RFC 3986 - Section 3.4, it states that the "?" and "/" characters should not be escaped to allow
  40 + query strings to include a URL. Therefore, all "reserved" characters with the exception of "?" and "/"
  41 + should be percent-escaped in the query string.
  42 +
  43 + @param string The string to be percent-escaped.
  44 +
  45 + @return The percent-escaped string.
  46 + */
  47 +FOUNDATION_EXPORT NSString * AFPercentEscapedStringFromString(NSString *string);
  48 +
  49 +/**
  50 + A helper method to generate encoded url query parameters for appending to the end of a URL.
  51 +
  52 + @param parameters A dictionary of key/values to be encoded.
  53 +
  54 + @return A url encoded query string
  55 + */
  56 +FOUNDATION_EXPORT NSString * AFQueryStringFromParameters(NSDictionary *parameters);
  57 +
  58 +/**
  59 + The `AFURLRequestSerialization` protocol is adopted by an object that encodes parameters for a specified HTTP requests. Request serializers may encode parameters as query strings, HTTP bodies, setting the appropriate HTTP header fields as necessary.
  60 +
  61 + For example, a JSON request serializer may set the HTTP body of the request to a JSON representation, and set the `Content-Type` HTTP header field value to `application/json`.
  62 + */
  63 +@protocol AFURLRequestSerialization <NSObject, NSSecureCoding, NSCopying>
  64 +
  65 +/**
  66 + Returns a request with the specified parameters encoded into a copy of the original request.
  67 +
  68 + @param request The original request.
  69 + @param parameters The parameters to be encoded.
  70 + @param error The error that occurred while attempting to encode the request parameters.
  71 +
  72 + @return A serialized request.
  73 + */
  74 +- (nullable NSURLRequest *)requestBySerializingRequest:(NSURLRequest *)request
  75 + withParameters:(nullable id)parameters
  76 + error:(NSError * _Nullable __autoreleasing *)error NS_SWIFT_NOTHROW;
  77 +
  78 +@end
  79 +
  80 +#pragma mark -
  81 +
  82 +/**
  83 +
  84 + */
  85 +typedef NS_ENUM(NSUInteger, AFHTTPRequestQueryStringSerializationStyle) {
  86 + AFHTTPRequestQueryStringDefaultStyle = 0,
  87 +};
  88 +
  89 +@protocol AFMultipartFormData;
  90 +
  91 +/**
  92 + `AFHTTPRequestSerializer` conforms to the `AFURLRequestSerialization` & `AFURLResponseSerialization` protocols, offering a concrete base implementation of query string / URL form-encoded parameter serialization and default request headers, as well as response status code and content type validation.
  93 +
  94 + Any request or response serializer dealing with HTTP is encouraged to subclass `AFHTTPRequestSerializer` in order to ensure consistent default behavior.
  95 + */
  96 +@interface AFHTTPRequestSerializer : NSObject <AFURLRequestSerialization>
  97 +
  98 +/**
  99 + The string encoding used to serialize parameters. `NSUTF8StringEncoding` by default.
  100 + */
  101 +@property (nonatomic, assign) NSStringEncoding stringEncoding;
  102 +
  103 +/**
  104 + Whether created requests can use the device’s cellular radio (if present). `YES` by default.
  105 +
  106 + @see NSMutableURLRequest -setAllowsCellularAccess:
  107 + */
  108 +@property (nonatomic, assign) BOOL allowsCellularAccess;
  109 +
  110 +/**
  111 + The cache policy of created requests. `NSURLRequestUseProtocolCachePolicy` by default.
  112 +
  113 + @see NSMutableURLRequest -setCachePolicy:
  114 + */
  115 +@property (nonatomic, assign) NSURLRequestCachePolicy cachePolicy;
  116 +
  117 +/**
  118 + Whether created requests should use the default cookie handling. `YES` by default.
  119 +
  120 + @see NSMutableURLRequest -setHTTPShouldHandleCookies:
  121 + */
  122 +@property (nonatomic, assign) BOOL HTTPShouldHandleCookies;
  123 +
  124 +/**
  125 + Whether created requests can continue transmitting data before receiving a response from an earlier transmission. `NO` by default
  126 +
  127 + @see NSMutableURLRequest -setHTTPShouldUsePipelining:
  128 + */
  129 +@property (nonatomic, assign) BOOL HTTPShouldUsePipelining;
  130 +
  131 +/**
  132 + The network service type for created requests. `NSURLNetworkServiceTypeDefault` by default.
  133 +
  134 + @see NSMutableURLRequest -setNetworkServiceType:
  135 + */
  136 +@property (nonatomic, assign) NSURLRequestNetworkServiceType networkServiceType;
  137 +
  138 +/**
  139 + The timeout interval, in seconds, for created requests. The default timeout interval is 60 seconds.
  140 +
  141 + @see NSMutableURLRequest -setTimeoutInterval:
  142 + */
  143 +@property (nonatomic, assign) NSTimeInterval timeoutInterval;
  144 +
  145 +///---------------------------------------
  146 +/// @name Configuring HTTP Request Headers
  147 +///---------------------------------------
  148 +
  149 +/**
  150 + Default HTTP header field values to be applied to serialized requests. By default, these include the following:
  151 +
  152 + - `Accept-Language` with the contents of `NSLocale +preferredLanguages`
  153 + - `User-Agent` with the contents of various bundle identifiers and OS designations
  154 +
  155 + @discussion To add or remove default request headers, use `setValue:forHTTPHeaderField:`.
  156 + */
  157 +@property (readonly, nonatomic, strong) NSDictionary <NSString *, NSString *> *HTTPRequestHeaders;
  158 +
  159 +/**
  160 + Creates and returns a serializer with default configuration.
  161 + */
  162 ++ (instancetype)serializer;
  163 +
  164 +/**
  165 + Sets the value for the HTTP headers set in request objects made by the HTTP client. If `nil`, removes the existing value for that header.
  166 +
  167 + @param field The HTTP header to set a default value for
  168 + @param value The value set as default for the specified header, or `nil`
  169 + */
  170 +- (void)setValue:(nullable NSString *)value
  171 +forHTTPHeaderField:(NSString *)field;
  172 +
  173 +/**
  174 + Returns the value for the HTTP headers set in the request serializer.
  175 +
  176 + @param field The HTTP header to retrieve the default value for
  177 +
  178 + @return The value set as default for the specified header, or `nil`
  179 + */
  180 +- (nullable NSString *)valueForHTTPHeaderField:(NSString *)field;
  181 +
  182 +/**
  183 + Sets the "Authorization" HTTP header set in request objects made by the HTTP client to a basic authentication value with Base64-encoded username and password. This overwrites any existing value for this header.
  184 +
  185 + @param username The HTTP basic auth username
  186 + @param password The HTTP basic auth password
  187 + */
  188 +- (void)setAuthorizationHeaderFieldWithUsername:(NSString *)username
  189 + password:(NSString *)password;
  190 +
  191 +/**
  192 + Clears any existing value for the "Authorization" HTTP header.
  193 + */
  194 +- (void)clearAuthorizationHeader;
  195 +
  196 +///-------------------------------------------------------
  197 +/// @name Configuring Query String Parameter Serialization
  198 +///-------------------------------------------------------
  199 +
  200 +/**
  201 + HTTP methods for which serialized requests will encode parameters as a query string. `GET`, `HEAD`, and `DELETE` by default.
  202 + */
  203 +@property (nonatomic, strong) NSSet <NSString *> *HTTPMethodsEncodingParametersInURI;
  204 +
  205 +/**
  206 + Set the method of query string serialization according to one of the pre-defined styles.
  207 +
  208 + @param style The serialization style.
  209 +
  210 + @see AFHTTPRequestQueryStringSerializationStyle
  211 + */
  212 +- (void)setQueryStringSerializationWithStyle:(AFHTTPRequestQueryStringSerializationStyle)style;
  213 +
  214 +/**
  215 + Set the a custom method of query string serialization according to the specified block.
  216 +
  217 + @param block A block that defines a process of encoding parameters into a query string. This block returns the query string and takes three arguments: the request, the parameters to encode, and the error that occurred when attempting to encode parameters for the given request.
  218 + */
  219 +- (void)setQueryStringSerializationWithBlock:(nullable NSString * _Nullable (^)(NSURLRequest *request, id parameters, NSError * __autoreleasing *error))block;
  220 +
  221 +///-------------------------------
  222 +/// @name Creating Request Objects
  223 +///-------------------------------
  224 +
  225 +/**
  226 + Creates an `NSMutableURLRequest` object with the specified HTTP method and URL string.
  227 +
  228 + If the HTTP method is `GET`, `HEAD`, or `DELETE`, the parameters will be used to construct a url-encoded query string that is appended to the request's URL. Otherwise, the parameters will be encoded according to the value of the `parameterEncoding` property, and set as the request body.
  229 +
  230 + @param method The HTTP method for the request, such as `GET`, `POST`, `PUT`, or `DELETE`. This parameter must not be `nil`.
  231 + @param URLString The URL string used to create the request URL.
  232 + @param parameters The parameters to be either set as a query string for `GET` requests, or the request HTTP body.
  233 + @param error The error that occurred while constructing the request.
  234 +
  235 + @return An `NSMutableURLRequest` object.
  236 + */
  237 +- (nullable NSMutableURLRequest *)requestWithMethod:(NSString *)method
  238 + URLString:(NSString *)URLString
  239 + parameters:(nullable id)parameters
  240 + error:(NSError * _Nullable __autoreleasing *)error;
  241 +
  242 +/**
  243 + Creates an `NSMutableURLRequest` object with the specified HTTP method and URLString, and constructs a `multipart/form-data` HTTP body, using the specified parameters and multipart form data block. See http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4.2
  244 +
  245 + Multipart form requests are automatically streamed, reading files directly from disk along with in-memory data in a single HTTP body. The resulting `NSMutableURLRequest` object has an `HTTPBodyStream` property, so refrain from setting `HTTPBodyStream` or `HTTPBody` on this request object, as it will clear out the multipart form body stream.
  246 +
  247 + @param method The HTTP method for the request. This parameter must not be `GET` or `HEAD`, or `nil`.
  248 + @param URLString The URL string used to create the request URL.
  249 + @param parameters The parameters to be encoded and set in the request HTTP body.
  250 + @param block A block that takes a single argument and appends data to the HTTP body. The block argument is an object adopting the `AFMultipartFormData` protocol.
  251 + @param error The error that occurred while constructing the request.
  252 +
  253 + @return An `NSMutableURLRequest` object
  254 + */
  255 +- (NSMutableURLRequest *)multipartFormRequestWithMethod:(NSString *)method
  256 + URLString:(NSString *)URLString
  257 + parameters:(nullable NSDictionary <NSString *, id> *)parameters
  258 + constructingBodyWithBlock:(nullable void (^)(id <AFMultipartFormData> formData))block
  259 + error:(NSError * _Nullable __autoreleasing *)error;
  260 +
  261 +/**
  262 + Creates an `NSMutableURLRequest` by removing the `HTTPBodyStream` from a request, and asynchronously writing its contents into the specified file, invoking the completion handler when finished.
  263 +
  264 + @param request The multipart form request. The `HTTPBodyStream` property of `request` must not be `nil`.
  265 + @param fileURL The file URL to write multipart form contents to.
  266 + @param handler A handler block to execute.
  267 +
  268 + @discussion There is a bug in `NSURLSessionTask` that causes requests to not send a `Content-Length` header when streaming contents from an HTTP body, which is notably problematic when interacting with the Amazon S3 webservice. As a workaround, this method takes a request constructed with `multipartFormRequestWithMethod:URLString:parameters:constructingBodyWithBlock:error:`, or any other request with an `HTTPBodyStream`, writes the contents to the specified file and returns a copy of the original request with the `HTTPBodyStream` property set to `nil`. From here, the file can either be passed to `AFURLSessionManager -uploadTaskWithRequest:fromFile:progress:completionHandler:`, or have its contents read into an `NSData` that's assigned to the `HTTPBody` property of the request.
  269 +
  270 + @see https://github.com/AFNetworking/AFNetworking/issues/1398
  271 + */
  272 +- (NSMutableURLRequest *)requestWithMultipartFormRequest:(NSURLRequest *)request
  273 + writingStreamContentsToFile:(NSURL *)fileURL
  274 + completionHandler:(nullable void (^)(NSError * _Nullable error))handler;
  275 +
  276 +@end
  277 +
  278 +#pragma mark -
  279 +
  280 +/**
  281 + The `AFMultipartFormData` protocol defines the methods supported by the parameter in the block argument of `AFHTTPRequestSerializer -multipartFormRequestWithMethod:URLString:parameters:constructingBodyWithBlock:`.
  282 + */
  283 +@protocol AFMultipartFormData
  284 +
  285 +/**
  286 + Appends the HTTP header `Content-Disposition: file; filename=#{generated filename}; name=#{name}"` and `Content-Type: #{generated mimeType}`, followed by the encoded file data and the multipart form boundary.
  287 +
  288 + The filename and MIME type for this data in the form will be automatically generated, using the last path component of the `fileURL` and system associated MIME type for the `fileURL` extension, respectively.
  289 +
  290 + @param fileURL The URL corresponding to the file whose content will be appended to the form. This parameter must not be `nil`.
  291 + @param name The name to be associated with the specified data. This parameter must not be `nil`.
  292 + @param error If an error occurs, upon return contains an `NSError` object that describes the problem.
  293 +
  294 + @return `YES` if the file data was successfully appended, otherwise `NO`.
  295 + */
  296 +- (BOOL)appendPartWithFileURL:(NSURL *)fileURL
  297 + name:(NSString *)name
  298 + error:(NSError * _Nullable __autoreleasing *)error;
  299 +
  300 +/**
  301 + Appends the HTTP header `Content-Disposition: file; filename=#{filename}; name=#{name}"` and `Content-Type: #{mimeType}`, followed by the encoded file data and the multipart form boundary.
  302 +
  303 + @param fileURL The URL corresponding to the file whose content will be appended to the form. This parameter must not be `nil`.
  304 + @param name The name to be associated with the specified data. This parameter must not be `nil`.
  305 + @param fileName The file name to be used in the `Content-Disposition` header. This parameter must not be `nil`.
  306 + @param mimeType The declared MIME type of the file data. This parameter must not be `nil`.
  307 + @param error If an error occurs, upon return contains an `NSError` object that describes the problem.
  308 +
  309 + @return `YES` if the file data was successfully appended otherwise `NO`.
  310 + */
  311 +- (BOOL)appendPartWithFileURL:(NSURL *)fileURL
  312 + name:(NSString *)name
  313 + fileName:(NSString *)fileName
  314 + mimeType:(NSString *)mimeType
  315 + error:(NSError * _Nullable __autoreleasing *)error;
  316 +
  317 +/**
  318 + Appends the HTTP header `Content-Disposition: file; filename=#{filename}; name=#{name}"` and `Content-Type: #{mimeType}`, followed by the data from the input stream and the multipart form boundary.
  319 +
  320 + @param inputStream The input stream to be appended to the form data
  321 + @param name The name to be associated with the specified input stream. This parameter must not be `nil`.
  322 + @param fileName The filename to be associated with the specified input stream. This parameter must not be `nil`.
  323 + @param length The length of the specified input stream in bytes.
  324 + @param mimeType The MIME type of the specified data. (For example, the MIME type for a JPEG image is image/jpeg.) For a list of valid MIME types, see http://www.iana.org/assignments/media-types/. This parameter must not be `nil`.
  325 + */
  326 +- (void)appendPartWithInputStream:(nullable NSInputStream *)inputStream
  327 + name:(NSString *)name
  328 + fileName:(NSString *)fileName
  329 + length:(int64_t)length
  330 + mimeType:(NSString *)mimeType;
  331 +
  332 +/**
  333 + Appends the HTTP header `Content-Disposition: file; filename=#{filename}; name=#{name}"` and `Content-Type: #{mimeType}`, followed by the encoded file data and the multipart form boundary.
  334 +
  335 + @param data The data to be encoded and appended to the form data.
  336 + @param name The name to be associated with the specified data. This parameter must not be `nil`.
  337 + @param fileName The filename to be associated with the specified data. This parameter must not be `nil`.
  338 + @param mimeType The MIME type of the specified data. (For example, the MIME type for a JPEG image is image/jpeg.) For a list of valid MIME types, see http://www.iana.org/assignments/media-types/. This parameter must not be `nil`.
  339 + */
  340 +- (void)appendPartWithFileData:(NSData *)data
  341 + name:(NSString *)name
  342 + fileName:(NSString *)fileName
  343 + mimeType:(NSString *)mimeType;
  344 +
  345 +/**
  346 + Appends the HTTP headers `Content-Disposition: form-data; name=#{name}"`, followed by the encoded data and the multipart form boundary.
  347 +
  348 + @param data The data to be encoded and appended to the form data.
  349 + @param name The name to be associated with the specified data. This parameter must not be `nil`.
  350 + */
  351 +
  352 +- (void)appendPartWithFormData:(NSData *)data
  353 + name:(NSString *)name;
  354 +
  355 +
  356 +/**
  357 + Appends HTTP headers, followed by the encoded data and the multipart form boundary.
  358 +
  359 + @param headers The HTTP headers to be appended to the form data.
  360 + @param body The data to be encoded and appended to the form data. This parameter must not be `nil`.
  361 + */
  362 +- (void)appendPartWithHeaders:(nullable NSDictionary <NSString *, NSString *> *)headers
  363 + body:(NSData *)body;
  364 +
  365 +/**
  366 + Throttles request bandwidth by limiting the packet size and adding a delay for each chunk read from the upload stream.
  367 +
  368 + When uploading over a 3G or EDGE connection, requests may fail with "request body stream exhausted". Setting a maximum packet size and delay according to the recommended values (`kAFUploadStream3GSuggestedPacketSize` and `kAFUploadStream3GSuggestedDelay`) lowers the risk of the input stream exceeding its allocated bandwidth. Unfortunately, there is no definite way to distinguish between a 3G, EDGE, or LTE connection over `NSURLConnection`. As such, it is not recommended that you throttle bandwidth based solely on network reachability. Instead, you should consider checking for the "request body stream exhausted" in a failure block, and then retrying the request with throttled bandwidth.
  369 +
  370 + @param numberOfBytes Maximum packet size, in number of bytes. The default packet size for an input stream is 16kb.
  371 + @param delay Duration of delay each time a packet is read. By default, no delay is set.
  372 + */
  373 +- (void)throttleBandwidthWithPacketSize:(NSUInteger)numberOfBytes
  374 + delay:(NSTimeInterval)delay;
  375 +
  376 +@end
  377 +
  378 +#pragma mark -
  379 +
  380 +/**
  381 + `AFJSONRequestSerializer` is a subclass of `AFHTTPRequestSerializer` that encodes parameters as JSON using `NSJSONSerialization`, setting the `Content-Type` of the encoded request to `application/json`.
  382 + */
  383 +@interface AFJSONRequestSerializer : AFHTTPRequestSerializer
  384 +
  385 +/**
  386 + Options for writing the request JSON data from Foundation objects. For possible values, see the `NSJSONSerialization` documentation section "NSJSONWritingOptions". `0` by default.
  387 + */
  388 +@property (nonatomic, assign) NSJSONWritingOptions writingOptions;
  389 +
  390 +/**
  391 + Creates and returns a JSON serializer with specified reading and writing options.
  392 +
  393 + @param writingOptions The specified JSON writing options.
  394 + */
  395 ++ (instancetype)serializerWithWritingOptions:(NSJSONWritingOptions)writingOptions;
  396 +
  397 +@end
  398 +
  399 +#pragma mark -
  400 +
  401 +/**
  402 + `AFPropertyListRequestSerializer` is a subclass of `AFHTTPRequestSerializer` that encodes parameters as JSON using `NSPropertyListSerializer`, setting the `Content-Type` of the encoded request to `application/x-plist`.
  403 + */
  404 +@interface AFPropertyListRequestSerializer : AFHTTPRequestSerializer
  405 +
  406 +/**
  407 + The property list format. Possible values are described in "NSPropertyListFormat".
  408 + */
  409 +@property (nonatomic, assign) NSPropertyListFormat format;
  410 +
  411 +/**
  412 + @warning The `writeOptions` property is currently unused.
  413 + */
  414 +@property (nonatomic, assign) NSPropertyListWriteOptions writeOptions;
  415 +
  416 +/**
  417 + Creates and returns a property list serializer with a specified format, read options, and write options.
  418 +
  419 + @param format The property list format.
  420 + @param writeOptions The property list write options.
  421 +
  422 + @warning The `writeOptions` property is currently unused.
  423 + */
  424 ++ (instancetype)serializerWithFormat:(NSPropertyListFormat)format
  425 + writeOptions:(NSPropertyListWriteOptions)writeOptions;
  426 +
  427 +@end
  428 +
  429 +#pragma mark -
  430 +
  431 +///----------------
  432 +/// @name Constants
  433 +///----------------
  434 +
  435 +/**
  436 + ## Error Domains
  437 +
  438 + The following error domain is predefined.
  439 +
  440 + - `NSString * const AFURLRequestSerializationErrorDomain`
  441 +
  442 + ### Constants
  443 +
  444 + `AFURLRequestSerializationErrorDomain`
  445 + AFURLRequestSerializer errors. Error codes for `AFURLRequestSerializationErrorDomain` correspond to codes in `NSURLErrorDomain`.
  446 + */
  447 +FOUNDATION_EXPORT NSString * const AFURLRequestSerializationErrorDomain;
  448 +
  449 +/**
  450 + ## User info dictionary keys
  451 +
  452 + These keys may exist in the user info dictionary, in addition to those defined for NSError.
  453 +
  454 + - `NSString * const AFNetworkingOperationFailingURLRequestErrorKey`
  455 +
  456 + ### Constants
  457 +
  458 + `AFNetworkingOperationFailingURLRequestErrorKey`
  459 + The corresponding value is an `NSURLRequest` containing the request of the operation associated with an error. This key is only present in the `AFURLRequestSerializationErrorDomain`.
  460 + */
  461 +FOUNDATION_EXPORT NSString * const AFNetworkingOperationFailingURLRequestErrorKey;
  462 +
  463 +/**
  464 + ## Throttling Bandwidth for HTTP Request Input Streams
  465 +
  466 + @see -throttleBandwidthWithPacketSize:delay:
  467 +
  468 + ### Constants
  469 +
  470 + `kAFUploadStream3GSuggestedPacketSize`
  471 + Maximum packet size, in number of bytes. Equal to 16kb.
  472 +
  473 + `kAFUploadStream3GSuggestedDelay`
  474 + Duration of delay each time a packet is read. Equal to 0.2 seconds.
  475 + */
  476 +FOUNDATION_EXPORT NSUInteger const kAFUploadStream3GSuggestedPacketSize;
  477 +FOUNDATION_EXPORT NSTimeInterval const kAFUploadStream3GSuggestedDelay;
  478 +
  479 +NS_ASSUME_NONNULL_END
... ...
Example/Pods/AFNetworking/AFNetworking/AFURLRequestSerialization.m 0 → 100644
  1 +// AFURLRequestSerialization.m
  2 +// Copyright (c) 2011–2016 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 +
  22 +#import "AFURLRequestSerialization.h"
  23 +
  24 +#if TARGET_OS_IOS || TARGET_OS_WATCH || TARGET_OS_TV
  25 +#import <MobileCoreServices/MobileCoreServices.h>
  26 +#else
  27 +#import <CoreServices/CoreServices.h>
  28 +#endif
  29 +
  30 +NSString * const AFURLRequestSerializationErrorDomain = @"com.alamofire.error.serialization.request";
  31 +NSString * const AFNetworkingOperationFailingURLRequestErrorKey = @"com.alamofire.serialization.request.error.response";
  32 +
  33 +typedef NSString * (^AFQueryStringSerializationBlock)(NSURLRequest *request, id parameters, NSError *__autoreleasing *error);
  34 +
  35 +/**
  36 + Returns a percent-escaped string following RFC 3986 for a query string key or value.
  37 + RFC 3986 states that the following characters are "reserved" characters.
  38 + - General Delimiters: ":", "#", "[", "]", "@", "?", "/"
  39 + - Sub-Delimiters: "!", "$", "&", "'", "(", ")", "*", "+", ",", ";", "="
  40 +
  41 + In RFC 3986 - Section 3.4, it states that the "?" and "/" characters should not be escaped to allow
  42 + query strings to include a URL. Therefore, all "reserved" characters with the exception of "?" and "/"
  43 + should be percent-escaped in the query string.
  44 + - parameter string: The string to be percent-escaped.
  45 + - returns: The percent-escaped string.
  46 + */
  47 +NSString * AFPercentEscapedStringFromString(NSString *string) {
  48 + static NSString * const kAFCharactersGeneralDelimitersToEncode = @":#[]@"; // does not include "?" or "/" due to RFC 3986 - Section 3.4
  49 + static NSString * const kAFCharactersSubDelimitersToEncode = @"!$&'()*+,;=";
  50 +
  51 + NSMutableCharacterSet * allowedCharacterSet = [[NSCharacterSet URLQueryAllowedCharacterSet] mutableCopy];
  52 + [allowedCharacterSet removeCharactersInString:[kAFCharactersGeneralDelimitersToEncode stringByAppendingString:kAFCharactersSubDelimitersToEncode]];
  53 +
  54 + // FIXME: https://github.com/AFNetworking/AFNetworking/pull/3028
  55 + // return [string stringByAddingPercentEncodingWithAllowedCharacters:allowedCharacterSet];
  56 +
  57 + static NSUInteger const batchSize = 50;
  58 +
  59 + NSUInteger index = 0;
  60 + NSMutableString *escaped = @"".mutableCopy;
  61 +
  62 + while (index < string.length) {
  63 + NSUInteger length = MIN(string.length - index, batchSize);
  64 + NSRange range = NSMakeRange(index, length);
  65 +
  66 + // To avoid breaking up character sequences such as 👴🏻👮🏽
  67 + range = [string rangeOfComposedCharacterSequencesForRange:range];
  68 +
  69 + NSString *substring = [string substringWithRange:range];
  70 + NSString *encoded = [substring stringByAddingPercentEncodingWithAllowedCharacters:allowedCharacterSet];
  71 + [escaped appendString:encoded];
  72 +
  73 + index += range.length;
  74 + }
  75 +
  76 + return escaped;
  77 +}
  78 +
  79 +#pragma mark -
  80 +
  81 +@interface AFQueryStringPair : NSObject
  82 +@property (readwrite, nonatomic, strong) id field;
  83 +@property (readwrite, nonatomic, strong) id value;
  84 +
  85 +- (instancetype)initWithField:(id)field value:(id)value;
  86 +
  87 +- (NSString *)URLEncodedStringValue;
  88 +@end
  89 +
  90 +@implementation AFQueryStringPair
  91 +
  92 +- (instancetype)initWithField:(id)field value:(id)value {
  93 + self = [super init];
  94 + if (!self) {
  95 + return nil;
  96 + }
  97 +
  98 + self.field = field;
  99 + self.value = value;
  100 +
  101 + return self;
  102 +}
  103 +
  104 +- (NSString *)URLEncodedStringValue {
  105 + if (!self.value || [self.value isEqual:[NSNull null]]) {
  106 + return AFPercentEscapedStringFromString([self.field description]);
  107 + } else {
  108 + return [NSString stringWithFormat:@"%@=%@", AFPercentEscapedStringFromString([self.field description]), AFPercentEscapedStringFromString([self.value description])];
  109 + }
  110 +}
  111 +
  112 +@end
  113 +
  114 +#pragma mark -
  115 +
  116 +FOUNDATION_EXPORT NSArray * AFQueryStringPairsFromDictionary(NSDictionary *dictionary);
  117 +FOUNDATION_EXPORT NSArray * AFQueryStringPairsFromKeyAndValue(NSString *key, id value);
  118 +
  119 +NSString * AFQueryStringFromParameters(NSDictionary *parameters) {
  120 + NSMutableArray *mutablePairs = [NSMutableArray array];
  121 + for (AFQueryStringPair *pair in AFQueryStringPairsFromDictionary(parameters)) {
  122 + [mutablePairs addObject:[pair URLEncodedStringValue]];
  123 + }
  124 +
  125 + return [mutablePairs componentsJoinedByString:@"&"];
  126 +}
  127 +
  128 +NSArray * AFQueryStringPairsFromDictionary(NSDictionary *dictionary) {
  129 + return AFQueryStringPairsFromKeyAndValue(nil, dictionary);
  130 +}
  131 +
  132 +NSArray * AFQueryStringPairsFromKeyAndValue(NSString *key, id value) {
  133 + NSMutableArray *mutableQueryStringComponents = [NSMutableArray array];
  134 +
  135 + NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"description" ascending:YES selector:@selector(compare:)];
  136 +
  137 + if ([value isKindOfClass:[NSDictionary class]]) {
  138 + NSDictionary *dictionary = value;
  139 + // Sort dictionary keys to ensure consistent ordering in query string, which is important when deserializing potentially ambiguous sequences, such as an array of dictionaries
  140 + for (id nestedKey in [dictionary.allKeys sortedArrayUsingDescriptors:@[ sortDescriptor ]]) {
  141 + id nestedValue = dictionary[nestedKey];
  142 + if (nestedValue) {
  143 + [mutableQueryStringComponents addObjectsFromArray:AFQueryStringPairsFromKeyAndValue((key ? [NSString stringWithFormat:@"%@[%@]", key, nestedKey] : nestedKey), nestedValue)];
  144 + }
  145 + }
  146 + } else if ([value isKindOfClass:[NSArray class]]) {
  147 + NSArray *array = value;
  148 + for (id nestedValue in array) {
  149 + [mutableQueryStringComponents addObjectsFromArray:AFQueryStringPairsFromKeyAndValue([NSString stringWithFormat:@"%@[]", key], nestedValue)];
  150 + }
  151 + } else if ([value isKindOfClass:[NSSet class]]) {
  152 + NSSet *set = value;
  153 + for (id obj in [set sortedArrayUsingDescriptors:@[ sortDescriptor ]]) {
  154 + [mutableQueryStringComponents addObjectsFromArray:AFQueryStringPairsFromKeyAndValue(key, obj)];
  155 + }
  156 + } else {
  157 + [mutableQueryStringComponents addObject:[[AFQueryStringPair alloc] initWithField:key value:value]];
  158 + }
  159 +
  160 + return mutableQueryStringComponents;
  161 +}
  162 +
  163 +#pragma mark -
  164 +
  165 +@interface AFStreamingMultipartFormData : NSObject <AFMultipartFormData>
  166 +- (instancetype)initWithURLRequest:(NSMutableURLRequest *)urlRequest
  167 + stringEncoding:(NSStringEncoding)encoding;
  168 +
  169 +- (NSMutableURLRequest *)requestByFinalizingMultipartFormData;
  170 +@end
  171 +
  172 +#pragma mark -
  173 +
  174 +static NSArray * AFHTTPRequestSerializerObservedKeyPaths() {
  175 + static NSArray *_AFHTTPRequestSerializerObservedKeyPaths = nil;
  176 + static dispatch_once_t onceToken;
  177 + dispatch_once(&onceToken, ^{
  178 + _AFHTTPRequestSerializerObservedKeyPaths = @[NSStringFromSelector(@selector(allowsCellularAccess)), NSStringFromSelector(@selector(cachePolicy)), NSStringFromSelector(@selector(HTTPShouldHandleCookies)), NSStringFromSelector(@selector(HTTPShouldUsePipelining)), NSStringFromSelector(@selector(networkServiceType)), NSStringFromSelector(@selector(timeoutInterval))];
  179 + });
  180 +
  181 + return _AFHTTPRequestSerializerObservedKeyPaths;
  182 +}
  183 +
  184 +static void *AFHTTPRequestSerializerObserverContext = &AFHTTPRequestSerializerObserverContext;
  185 +
  186 +@interface AFHTTPRequestSerializer ()
  187 +@property (readwrite, nonatomic, strong) NSMutableSet *mutableObservedChangedKeyPaths;
  188 +@property (readwrite, nonatomic, strong) NSMutableDictionary *mutableHTTPRequestHeaders;
  189 +@property (readwrite, nonatomic, strong) dispatch_queue_t requestHeaderModificationQueue;
  190 +@property (readwrite, nonatomic, assign) AFHTTPRequestQueryStringSerializationStyle queryStringSerializationStyle;
  191 +@property (readwrite, nonatomic, copy) AFQueryStringSerializationBlock queryStringSerialization;
  192 +@end
  193 +
  194 +@implementation AFHTTPRequestSerializer
  195 +
  196 ++ (instancetype)serializer {
  197 + return [[self alloc] init];
  198 +}
  199 +
  200 +- (instancetype)init {
  201 + self = [super init];
  202 + if (!self) {
  203 + return nil;
  204 + }
  205 +
  206 + self.stringEncoding = NSUTF8StringEncoding;
  207 +
  208 + self.mutableHTTPRequestHeaders = [NSMutableDictionary dictionary];
  209 + self.requestHeaderModificationQueue = dispatch_queue_create("requestHeaderModificationQueue", DISPATCH_QUEUE_CONCURRENT);
  210 +
  211 + // Accept-Language HTTP Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4
  212 + NSMutableArray *acceptLanguagesComponents = [NSMutableArray array];
  213 + [[NSLocale preferredLanguages] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
  214 + float q = 1.0f - (idx * 0.1f);
  215 + [acceptLanguagesComponents addObject:[NSString stringWithFormat:@"%@;q=%0.1g", obj, q]];
  216 + *stop = q <= 0.5f;
  217 + }];
  218 + [self setValue:[acceptLanguagesComponents componentsJoinedByString:@", "] forHTTPHeaderField:@"Accept-Language"];
  219 +
  220 + // User-Agent Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.43
  221 + NSString *userAgent = nil;
  222 +#if TARGET_OS_IOS
  223 + userAgent = [NSString stringWithFormat:@"%@/%@ (%@; iOS %@; Scale/%0.2f)", [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleExecutableKey] ?: [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleIdentifierKey], [[NSBundle mainBundle] infoDictionary][@"CFBundleShortVersionString"] ?: [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleVersionKey], [[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion], [[UIScreen mainScreen] scale]];
  224 +#elif TARGET_OS_TV
  225 + userAgent = [NSString stringWithFormat:@"%@/%@ (%@; tvOS %@; Scale/%0.2f)", [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleExecutableKey] ?: [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleIdentifierKey], [[NSBundle mainBundle] infoDictionary][@"CFBundleShortVersionString"] ?: [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleVersionKey], [[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion], [[UIScreen mainScreen] scale]];
  226 +#elif TARGET_OS_WATCH
  227 + userAgent = [NSString stringWithFormat:@"%@/%@ (%@; watchOS %@; Scale/%0.2f)", [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleExecutableKey] ?: [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleIdentifierKey], [[NSBundle mainBundle] infoDictionary][@"CFBundleShortVersionString"] ?: [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleVersionKey], [[WKInterfaceDevice currentDevice] model], [[WKInterfaceDevice currentDevice] systemVersion], [[WKInterfaceDevice currentDevice] screenScale]];
  228 +#elif defined(__MAC_OS_X_VERSION_MIN_REQUIRED)
  229 + userAgent = [NSString stringWithFormat:@"%@/%@ (Mac OS X %@)", [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleExecutableKey] ?: [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleIdentifierKey], [[NSBundle mainBundle] infoDictionary][@"CFBundleShortVersionString"] ?: [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleVersionKey], [[NSProcessInfo processInfo] operatingSystemVersionString]];
  230 +#endif
  231 + if (userAgent) {
  232 + if (![userAgent canBeConvertedToEncoding:NSASCIIStringEncoding]) {
  233 + NSMutableString *mutableUserAgent = [userAgent mutableCopy];
  234 + if (CFStringTransform((__bridge CFMutableStringRef)(mutableUserAgent), NULL, (__bridge CFStringRef)@"Any-Latin; Latin-ASCII; [:^ASCII:] Remove", false)) {
  235 + userAgent = mutableUserAgent;
  236 + }
  237 + }
  238 + [self setValue:userAgent forHTTPHeaderField:@"User-Agent"];
  239 + }
  240 +
  241 + // HTTP Method Definitions; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
  242 + self.HTTPMethodsEncodingParametersInURI = [NSSet setWithObjects:@"GET", @"HEAD", @"DELETE", nil];
  243 +
  244 + self.mutableObservedChangedKeyPaths = [NSMutableSet set];
  245 + for (NSString *keyPath in AFHTTPRequestSerializerObservedKeyPaths()) {
  246 + if ([self respondsToSelector:NSSelectorFromString(keyPath)]) {
  247 + [self addObserver:self forKeyPath:keyPath options:NSKeyValueObservingOptionNew context:AFHTTPRequestSerializerObserverContext];
  248 + }
  249 + }
  250 +
  251 + return self;
  252 +}
  253 +
  254 +- (void)dealloc {
  255 + for (NSString *keyPath in AFHTTPRequestSerializerObservedKeyPaths()) {
  256 + if ([self respondsToSelector:NSSelectorFromString(keyPath)]) {
  257 + [self removeObserver:self forKeyPath:keyPath context:AFHTTPRequestSerializerObserverContext];
  258 + }
  259 + }
  260 +}
  261 +
  262 +#pragma mark -
  263 +
  264 +// Workarounds for crashing behavior using Key-Value Observing with XCTest
  265 +// See https://github.com/AFNetworking/AFNetworking/issues/2523
  266 +
  267 +- (void)setAllowsCellularAccess:(BOOL)allowsCellularAccess {
  268 + [self willChangeValueForKey:NSStringFromSelector(@selector(allowsCellularAccess))];
  269 + _allowsCellularAccess = allowsCellularAccess;
  270 + [self didChangeValueForKey:NSStringFromSelector(@selector(allowsCellularAccess))];
  271 +}
  272 +
  273 +- (void)setCachePolicy:(NSURLRequestCachePolicy)cachePolicy {
  274 + [self willChangeValueForKey:NSStringFromSelector(@selector(cachePolicy))];
  275 + _cachePolicy = cachePolicy;
  276 + [self didChangeValueForKey:NSStringFromSelector(@selector(cachePolicy))];
  277 +}
  278 +
  279 +- (void)setHTTPShouldHandleCookies:(BOOL)HTTPShouldHandleCookies {
  280 + [self willChangeValueForKey:NSStringFromSelector(@selector(HTTPShouldHandleCookies))];
  281 + _HTTPShouldHandleCookies = HTTPShouldHandleCookies;
  282 + [self didChangeValueForKey:NSStringFromSelector(@selector(HTTPShouldHandleCookies))];
  283 +}
  284 +
  285 +- (void)setHTTPShouldUsePipelining:(BOOL)HTTPShouldUsePipelining {
  286 + [self willChangeValueForKey:NSStringFromSelector(@selector(HTTPShouldUsePipelining))];
  287 + _HTTPShouldUsePipelining = HTTPShouldUsePipelining;
  288 + [self didChangeValueForKey:NSStringFromSelector(@selector(HTTPShouldUsePipelining))];
  289 +}
  290 +
  291 +- (void)setNetworkServiceType:(NSURLRequestNetworkServiceType)networkServiceType {
  292 + [self willChangeValueForKey:NSStringFromSelector(@selector(networkServiceType))];
  293 + _networkServiceType = networkServiceType;
  294 + [self didChangeValueForKey:NSStringFromSelector(@selector(networkServiceType))];
  295 +}
  296 +
  297 +- (void)setTimeoutInterval:(NSTimeInterval)timeoutInterval {
  298 + [self willChangeValueForKey:NSStringFromSelector(@selector(timeoutInterval))];
  299 + _timeoutInterval = timeoutInterval;
  300 + [self didChangeValueForKey:NSStringFromSelector(@selector(timeoutInterval))];
  301 +}
  302 +
  303 +#pragma mark -
  304 +
  305 +- (NSDictionary *)HTTPRequestHeaders {
  306 + NSDictionary __block *value;
  307 + dispatch_sync(self.requestHeaderModificationQueue, ^{
  308 + value = [NSDictionary dictionaryWithDictionary:self.mutableHTTPRequestHeaders];
  309 + });
  310 + return value;
  311 +}
  312 +
  313 +- (void)setValue:(NSString *)value
  314 +forHTTPHeaderField:(NSString *)field
  315 +{
  316 + dispatch_barrier_sync(self.requestHeaderModificationQueue, ^{
  317 + [self.mutableHTTPRequestHeaders setValue:value forKey:field];
  318 + });
  319 +}
  320 +
  321 +- (NSString *)valueForHTTPHeaderField:(NSString *)field {
  322 + NSString __block *value;
  323 + dispatch_sync(self.requestHeaderModificationQueue, ^{
  324 + value = [self.mutableHTTPRequestHeaders valueForKey:field];
  325 + });
  326 + return value;
  327 +}
  328 +
  329 +- (void)setAuthorizationHeaderFieldWithUsername:(NSString *)username
  330 + password:(NSString *)password
  331 +{
  332 + NSData *basicAuthCredentials = [[NSString stringWithFormat:@"%@:%@", username, password] dataUsingEncoding:NSUTF8StringEncoding];
  333 + NSString *base64AuthCredentials = [basicAuthCredentials base64EncodedStringWithOptions:(NSDataBase64EncodingOptions)0];
  334 + [self setValue:[NSString stringWithFormat:@"Basic %@", base64AuthCredentials] forHTTPHeaderField:@"Authorization"];
  335 +}
  336 +
  337 +- (void)clearAuthorizationHeader {
  338 + dispatch_barrier_sync(self.requestHeaderModificationQueue, ^{
  339 + [self.mutableHTTPRequestHeaders removeObjectForKey:@"Authorization"];
  340 + });
  341 +}
  342 +
  343 +#pragma mark -
  344 +
  345 +- (void)setQueryStringSerializationWithStyle:(AFHTTPRequestQueryStringSerializationStyle)style {
  346 + self.queryStringSerializationStyle = style;
  347 + self.queryStringSerialization = nil;
  348 +}
  349 +
  350 +- (void)setQueryStringSerializationWithBlock:(NSString *(^)(NSURLRequest *, id, NSError *__autoreleasing *))block {
  351 + self.queryStringSerialization = block;
  352 +}
  353 +
  354 +#pragma mark -
  355 +
  356 +- (NSMutableURLRequest *)requestWithMethod:(NSString *)method
  357 + URLString:(NSString *)URLString
  358 + parameters:(id)parameters
  359 + error:(NSError *__autoreleasing *)error
  360 +{
  361 + NSParameterAssert(method);
  362 + NSParameterAssert(URLString);
  363 +
  364 + NSURL *url = [NSURL URLWithString:URLString];
  365 +
  366 + NSParameterAssert(url);
  367 +
  368 + NSMutableURLRequest *mutableRequest = [[NSMutableURLRequest alloc] initWithURL:url];
  369 + mutableRequest.HTTPMethod = method;
  370 +
  371 + for (NSString *keyPath in AFHTTPRequestSerializerObservedKeyPaths()) {
  372 + if ([self.mutableObservedChangedKeyPaths containsObject:keyPath]) {
  373 + [mutableRequest setValue:[self valueForKeyPath:keyPath] forKey:keyPath];
  374 + }
  375 + }
  376 +
  377 + mutableRequest = [[self requestBySerializingRequest:mutableRequest withParameters:parameters error:error] mutableCopy];
  378 +
  379 + return mutableRequest;
  380 +}
  381 +
  382 +- (NSMutableURLRequest *)multipartFormRequestWithMethod:(NSString *)method
  383 + URLString:(NSString *)URLString
  384 + parameters:(NSDictionary *)parameters
  385 + constructingBodyWithBlock:(void (^)(id <AFMultipartFormData> formData))block
  386 + error:(NSError *__autoreleasing *)error
  387 +{
  388 + NSParameterAssert(method);
  389 + NSParameterAssert(![method isEqualToString:@"GET"] && ![method isEqualToString:@"HEAD"]);
  390 +
  391 + NSMutableURLRequest *mutableRequest = [self requestWithMethod:method URLString:URLString parameters:nil error:error];
  392 +
  393 + __block AFStreamingMultipartFormData *formData = [[AFStreamingMultipartFormData alloc] initWithURLRequest:mutableRequest stringEncoding:NSUTF8StringEncoding];
  394 +
  395 + if (parameters) {
  396 + for (AFQueryStringPair *pair in AFQueryStringPairsFromDictionary(parameters)) {
  397 + NSData *data = nil;
  398 + if ([pair.value isKindOfClass:[NSData class]]) {
  399 + data = pair.value;
  400 + } else if ([pair.value isEqual:[NSNull null]]) {
  401 + data = [NSData data];
  402 + } else {
  403 + data = [[pair.value description] dataUsingEncoding:self.stringEncoding];
  404 + }
  405 +
  406 + if (data) {
  407 + [formData appendPartWithFormData:data name:[pair.field description]];
  408 + }
  409 + }
  410 + }
  411 +
  412 + if (block) {
  413 + block(formData);
  414 + }
  415 +
  416 + return [formData requestByFinalizingMultipartFormData];
  417 +}
  418 +
  419 +- (NSMutableURLRequest *)requestWithMultipartFormRequest:(NSURLRequest *)request
  420 + writingStreamContentsToFile:(NSURL *)fileURL
  421 + completionHandler:(void (^)(NSError *error))handler
  422 +{
  423 + NSParameterAssert(request.HTTPBodyStream);
  424 + NSParameterAssert([fileURL isFileURL]);
  425 +
  426 + NSInputStream *inputStream = request.HTTPBodyStream;
  427 + NSOutputStream *outputStream = [[NSOutputStream alloc] initWithURL:fileURL append:NO];
  428 + __block NSError *error = nil;
  429 +
  430 + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  431 + [inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
  432 + [outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
  433 +
  434 + [inputStream open];
  435 + [outputStream open];
  436 +
  437 + while ([inputStream hasBytesAvailable] && [outputStream hasSpaceAvailable]) {
  438 + uint8_t buffer[1024];
  439 +
  440 + NSInteger bytesRead = [inputStream read:buffer maxLength:1024];
  441 + if (inputStream.streamError || bytesRead < 0) {
  442 + error = inputStream.streamError;
  443 + break;
  444 + }
  445 +
  446 + NSInteger bytesWritten = [outputStream write:buffer maxLength:(NSUInteger)bytesRead];
  447 + if (outputStream.streamError || bytesWritten < 0) {
  448 + error = outputStream.streamError;
  449 + break;
  450 + }
  451 +
  452 + if (bytesRead == 0 && bytesWritten == 0) {
  453 + break;
  454 + }
  455 + }
  456 +
  457 + [outputStream close];
  458 + [inputStream close];
  459 +
  460 + if (handler) {
  461 + dispatch_async(dispatch_get_main_queue(), ^{
  462 + handler(error);
  463 + });
  464 + }
  465 + });
  466 +
  467 + NSMutableURLRequest *mutableRequest = [request mutableCopy];
  468 + mutableRequest.HTTPBodyStream = nil;
  469 +
  470 + return mutableRequest;
  471 +}
  472 +
  473 +#pragma mark - AFURLRequestSerialization
  474 +
  475 +- (NSURLRequest *)requestBySerializingRequest:(NSURLRequest *)request
  476 + withParameters:(id)parameters
  477 + error:(NSError *__autoreleasing *)error
  478 +{
  479 + NSParameterAssert(request);
  480 +
  481 + NSMutableURLRequest *mutableRequest = [request mutableCopy];
  482 +
  483 + [self.HTTPRequestHeaders enumerateKeysAndObjectsUsingBlock:^(id field, id value, BOOL * __unused stop) {
  484 + if (![request valueForHTTPHeaderField:field]) {
  485 + [mutableRequest setValue:value forHTTPHeaderField:field];
  486 + }
  487 + }];
  488 +
  489 + NSString *query = nil;
  490 + if (parameters) {
  491 + if (self.queryStringSerialization) {
  492 + NSError *serializationError;
  493 + query = self.queryStringSerialization(request, parameters, &serializationError);
  494 +
  495 + if (serializationError) {
  496 + if (error) {
  497 + *error = serializationError;
  498 + }
  499 +
  500 + return nil;
  501 + }
  502 + } else {
  503 + switch (self.queryStringSerializationStyle) {
  504 + case AFHTTPRequestQueryStringDefaultStyle:
  505 + query = AFQueryStringFromParameters(parameters);
  506 + break;
  507 + }
  508 + }
  509 + }
  510 +
  511 + if ([self.HTTPMethodsEncodingParametersInURI containsObject:[[request HTTPMethod] uppercaseString]]) {
  512 + if (query && query.length > 0) {
  513 + mutableRequest.URL = [NSURL URLWithString:[[mutableRequest.URL absoluteString] stringByAppendingFormat:mutableRequest.URL.query ? @"&%@" : @"?%@", query]];
  514 + }
  515 + } else {
  516 + // #2864: an empty string is a valid x-www-form-urlencoded payload
  517 + if (!query) {
  518 + query = @"";
  519 + }
  520 + if (![mutableRequest valueForHTTPHeaderField:@"Content-Type"]) {
  521 + [mutableRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
  522 + }
  523 + [mutableRequest setHTTPBody:[query dataUsingEncoding:self.stringEncoding]];
  524 + }
  525 +
  526 + return mutableRequest;
  527 +}
  528 +
  529 +#pragma mark - NSKeyValueObserving
  530 +
  531 ++ (BOOL)automaticallyNotifiesObserversForKey:(NSString *)key {
  532 + if ([AFHTTPRequestSerializerObservedKeyPaths() containsObject:key]) {
  533 + return NO;
  534 + }
  535 +
  536 + return [super automaticallyNotifiesObserversForKey:key];
  537 +}
  538 +
  539 +- (void)observeValueForKeyPath:(NSString *)keyPath
  540 + ofObject:(__unused id)object
  541 + change:(NSDictionary *)change
  542 + context:(void *)context
  543 +{
  544 + if (context == AFHTTPRequestSerializerObserverContext) {
  545 + if ([change[NSKeyValueChangeNewKey] isEqual:[NSNull null]]) {
  546 + [self.mutableObservedChangedKeyPaths removeObject:keyPath];
  547 + } else {
  548 + [self.mutableObservedChangedKeyPaths addObject:keyPath];
  549 + }
  550 + }
  551 +}
  552 +
  553 +#pragma mark - NSSecureCoding
  554 +
  555 ++ (BOOL)supportsSecureCoding {
  556 + return YES;
  557 +}
  558 +
  559 +- (instancetype)initWithCoder:(NSCoder *)decoder {
  560 + self = [self init];
  561 + if (!self) {
  562 + return nil;
  563 + }
  564 +
  565 + self.mutableHTTPRequestHeaders = [[decoder decodeObjectOfClass:[NSDictionary class] forKey:NSStringFromSelector(@selector(mutableHTTPRequestHeaders))] mutableCopy];
  566 + self.queryStringSerializationStyle = (AFHTTPRequestQueryStringSerializationStyle)[[decoder decodeObjectOfClass:[NSNumber class] forKey:NSStringFromSelector(@selector(queryStringSerializationStyle))] unsignedIntegerValue];
  567 +
  568 + return self;
  569 +}
  570 +
  571 +- (void)encodeWithCoder:(NSCoder *)coder {
  572 + dispatch_sync(self.requestHeaderModificationQueue, ^{
  573 + [coder encodeObject:self.mutableHTTPRequestHeaders forKey:NSStringFromSelector(@selector(mutableHTTPRequestHeaders))];
  574 + });
  575 + [coder encodeObject:@(self.queryStringSerializationStyle) forKey:NSStringFromSelector(@selector(queryStringSerializationStyle))];
  576 +}
  577 +
  578 +#pragma mark - NSCopying
  579 +
  580 +- (instancetype)copyWithZone:(NSZone *)zone {
  581 + AFHTTPRequestSerializer *serializer = [[[self class] allocWithZone:zone] init];
  582 + dispatch_sync(self.requestHeaderModificationQueue, ^{
  583 + serializer.mutableHTTPRequestHeaders = [self.mutableHTTPRequestHeaders mutableCopyWithZone:zone];
  584 + });
  585 + serializer.queryStringSerializationStyle = self.queryStringSerializationStyle;
  586 + serializer.queryStringSerialization = self.queryStringSerialization;
  587 +
  588 + return serializer;
  589 +}
  590 +
  591 +@end
  592 +
  593 +#pragma mark -
  594 +
  595 +static NSString * AFCreateMultipartFormBoundary() {
  596 + return [NSString stringWithFormat:@"Boundary+%08X%08X", arc4random(), arc4random()];
  597 +}
  598 +
  599 +static NSString * const kAFMultipartFormCRLF = @"\r\n";
  600 +
  601 +static inline NSString * AFMultipartFormInitialBoundary(NSString *boundary) {
  602 + return [NSString stringWithFormat:@"--%@%@", boundary, kAFMultipartFormCRLF];
  603 +}
  604 +
  605 +static inline NSString * AFMultipartFormEncapsulationBoundary(NSString *boundary) {
  606 + return [NSString stringWithFormat:@"%@--%@%@", kAFMultipartFormCRLF, boundary, kAFMultipartFormCRLF];
  607 +}
  608 +
  609 +static inline NSString * AFMultipartFormFinalBoundary(NSString *boundary) {
  610 + return [NSString stringWithFormat:@"%@--%@--%@", kAFMultipartFormCRLF, boundary, kAFMultipartFormCRLF];
  611 +}
  612 +
  613 +static inline NSString * AFContentTypeForPathExtension(NSString *extension) {
  614 + NSString *UTI = (__bridge_transfer NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)extension, NULL);
  615 + NSString *contentType = (__bridge_transfer NSString *)UTTypeCopyPreferredTagWithClass((__bridge CFStringRef)UTI, kUTTagClassMIMEType);
  616 + if (!contentType) {
  617 + return @"application/octet-stream";
  618 + } else {
  619 + return contentType;
  620 + }
  621 +}
  622 +
  623 +NSUInteger const kAFUploadStream3GSuggestedPacketSize = 1024 * 16;
  624 +NSTimeInterval const kAFUploadStream3GSuggestedDelay = 0.2;
  625 +
  626 +@interface AFHTTPBodyPart : NSObject
  627 +@property (nonatomic, assign) NSStringEncoding stringEncoding;
  628 +@property (nonatomic, strong) NSDictionary *headers;
  629 +@property (nonatomic, copy) NSString *boundary;
  630 +@property (nonatomic, strong) id body;
  631 +@property (nonatomic, assign) unsigned long long bodyContentLength;
  632 +@property (nonatomic, strong) NSInputStream *inputStream;
  633 +
  634 +@property (nonatomic, assign) BOOL hasInitialBoundary;
  635 +@property (nonatomic, assign) BOOL hasFinalBoundary;
  636 +
  637 +@property (readonly, nonatomic, assign, getter = hasBytesAvailable) BOOL bytesAvailable;
  638 +@property (readonly, nonatomic, assign) unsigned long long contentLength;
  639 +
  640 +- (NSInteger)read:(uint8_t *)buffer
  641 + maxLength:(NSUInteger)length;
  642 +@end
  643 +
  644 +@interface AFMultipartBodyStream : NSInputStream <NSStreamDelegate>
  645 +@property (nonatomic, assign) NSUInteger numberOfBytesInPacket;
  646 +@property (nonatomic, assign) NSTimeInterval delay;
  647 +@property (nonatomic, strong) NSInputStream *inputStream;
  648 +@property (readonly, nonatomic, assign) unsigned long long contentLength;
  649 +@property (readonly, nonatomic, assign, getter = isEmpty) BOOL empty;
  650 +
  651 +- (instancetype)initWithStringEncoding:(NSStringEncoding)encoding;
  652 +- (void)setInitialAndFinalBoundaries;
  653 +- (void)appendHTTPBodyPart:(AFHTTPBodyPart *)bodyPart;
  654 +@end
  655 +
  656 +#pragma mark -
  657 +
  658 +@interface AFStreamingMultipartFormData ()
  659 +@property (readwrite, nonatomic, copy) NSMutableURLRequest *request;
  660 +@property (readwrite, nonatomic, assign) NSStringEncoding stringEncoding;
  661 +@property (readwrite, nonatomic, copy) NSString *boundary;
  662 +@property (readwrite, nonatomic, strong) AFMultipartBodyStream *bodyStream;
  663 +@end
  664 +
  665 +@implementation AFStreamingMultipartFormData
  666 +
  667 +- (instancetype)initWithURLRequest:(NSMutableURLRequest *)urlRequest
  668 + stringEncoding:(NSStringEncoding)encoding
  669 +{
  670 + self = [super init];
  671 + if (!self) {
  672 + return nil;
  673 + }
  674 +
  675 + self.request = urlRequest;
  676 + self.stringEncoding = encoding;
  677 + self.boundary = AFCreateMultipartFormBoundary();
  678 + self.bodyStream = [[AFMultipartBodyStream alloc] initWithStringEncoding:encoding];
  679 +
  680 + return self;
  681 +}
  682 +
  683 +- (void)setRequest:(NSMutableURLRequest *)request
  684 +{
  685 + _request = [request mutableCopy];
  686 +}
  687 +
  688 +- (BOOL)appendPartWithFileURL:(NSURL *)fileURL
  689 + name:(NSString *)name
  690 + error:(NSError * __autoreleasing *)error
  691 +{
  692 + NSParameterAssert(fileURL);
  693 + NSParameterAssert(name);
  694 +
  695 + NSString *fileName = [fileURL lastPathComponent];
  696 + NSString *mimeType = AFContentTypeForPathExtension([fileURL pathExtension]);
  697 +
  698 + return [self appendPartWithFileURL:fileURL name:name fileName:fileName mimeType:mimeType error:error];
  699 +}
  700 +
  701 +- (BOOL)appendPartWithFileURL:(NSURL *)fileURL
  702 + name:(NSString *)name
  703 + fileName:(NSString *)fileName
  704 + mimeType:(NSString *)mimeType
  705 + error:(NSError * __autoreleasing *)error
  706 +{
  707 + NSParameterAssert(fileURL);
  708 + NSParameterAssert(name);
  709 + NSParameterAssert(fileName);
  710 + NSParameterAssert(mimeType);
  711 +
  712 + if (![fileURL isFileURL]) {
  713 + NSDictionary *userInfo = @{NSLocalizedFailureReasonErrorKey: NSLocalizedStringFromTable(@"Expected URL to be a file URL", @"AFNetworking", nil)};
  714 + if (error) {
  715 + *error = [[NSError alloc] initWithDomain:AFURLRequestSerializationErrorDomain code:NSURLErrorBadURL userInfo:userInfo];
  716 + }
  717 +
  718 + return NO;
  719 + } else if ([fileURL checkResourceIsReachableAndReturnError:error] == NO) {
  720 + NSDictionary *userInfo = @{NSLocalizedFailureReasonErrorKey: NSLocalizedStringFromTable(@"File URL not reachable.", @"AFNetworking", nil)};
  721 + if (error) {
  722 + *error = [[NSError alloc] initWithDomain:AFURLRequestSerializationErrorDomain code:NSURLErrorBadURL userInfo:userInfo];
  723 + }
  724 +
  725 + return NO;
  726 + }
  727 +
  728 + NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:[fileURL path] error:error];
  729 + if (!fileAttributes) {
  730 + return NO;
  731 + }
  732 +
  733 + NSMutableDictionary *mutableHeaders = [NSMutableDictionary dictionary];
  734 + [mutableHeaders setValue:[NSString stringWithFormat:@"form-data; name=\"%@\"; filename=\"%@\"", name, fileName] forKey:@"Content-Disposition"];
  735 + [mutableHeaders setValue:mimeType forKey:@"Content-Type"];
  736 +
  737 + AFHTTPBodyPart *bodyPart = [[AFHTTPBodyPart alloc] init];
  738 + bodyPart.stringEncoding = self.stringEncoding;
  739 + bodyPart.headers = mutableHeaders;
  740 + bodyPart.boundary = self.boundary;
  741 + bodyPart.body = fileURL;
  742 + bodyPart.bodyContentLength = [fileAttributes[NSFileSize] unsignedLongLongValue];
  743 + [self.bodyStream appendHTTPBodyPart:bodyPart];
  744 +
  745 + return YES;
  746 +}
  747 +
  748 +- (void)appendPartWithInputStream:(NSInputStream *)inputStream
  749 + name:(NSString *)name
  750 + fileName:(NSString *)fileName
  751 + length:(int64_t)length
  752 + mimeType:(NSString *)mimeType
  753 +{
  754 + NSParameterAssert(name);
  755 + NSParameterAssert(fileName);
  756 + NSParameterAssert(mimeType);
  757 +
  758 + NSMutableDictionary *mutableHeaders = [NSMutableDictionary dictionary];
  759 + [mutableHeaders setValue:[NSString stringWithFormat:@"form-data; name=\"%@\"; filename=\"%@\"", name, fileName] forKey:@"Content-Disposition"];
  760 + [mutableHeaders setValue:mimeType forKey:@"Content-Type"];
  761 +
  762 + AFHTTPBodyPart *bodyPart = [[AFHTTPBodyPart alloc] init];
  763 + bodyPart.stringEncoding = self.stringEncoding;
  764 + bodyPart.headers = mutableHeaders;
  765 + bodyPart.boundary = self.boundary;
  766 + bodyPart.body = inputStream;
  767 +
  768 + bodyPart.bodyContentLength = (unsigned long long)length;
  769 +
  770 + [self.bodyStream appendHTTPBodyPart:bodyPart];
  771 +}
  772 +
  773 +- (void)appendPartWithFileData:(NSData *)data
  774 + name:(NSString *)name
  775 + fileName:(NSString *)fileName
  776 + mimeType:(NSString *)mimeType
  777 +{
  778 + NSParameterAssert(name);
  779 + NSParameterAssert(fileName);
  780 + NSParameterAssert(mimeType);
  781 +
  782 + NSMutableDictionary *mutableHeaders = [NSMutableDictionary dictionary];
  783 + [mutableHeaders setValue:[NSString stringWithFormat:@"form-data; name=\"%@\"; filename=\"%@\"", name, fileName] forKey:@"Content-Disposition"];
  784 + [mutableHeaders setValue:mimeType forKey:@"Content-Type"];
  785 +
  786 + [self appendPartWithHeaders:mutableHeaders body:data];
  787 +}
  788 +
  789 +- (void)appendPartWithFormData:(NSData *)data
  790 + name:(NSString *)name
  791 +{
  792 + NSParameterAssert(name);
  793 +
  794 + NSMutableDictionary *mutableHeaders = [NSMutableDictionary dictionary];
  795 + [mutableHeaders setValue:[NSString stringWithFormat:@"form-data; name=\"%@\"", name] forKey:@"Content-Disposition"];
  796 +
  797 + [self appendPartWithHeaders:mutableHeaders body:data];
  798 +}
  799 +
  800 +- (void)appendPartWithHeaders:(NSDictionary *)headers
  801 + body:(NSData *)body
  802 +{
  803 + NSParameterAssert(body);
  804 +
  805 + AFHTTPBodyPart *bodyPart = [[AFHTTPBodyPart alloc] init];
  806 + bodyPart.stringEncoding = self.stringEncoding;
  807 + bodyPart.headers = headers;
  808 + bodyPart.boundary = self.boundary;
  809 + bodyPart.bodyContentLength = [body length];
  810 + bodyPart.body = body;
  811 +
  812 + [self.bodyStream appendHTTPBodyPart:bodyPart];
  813 +}
  814 +
  815 +- (void)throttleBandwidthWithPacketSize:(NSUInteger)numberOfBytes
  816 + delay:(NSTimeInterval)delay
  817 +{
  818 + self.bodyStream.numberOfBytesInPacket = numberOfBytes;
  819 + self.bodyStream.delay = delay;
  820 +}
  821 +
  822 +- (NSMutableURLRequest *)requestByFinalizingMultipartFormData {
  823 + if ([self.bodyStream isEmpty]) {
  824 + return self.request;
  825 + }
  826 +
  827 + // Reset the initial and final boundaries to ensure correct Content-Length
  828 + [self.bodyStream setInitialAndFinalBoundaries];
  829 + [self.request setHTTPBodyStream:self.bodyStream];
  830 +
  831 + [self.request setValue:[NSString stringWithFormat:@"multipart/form-data; boundary=%@", self.boundary] forHTTPHeaderField:@"Content-Type"];
  832 + [self.request setValue:[NSString stringWithFormat:@"%llu", [self.bodyStream contentLength]] forHTTPHeaderField:@"Content-Length"];
  833 +
  834 + return self.request;
  835 +}
  836 +
  837 +@end
  838 +
  839 +#pragma mark -
  840 +
  841 +@interface NSStream ()
  842 +@property (readwrite) NSStreamStatus streamStatus;
  843 +@property (readwrite, copy) NSError *streamError;
  844 +@end
  845 +
  846 +@interface AFMultipartBodyStream () <NSCopying>
  847 +@property (readwrite, nonatomic, assign) NSStringEncoding stringEncoding;
  848 +@property (readwrite, nonatomic, strong) NSMutableArray *HTTPBodyParts;
  849 +@property (readwrite, nonatomic, strong) NSEnumerator *HTTPBodyPartEnumerator;
  850 +@property (readwrite, nonatomic, strong) AFHTTPBodyPart *currentHTTPBodyPart;
  851 +@property (readwrite, nonatomic, strong) NSOutputStream *outputStream;
  852 +@property (readwrite, nonatomic, strong) NSMutableData *buffer;
  853 +@end
  854 +
  855 +@implementation AFMultipartBodyStream
  856 +#if (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000) || (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 1100)
  857 +@synthesize delegate;
  858 +#endif
  859 +@synthesize streamStatus;
  860 +@synthesize streamError;
  861 +
  862 +- (instancetype)initWithStringEncoding:(NSStringEncoding)encoding {
  863 + self = [super init];
  864 + if (!self) {
  865 + return nil;
  866 + }
  867 +
  868 + self.stringEncoding = encoding;
  869 + self.HTTPBodyParts = [NSMutableArray array];
  870 + self.numberOfBytesInPacket = NSIntegerMax;
  871 +
  872 + return self;
  873 +}
  874 +
  875 +- (void)setInitialAndFinalBoundaries {
  876 + if ([self.HTTPBodyParts count] > 0) {
  877 + for (AFHTTPBodyPart *bodyPart in self.HTTPBodyParts) {
  878 + bodyPart.hasInitialBoundary = NO;
  879 + bodyPart.hasFinalBoundary = NO;
  880 + }
  881 +
  882 + [[self.HTTPBodyParts firstObject] setHasInitialBoundary:YES];
  883 + [[self.HTTPBodyParts lastObject] setHasFinalBoundary:YES];
  884 + }
  885 +}
  886 +
  887 +- (void)appendHTTPBodyPart:(AFHTTPBodyPart *)bodyPart {
  888 + [self.HTTPBodyParts addObject:bodyPart];
  889 +}
  890 +
  891 +- (BOOL)isEmpty {
  892 + return [self.HTTPBodyParts count] == 0;
  893 +}
  894 +
  895 +#pragma mark - NSInputStream
  896 +
  897 +- (NSInteger)read:(uint8_t *)buffer
  898 + maxLength:(NSUInteger)length
  899 +{
  900 + if ([self streamStatus] == NSStreamStatusClosed) {
  901 + return 0;
  902 + }
  903 +
  904 + NSInteger totalNumberOfBytesRead = 0;
  905 +
  906 + while ((NSUInteger)totalNumberOfBytesRead < MIN(length, self.numberOfBytesInPacket)) {
  907 + if (!self.currentHTTPBodyPart || ![self.currentHTTPBodyPart hasBytesAvailable]) {
  908 + if (!(self.currentHTTPBodyPart = [self.HTTPBodyPartEnumerator nextObject])) {
  909 + break;
  910 + }
  911 + } else {
  912 + NSUInteger maxLength = MIN(length, self.numberOfBytesInPacket) - (NSUInteger)totalNumberOfBytesRead;
  913 + NSInteger numberOfBytesRead = [self.currentHTTPBodyPart read:&buffer[totalNumberOfBytesRead] maxLength:maxLength];
  914 + if (numberOfBytesRead == -1) {
  915 + self.streamError = self.currentHTTPBodyPart.inputStream.streamError;
  916 + break;
  917 + } else {
  918 + totalNumberOfBytesRead += numberOfBytesRead;
  919 +
  920 + if (self.delay > 0.0f) {
  921 + [NSThread sleepForTimeInterval:self.delay];
  922 + }
  923 + }
  924 + }
  925 + }
  926 +
  927 + return totalNumberOfBytesRead;
  928 +}
  929 +
  930 +- (BOOL)getBuffer:(__unused uint8_t **)buffer
  931 + length:(__unused NSUInteger *)len
  932 +{
  933 + return NO;
  934 +}
  935 +
  936 +- (BOOL)hasBytesAvailable {
  937 + return [self streamStatus] == NSStreamStatusOpen;
  938 +}
  939 +
  940 +#pragma mark - NSStream
  941 +
  942 +- (void)open {
  943 + if (self.streamStatus == NSStreamStatusOpen) {
  944 + return;
  945 + }
  946 +
  947 + self.streamStatus = NSStreamStatusOpen;
  948 +
  949 + [self setInitialAndFinalBoundaries];
  950 + self.HTTPBodyPartEnumerator = [self.HTTPBodyParts objectEnumerator];
  951 +}
  952 +
  953 +- (void)close {
  954 + self.streamStatus = NSStreamStatusClosed;
  955 +}
  956 +
  957 +- (id)propertyForKey:(__unused NSString *)key {
  958 + return nil;
  959 +}
  960 +
  961 +- (BOOL)setProperty:(__unused id)property
  962 + forKey:(__unused NSString *)key
  963 +{
  964 + return NO;
  965 +}
  966 +
  967 +- (void)scheduleInRunLoop:(__unused NSRunLoop *)aRunLoop
  968 + forMode:(__unused NSString *)mode
  969 +{}
  970 +
  971 +- (void)removeFromRunLoop:(__unused NSRunLoop *)aRunLoop
  972 + forMode:(__unused NSString *)mode
  973 +{}
  974 +
  975 +- (unsigned long long)contentLength {
  976 + unsigned long long length = 0;
  977 + for (AFHTTPBodyPart *bodyPart in self.HTTPBodyParts) {
  978 + length += [bodyPart contentLength];
  979 + }
  980 +
  981 + return length;
  982 +}
  983 +
  984 +#pragma mark - Undocumented CFReadStream Bridged Methods
  985 +
  986 +- (void)_scheduleInCFRunLoop:(__unused CFRunLoopRef)aRunLoop
  987 + forMode:(__unused CFStringRef)aMode
  988 +{}
  989 +
  990 +- (void)_unscheduleFromCFRunLoop:(__unused CFRunLoopRef)aRunLoop
  991 + forMode:(__unused CFStringRef)aMode
  992 +{}
  993 +
  994 +- (BOOL)_setCFClientFlags:(__unused CFOptionFlags)inFlags
  995 + callback:(__unused CFReadStreamClientCallBack)inCallback
  996 + context:(__unused CFStreamClientContext *)inContext {
  997 + return NO;
  998 +}
  999 +
  1000 +#pragma mark - NSCopying
  1001 +
  1002 +- (instancetype)copyWithZone:(NSZone *)zone {
  1003 + AFMultipartBodyStream *bodyStreamCopy = [[[self class] allocWithZone:zone] initWithStringEncoding:self.stringEncoding];
  1004 +
  1005 + for (AFHTTPBodyPart *bodyPart in self.HTTPBodyParts) {
  1006 + [bodyStreamCopy appendHTTPBodyPart:[bodyPart copy]];
  1007 + }
  1008 +
  1009 + [bodyStreamCopy setInitialAndFinalBoundaries];
  1010 +
  1011 + return bodyStreamCopy;
  1012 +}
  1013 +
  1014 +@end
  1015 +
  1016 +#pragma mark -
  1017 +
  1018 +typedef enum {
  1019 + AFEncapsulationBoundaryPhase = 1,
  1020 + AFHeaderPhase = 2,
  1021 + AFBodyPhase = 3,
  1022 + AFFinalBoundaryPhase = 4,
  1023 +} AFHTTPBodyPartReadPhase;
  1024 +
  1025 +@interface AFHTTPBodyPart () <NSCopying> {
  1026 + AFHTTPBodyPartReadPhase _phase;
  1027 + NSInputStream *_inputStream;
  1028 + unsigned long long _phaseReadOffset;
  1029 +}
  1030 +
  1031 +- (BOOL)transitionToNextPhase;
  1032 +- (NSInteger)readData:(NSData *)data
  1033 + intoBuffer:(uint8_t *)buffer
  1034 + maxLength:(NSUInteger)length;
  1035 +@end
  1036 +
  1037 +@implementation AFHTTPBodyPart
  1038 +
  1039 +- (instancetype)init {
  1040 + self = [super init];
  1041 + if (!self) {
  1042 + return nil;
  1043 + }
  1044 +
  1045 + [self transitionToNextPhase];
  1046 +
  1047 + return self;
  1048 +}
  1049 +
  1050 +- (void)dealloc {
  1051 + if (_inputStream) {
  1052 + [_inputStream close];
  1053 + _inputStream = nil;
  1054 + }
  1055 +}
  1056 +
  1057 +- (NSInputStream *)inputStream {
  1058 + if (!_inputStream) {
  1059 + if ([self.body isKindOfClass:[NSData class]]) {
  1060 + _inputStream = [NSInputStream inputStreamWithData:self.body];
  1061 + } else if ([self.body isKindOfClass:[NSURL class]]) {
  1062 + _inputStream = [NSInputStream inputStreamWithURL:self.body];
  1063 + } else if ([self.body isKindOfClass:[NSInputStream class]]) {
  1064 + _inputStream = self.body;
  1065 + } else {
  1066 + _inputStream = [NSInputStream inputStreamWithData:[NSData data]];
  1067 + }
  1068 + }
  1069 +
  1070 + return _inputStream;
  1071 +}
  1072 +
  1073 +- (NSString *)stringForHeaders {
  1074 + NSMutableString *headerString = [NSMutableString string];
  1075 + for (NSString *field in [self.headers allKeys]) {
  1076 + [headerString appendString:[NSString stringWithFormat:@"%@: %@%@", field, [self.headers valueForKey:field], kAFMultipartFormCRLF]];
  1077 + }
  1078 + [headerString appendString:kAFMultipartFormCRLF];
  1079 +
  1080 + return [NSString stringWithString:headerString];
  1081 +}
  1082 +
  1083 +- (unsigned long long)contentLength {
  1084 + unsigned long long length = 0;
  1085 +
  1086 + NSData *encapsulationBoundaryData = [([self hasInitialBoundary] ? AFMultipartFormInitialBoundary(self.boundary) : AFMultipartFormEncapsulationBoundary(self.boundary)) dataUsingEncoding:self.stringEncoding];
  1087 + length += [encapsulationBoundaryData length];
  1088 +
  1089 + NSData *headersData = [[self stringForHeaders] dataUsingEncoding:self.stringEncoding];
  1090 + length += [headersData length];
  1091 +
  1092 + length += _bodyContentLength;
  1093 +
  1094 + NSData *closingBoundaryData = ([self hasFinalBoundary] ? [AFMultipartFormFinalBoundary(self.boundary) dataUsingEncoding:self.stringEncoding] : [NSData data]);
  1095 + length += [closingBoundaryData length];
  1096 +
  1097 + return length;
  1098 +}
  1099 +
  1100 +- (BOOL)hasBytesAvailable {
  1101 + // Allows `read:maxLength:` to be called again if `AFMultipartFormFinalBoundary` doesn't fit into the available buffer
  1102 + if (_phase == AFFinalBoundaryPhase) {
  1103 + return YES;
  1104 + }
  1105 +
  1106 + switch (self.inputStream.streamStatus) {
  1107 + case NSStreamStatusNotOpen:
  1108 + case NSStreamStatusOpening:
  1109 + case NSStreamStatusOpen:
  1110 + case NSStreamStatusReading:
  1111 + case NSStreamStatusWriting:
  1112 + return YES;
  1113 + case NSStreamStatusAtEnd:
  1114 + case NSStreamStatusClosed:
  1115 + case NSStreamStatusError:
  1116 + default:
  1117 + return NO;
  1118 + }
  1119 +}
  1120 +
  1121 +- (NSInteger)read:(uint8_t *)buffer
  1122 + maxLength:(NSUInteger)length
  1123 +{
  1124 + NSInteger totalNumberOfBytesRead = 0;
  1125 +
  1126 + if (_phase == AFEncapsulationBoundaryPhase) {
  1127 + NSData *encapsulationBoundaryData = [([self hasInitialBoundary] ? AFMultipartFormInitialBoundary(self.boundary) : AFMultipartFormEncapsulationBoundary(self.boundary)) dataUsingEncoding:self.stringEncoding];
  1128 + totalNumberOfBytesRead += [self readData:encapsulationBoundaryData intoBuffer:&buffer[totalNumberOfBytesRead] maxLength:(length - (NSUInteger)totalNumberOfBytesRead)];
  1129 + }
  1130 +
  1131 + if (_phase == AFHeaderPhase) {
  1132 + NSData *headersData = [[self stringForHeaders] dataUsingEncoding:self.stringEncoding];
  1133 + totalNumberOfBytesRead += [self readData:headersData intoBuffer:&buffer[totalNumberOfBytesRead] maxLength:(length - (NSUInteger)totalNumberOfBytesRead)];
  1134 + }
  1135 +
  1136 + if (_phase == AFBodyPhase) {
  1137 + NSInteger numberOfBytesRead = 0;
  1138 +
  1139 + numberOfBytesRead = [self.inputStream read:&buffer[totalNumberOfBytesRead] maxLength:(length - (NSUInteger)totalNumberOfBytesRead)];
  1140 + if (numberOfBytesRead == -1) {
  1141 + return -1;
  1142 + } else {
  1143 + totalNumberOfBytesRead += numberOfBytesRead;
  1144 +
  1145 + if ([self.inputStream streamStatus] >= NSStreamStatusAtEnd) {
  1146 + [self transitionToNextPhase];
  1147 + }
  1148 + }
  1149 + }
  1150 +
  1151 + if (_phase == AFFinalBoundaryPhase) {
  1152 + NSData *closingBoundaryData = ([self hasFinalBoundary] ? [AFMultipartFormFinalBoundary(self.boundary) dataUsingEncoding:self.stringEncoding] : [NSData data]);
  1153 + totalNumberOfBytesRead += [self readData:closingBoundaryData intoBuffer:&buffer[totalNumberOfBytesRead] maxLength:(length - (NSUInteger)totalNumberOfBytesRead)];
  1154 + }
  1155 +
  1156 + return totalNumberOfBytesRead;
  1157 +}
  1158 +
  1159 +- (NSInteger)readData:(NSData *)data
  1160 + intoBuffer:(uint8_t *)buffer
  1161 + maxLength:(NSUInteger)length
  1162 +{
  1163 + NSRange range = NSMakeRange((NSUInteger)_phaseReadOffset, MIN([data length] - ((NSUInteger)_phaseReadOffset), length));
  1164 + [data getBytes:buffer range:range];
  1165 +
  1166 + _phaseReadOffset += range.length;
  1167 +
  1168 + if (((NSUInteger)_phaseReadOffset) >= [data length]) {
  1169 + [self transitionToNextPhase];
  1170 + }
  1171 +
  1172 + return (NSInteger)range.length;
  1173 +}
  1174 +
  1175 +- (BOOL)transitionToNextPhase {
  1176 + if (![[NSThread currentThread] isMainThread]) {
  1177 + dispatch_sync(dispatch_get_main_queue(), ^{
  1178 + [self transitionToNextPhase];
  1179 + });
  1180 + return YES;
  1181 + }
  1182 +
  1183 + switch (_phase) {
  1184 + case AFEncapsulationBoundaryPhase:
  1185 + _phase = AFHeaderPhase;
  1186 + break;
  1187 + case AFHeaderPhase:
  1188 + [self.inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
  1189 + [self.inputStream open];
  1190 + _phase = AFBodyPhase;
  1191 + break;
  1192 + case AFBodyPhase:
  1193 + [self.inputStream close];
  1194 + _phase = AFFinalBoundaryPhase;
  1195 + break;
  1196 + case AFFinalBoundaryPhase:
  1197 + default:
  1198 + _phase = AFEncapsulationBoundaryPhase;
  1199 + break;
  1200 + }
  1201 + _phaseReadOffset = 0;
  1202 +
  1203 + return YES;
  1204 +}
  1205 +
  1206 +#pragma mark - NSCopying
  1207 +
  1208 +- (instancetype)copyWithZone:(NSZone *)zone {
  1209 + AFHTTPBodyPart *bodyPart = [[[self class] allocWithZone:zone] init];
  1210 +
  1211 + bodyPart.stringEncoding = self.stringEncoding;
  1212 + bodyPart.headers = self.headers;
  1213 + bodyPart.bodyContentLength = self.bodyContentLength;
  1214 + bodyPart.body = self.body;
  1215 + bodyPart.boundary = self.boundary;
  1216 +
  1217 + return bodyPart;
  1218 +}
  1219 +
  1220 +@end
  1221 +
  1222 +#pragma mark -
  1223 +
  1224 +@implementation AFJSONRequestSerializer
  1225 +
  1226 ++ (instancetype)serializer {
  1227 + return [self serializerWithWritingOptions:(NSJSONWritingOptions)0];
  1228 +}
  1229 +
  1230 ++ (instancetype)serializerWithWritingOptions:(NSJSONWritingOptions)writingOptions
  1231 +{
  1232 + AFJSONRequestSerializer *serializer = [[self alloc] init];
  1233 + serializer.writingOptions = writingOptions;
  1234 +
  1235 + return serializer;
  1236 +}
  1237 +
  1238 +#pragma mark - AFURLRequestSerialization
  1239 +
  1240 +- (NSURLRequest *)requestBySerializingRequest:(NSURLRequest *)request
  1241 + withParameters:(id)parameters
  1242 + error:(NSError *__autoreleasing *)error
  1243 +{
  1244 + NSParameterAssert(request);
  1245 +
  1246 + if ([self.HTTPMethodsEncodingParametersInURI containsObject:[[request HTTPMethod] uppercaseString]]) {
  1247 + return [super requestBySerializingRequest:request withParameters:parameters error:error];
  1248 + }
  1249 +
  1250 + NSMutableURLRequest *mutableRequest = [request mutableCopy];
  1251 +
  1252 + [self.HTTPRequestHeaders enumerateKeysAndObjectsUsingBlock:^(id field, id value, BOOL * __unused stop) {
  1253 + if (![request valueForHTTPHeaderField:field]) {
  1254 + [mutableRequest setValue:value forHTTPHeaderField:field];
  1255 + }
  1256 + }];
  1257 +
  1258 + if (parameters) {
  1259 + if (![mutableRequest valueForHTTPHeaderField:@"Content-Type"]) {
  1260 + [mutableRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
  1261 + }
  1262 +
  1263 + if (![NSJSONSerialization isValidJSONObject:parameters]) {
  1264 + if (error) {
  1265 + NSDictionary *userInfo = @{NSLocalizedFailureReasonErrorKey: NSLocalizedStringFromTable(@"The `parameters` argument is not valid JSON.", @"AFNetworking", nil)};
  1266 + *error = [[NSError alloc] initWithDomain:AFURLRequestSerializationErrorDomain code:NSURLErrorCannotDecodeContentData userInfo:userInfo];
  1267 + }
  1268 + return nil;
  1269 + }
  1270 +
  1271 + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:parameters options:self.writingOptions error:error];
  1272 +
  1273 + if (!jsonData) {
  1274 + return nil;
  1275 + }
  1276 +
  1277 + [mutableRequest setHTTPBody:jsonData];
  1278 + }
  1279 +
  1280 + return mutableRequest;
  1281 +}
  1282 +
  1283 +#pragma mark - NSSecureCoding
  1284 +
  1285 +- (instancetype)initWithCoder:(NSCoder *)decoder {
  1286 + self = [super initWithCoder:decoder];
  1287 + if (!self) {
  1288 + return nil;
  1289 + }
  1290 +
  1291 + self.writingOptions = [[decoder decodeObjectOfClass:[NSNumber class] forKey:NSStringFromSelector(@selector(writingOptions))] unsignedIntegerValue];
  1292 +
  1293 + return self;
  1294 +}
  1295 +
  1296 +- (void)encodeWithCoder:(NSCoder *)coder {
  1297 + [super encodeWithCoder:coder];
  1298 +
  1299 + [coder encodeObject:@(self.writingOptions) forKey:NSStringFromSelector(@selector(writingOptions))];
  1300 +}
  1301 +
  1302 +#pragma mark - NSCopying
  1303 +
  1304 +- (instancetype)copyWithZone:(NSZone *)zone {
  1305 + AFJSONRequestSerializer *serializer = [super copyWithZone:zone];
  1306 + serializer.writingOptions = self.writingOptions;
  1307 +
  1308 + return serializer;
  1309 +}
  1310 +
  1311 +@end
  1312 +
  1313 +#pragma mark -
  1314 +
  1315 +@implementation AFPropertyListRequestSerializer
  1316 +
  1317 ++ (instancetype)serializer {
  1318 + return [self serializerWithFormat:NSPropertyListXMLFormat_v1_0 writeOptions:0];
  1319 +}
  1320 +
  1321 ++ (instancetype)serializerWithFormat:(NSPropertyListFormat)format
  1322 + writeOptions:(NSPropertyListWriteOptions)writeOptions
  1323 +{
  1324 + AFPropertyListRequestSerializer *serializer = [[self alloc] init];
  1325 + serializer.format = format;
  1326 + serializer.writeOptions = writeOptions;
  1327 +
  1328 + return serializer;
  1329 +}
  1330 +
  1331 +#pragma mark - AFURLRequestSerializer
  1332 +
  1333 +- (NSURLRequest *)requestBySerializingRequest:(NSURLRequest *)request
  1334 + withParameters:(id)parameters
  1335 + error:(NSError *__autoreleasing *)error
  1336 +{
  1337 + NSParameterAssert(request);
  1338 +
  1339 + if ([self.HTTPMethodsEncodingParametersInURI containsObject:[[request HTTPMethod] uppercaseString]]) {
  1340 + return [super requestBySerializingRequest:request withParameters:parameters error:error];
  1341 + }
  1342 +
  1343 + NSMutableURLRequest *mutableRequest = [request mutableCopy];
  1344 +
  1345 + [self.HTTPRequestHeaders enumerateKeysAndObjectsUsingBlock:^(id field, id value, BOOL * __unused stop) {
  1346 + if (![request valueForHTTPHeaderField:field]) {
  1347 + [mutableRequest setValue:value forHTTPHeaderField:field];
  1348 + }
  1349 + }];
  1350 +
  1351 + if (parameters) {
  1352 + if (![mutableRequest valueForHTTPHeaderField:@"Content-Type"]) {
  1353 + [mutableRequest setValue:@"application/x-plist" forHTTPHeaderField:@"Content-Type"];
  1354 + }
  1355 +
  1356 + NSData *plistData = [NSPropertyListSerialization dataWithPropertyList:parameters format:self.format options:self.writeOptions error:error];
  1357 +
  1358 + if (!plistData) {
  1359 + return nil;
  1360 + }
  1361 +
  1362 + [mutableRequest setHTTPBody:plistData];
  1363 + }
  1364 +
  1365 + return mutableRequest;
  1366 +}
  1367 +
  1368 +#pragma mark - NSSecureCoding
  1369 +
  1370 +- (instancetype)initWithCoder:(NSCoder *)decoder {
  1371 + self = [super initWithCoder:decoder];
  1372 + if (!self) {
  1373 + return nil;
  1374 + }
  1375 +
  1376 + self.format = (NSPropertyListFormat)[[decoder decodeObjectOfClass:[NSNumber class] forKey:NSStringFromSelector(@selector(format))] unsignedIntegerValue];
  1377 + self.writeOptions = [[decoder decodeObjectOfClass:[NSNumber class] forKey:NSStringFromSelector(@selector(writeOptions))] unsignedIntegerValue];
  1378 +
  1379 + return self;
  1380 +}
  1381 +
  1382 +- (void)encodeWithCoder:(NSCoder *)coder {
  1383 + [super encodeWithCoder:coder];
  1384 +
  1385 + [coder encodeObject:@(self.format) forKey:NSStringFromSelector(@selector(format))];
  1386 + [coder encodeObject:@(self.writeOptions) forKey:NSStringFromSelector(@selector(writeOptions))];
  1387 +}
  1388 +
  1389 +#pragma mark - NSCopying
  1390 +
  1391 +- (instancetype)copyWithZone:(NSZone *)zone {
  1392 + AFPropertyListRequestSerializer *serializer = [super copyWithZone:zone];
  1393 + serializer.format = self.format;
  1394 + serializer.writeOptions = self.writeOptions;
  1395 +
  1396 + return serializer;
  1397 +}
  1398 +
  1399 +@end
... ...
Example/Pods/AFNetworking/AFNetworking/AFURLResponseSerialization.h 0 → 100644
  1 +// AFURLResponseSerialization.h
  2 +// Copyright (c) 2011–2016 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 +
  22 +#import <Foundation/Foundation.h>
  23 +#import <CoreGraphics/CoreGraphics.h>
  24 +
  25 +NS_ASSUME_NONNULL_BEGIN
  26 +
  27 +/**
  28 + Recursively removes `NSNull` values from a JSON object.
  29 +*/
  30 +FOUNDATION_EXPORT id AFJSONObjectByRemovingKeysWithNullValues(id JSONObject, NSJSONReadingOptions readingOptions);
  31 +
  32 +/**
  33 + The `AFURLResponseSerialization` protocol is adopted by an object that decodes data into a more useful object representation, according to details in the server response. Response serializers may additionally perform validation on the incoming response and data.
  34 +
  35 + For example, a JSON response serializer may check for an acceptable status code (`2XX` range) and content type (`application/json`), decoding a valid JSON response into an object.
  36 + */
  37 +@protocol AFURLResponseSerialization <NSObject, NSSecureCoding, NSCopying>
  38 +
  39 +/**
  40 + The response object decoded from the data associated with a specified response.
  41 +
  42 + @param response The response to be processed.
  43 + @param data The response data to be decoded.
  44 + @param error The error that occurred while attempting to decode the response data.
  45 +
  46 + @return The object decoded from the specified response data.
  47 + */
  48 +- (nullable id)responseObjectForResponse:(nullable NSURLResponse *)response
  49 + data:(nullable NSData *)data
  50 + error:(NSError * _Nullable __autoreleasing *)error NS_SWIFT_NOTHROW;
  51 +
  52 +@end
  53 +
  54 +#pragma mark -
  55 +
  56 +/**
  57 + `AFHTTPResponseSerializer` conforms to the `AFURLRequestSerialization` & `AFURLResponseSerialization` protocols, offering a concrete base implementation of query string / URL form-encoded parameter serialization and default request headers, as well as response status code and content type validation.
  58 +
  59 + Any request or response serializer dealing with HTTP is encouraged to subclass `AFHTTPResponseSerializer` in order to ensure consistent default behavior.
  60 + */
  61 +@interface AFHTTPResponseSerializer : NSObject <AFURLResponseSerialization>
  62 +
  63 +- (instancetype)init;
  64 +
  65 +/**
  66 + Creates and returns a serializer with default configuration.
  67 + */
  68 ++ (instancetype)serializer;
  69 +
  70 +///-----------------------------------------
  71 +/// @name Configuring Response Serialization
  72 +///-----------------------------------------
  73 +
  74 +/**
  75 + The acceptable HTTP status codes for responses. When non-`nil`, responses with status codes not contained by the set will result in an error during validation.
  76 +
  77 + See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
  78 + */
  79 +@property (nonatomic, copy, nullable) NSIndexSet *acceptableStatusCodes;
  80 +
  81 +/**
  82 + The acceptable MIME types for responses. When non-`nil`, responses with a `Content-Type` with MIME types that do not intersect with the set will result in an error during validation.
  83 + */
  84 +@property (nonatomic, copy, nullable) NSSet <NSString *> *acceptableContentTypes;
  85 +
  86 +/**
  87 + Validates the specified response and data.
  88 +
  89 + In its base implementation, this method checks for an acceptable status code and content type. Subclasses may wish to add other domain-specific checks.
  90 +
  91 + @param response The response to be validated.
  92 + @param data The data associated with the response.
  93 + @param error The error that occurred while attempting to validate the response.
  94 +
  95 + @return `YES` if the response is valid, otherwise `NO`.
  96 + */
  97 +- (BOOL)validateResponse:(nullable NSHTTPURLResponse *)response
  98 + data:(nullable NSData *)data
  99 + error:(NSError * _Nullable __autoreleasing *)error;
  100 +
  101 +@end
  102 +
  103 +#pragma mark -
  104 +
  105 +
  106 +/**
  107 + `AFJSONResponseSerializer` is a subclass of `AFHTTPResponseSerializer` that validates and decodes JSON responses.
  108 +
  109 + By default, `AFJSONResponseSerializer` accepts the following MIME types, which includes the official standard, `application/json`, as well as other commonly-used types:
  110 +
  111 + - `application/json`
  112 + - `text/json`
  113 + - `text/javascript`
  114 +
  115 + In RFC 7159 - Section 8.1, it states that JSON text is required to be encoded in UTF-8, UTF-16, or UTF-32, and the default encoding is UTF-8. NSJSONSerialization provides support for all the encodings listed in the specification, and recommends UTF-8 for efficiency. Using an unsupported encoding will result in serialization error. See the `NSJSONSerialization` documentation for more details.
  116 + */
  117 +@interface AFJSONResponseSerializer : AFHTTPResponseSerializer
  118 +
  119 +- (instancetype)init;
  120 +
  121 +/**
  122 + Options for reading the response JSON data and creating the Foundation objects. For possible values, see the `NSJSONSerialization` documentation section "NSJSONReadingOptions". `0` by default.
  123 + */
  124 +@property (nonatomic, assign) NSJSONReadingOptions readingOptions;
  125 +
  126 +/**
  127 + Whether to remove keys with `NSNull` values from response JSON. Defaults to `NO`.
  128 + */
  129 +@property (nonatomic, assign) BOOL removesKeysWithNullValues;
  130 +
  131 +/**
  132 + Creates and returns a JSON serializer with specified reading and writing options.
  133 +
  134 + @param readingOptions The specified JSON reading options.
  135 + */
  136 ++ (instancetype)serializerWithReadingOptions:(NSJSONReadingOptions)readingOptions;
  137 +
  138 +@end
  139 +
  140 +#pragma mark -
  141 +
  142 +/**
  143 + `AFXMLParserResponseSerializer` is a subclass of `AFHTTPResponseSerializer` that validates and decodes XML responses as an `NSXMLParser` objects.
  144 +
  145 + By default, `AFXMLParserResponseSerializer` accepts the following MIME types, which includes the official standard, `application/xml`, as well as other commonly-used types:
  146 +
  147 + - `application/xml`
  148 + - `text/xml`
  149 + */
  150 +@interface AFXMLParserResponseSerializer : AFHTTPResponseSerializer
  151 +
  152 +@end
  153 +
  154 +#pragma mark -
  155 +
  156 +#ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
  157 +
  158 +/**
  159 + `AFXMLDocumentResponseSerializer` is a subclass of `AFHTTPResponseSerializer` that validates and decodes XML responses as an `NSXMLDocument` objects.
  160 +
  161 + By default, `AFXMLDocumentResponseSerializer` accepts the following MIME types, which includes the official standard, `application/xml`, as well as other commonly-used types:
  162 +
  163 + - `application/xml`
  164 + - `text/xml`
  165 + */
  166 +@interface AFXMLDocumentResponseSerializer : AFHTTPResponseSerializer
  167 +
  168 +- (instancetype)init;
  169 +
  170 +/**
  171 + Input and output options specifically intended for `NSXMLDocument` objects. For possible values, see the `NSXMLDocument` documentation section "Input and Output Options". `0` by default.
  172 + */
  173 +@property (nonatomic, assign) NSUInteger options;
  174 +
  175 +/**
  176 + Creates and returns an XML document serializer with the specified options.
  177 +
  178 + @param mask The XML document options.
  179 + */
  180 ++ (instancetype)serializerWithXMLDocumentOptions:(NSUInteger)mask;
  181 +
  182 +@end
  183 +
  184 +#endif
  185 +
  186 +#pragma mark -
  187 +
  188 +/**
  189 + `AFPropertyListResponseSerializer` is a subclass of `AFHTTPResponseSerializer` that validates and decodes XML responses as an `NSXMLDocument` objects.
  190 +
  191 + By default, `AFPropertyListResponseSerializer` accepts the following MIME types:
  192 +
  193 + - `application/x-plist`
  194 + */
  195 +@interface AFPropertyListResponseSerializer : AFHTTPResponseSerializer
  196 +
  197 +- (instancetype)init;
  198 +
  199 +/**
  200 + The property list format. Possible values are described in "NSPropertyListFormat".
  201 + */
  202 +@property (nonatomic, assign) NSPropertyListFormat format;
  203 +
  204 +/**
  205 + The property list reading options. Possible values are described in "NSPropertyListMutabilityOptions."
  206 + */
  207 +@property (nonatomic, assign) NSPropertyListReadOptions readOptions;
  208 +
  209 +/**
  210 + Creates and returns a property list serializer with a specified format, read options, and write options.
  211 +
  212 + @param format The property list format.
  213 + @param readOptions The property list reading options.
  214 + */
  215 ++ (instancetype)serializerWithFormat:(NSPropertyListFormat)format
  216 + readOptions:(NSPropertyListReadOptions)readOptions;
  217 +
  218 +@end
  219 +
  220 +#pragma mark -
  221 +
  222 +/**
  223 + `AFImageResponseSerializer` is a subclass of `AFHTTPResponseSerializer` that validates and decodes image responses.
  224 +
  225 + By default, `AFImageResponseSerializer` accepts the following MIME types, which correspond to the image formats supported by UIImage or NSImage:
  226 +
  227 + - `image/tiff`
  228 + - `image/jpeg`
  229 + - `image/gif`
  230 + - `image/png`
  231 + - `image/ico`
  232 + - `image/x-icon`
  233 + - `image/bmp`
  234 + - `image/x-bmp`
  235 + - `image/x-xbitmap`
  236 + - `image/x-win-bitmap`
  237 + */
  238 +@interface AFImageResponseSerializer : AFHTTPResponseSerializer
  239 +
  240 +#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_WATCH
  241 +/**
  242 + The scale factor used when interpreting the image data to construct `responseImage`. Specifying a scale factor of 1.0 results in an image whose size matches the pixel-based dimensions of the image. Applying a different scale factor changes the size of the image as reported by the size property. This is set to the value of scale of the main screen by default, which automatically scales images for retina displays, for instance.
  243 + */
  244 +@property (nonatomic, assign) CGFloat imageScale;
  245 +
  246 +/**
  247 + Whether to automatically inflate response image data for compressed formats (such as PNG or JPEG). Enabling this can significantly improve drawing performance on iOS when used with `setCompletionBlockWithSuccess:failure:`, as it allows a bitmap representation to be constructed in the background rather than on the main thread. `YES` by default.
  248 + */
  249 +@property (nonatomic, assign) BOOL automaticallyInflatesResponseImage;
  250 +#endif
  251 +
  252 +@end
  253 +
  254 +#pragma mark -
  255 +
  256 +/**
  257 + `AFCompoundSerializer` is a subclass of `AFHTTPResponseSerializer` that delegates the response serialization to the first `AFHTTPResponseSerializer` object that returns an object for `responseObjectForResponse:data:error:`, falling back on the default behavior of `AFHTTPResponseSerializer`. This is useful for supporting multiple potential types and structures of server responses with a single serializer.
  258 + */
  259 +@interface AFCompoundResponseSerializer : AFHTTPResponseSerializer
  260 +
  261 +/**
  262 + The component response serializers.
  263 + */
  264 +@property (readonly, nonatomic, copy) NSArray <id<AFURLResponseSerialization>> *responseSerializers;
  265 +
  266 +/**
  267 + Creates and returns a compound serializer comprised of the specified response serializers.
  268 +
  269 + @warning Each response serializer specified must be a subclass of `AFHTTPResponseSerializer`, and response to `-validateResponse:data:error:`.
  270 + */
  271 ++ (instancetype)compoundSerializerWithResponseSerializers:(NSArray <id<AFURLResponseSerialization>> *)responseSerializers;
  272 +
  273 +@end
  274 +
  275 +///----------------
  276 +/// @name Constants
  277 +///----------------
  278 +
  279 +/**
  280 + ## Error Domains
  281 +
  282 + The following error domain is predefined.
  283 +
  284 + - `NSString * const AFURLResponseSerializationErrorDomain`
  285 +
  286 + ### Constants
  287 +
  288 + `AFURLResponseSerializationErrorDomain`
  289 + AFURLResponseSerializer errors. Error codes for `AFURLResponseSerializationErrorDomain` correspond to codes in `NSURLErrorDomain`.
  290 + */
  291 +FOUNDATION_EXPORT NSString * const AFURLResponseSerializationErrorDomain;
  292 +
  293 +/**
  294 + ## User info dictionary keys
  295 +
  296 + These keys may exist in the user info dictionary, in addition to those defined for NSError.
  297 +
  298 + - `NSString * const AFNetworkingOperationFailingURLResponseErrorKey`
  299 + - `NSString * const AFNetworkingOperationFailingURLResponseDataErrorKey`
  300 +
  301 + ### Constants
  302 +
  303 + `AFNetworkingOperationFailingURLResponseErrorKey`
  304 + The corresponding value is an `NSURLResponse` containing the response of the operation associated with an error. This key is only present in the `AFURLResponseSerializationErrorDomain`.
  305 +
  306 + `AFNetworkingOperationFailingURLResponseDataErrorKey`
  307 + The corresponding value is an `NSData` containing the original data of the operation associated with an error. This key is only present in the `AFURLResponseSerializationErrorDomain`.
  308 + */
  309 +FOUNDATION_EXPORT NSString * const AFNetworkingOperationFailingURLResponseErrorKey;
  310 +
  311 +FOUNDATION_EXPORT NSString * const AFNetworkingOperationFailingURLResponseDataErrorKey;
  312 +
  313 +NS_ASSUME_NONNULL_END
... ...