Skip to content

Commit

Permalink
Request resume, suspend and cancel APIs now post notifications.
Browse files Browse the repository at this point in the history
This is necessary to support the network activity indicator.
  • Loading branch information
cnoon committed Feb 7, 2016
1 parent caf937f commit 1bd2a6a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
10 changes: 10 additions & 0 deletions Alamofire.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@
4C83F41D1B749E0E00203445 /* Stream.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C83F41A1B749E0E00203445 /* Stream.swift */; };
4CA028C51B7466C500C84163 /* ResultTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CA028C41B7466C500C84163 /* ResultTests.swift */; };
4CA028C61B7466C500C84163 /* ResultTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CA028C41B7466C500C84163 /* ResultTests.swift */; };
4CB928291C66BFBC00CE5F08 /* NotificationNames.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CB928281C66BFBC00CE5F08 /* NotificationNames.swift */; };
4CB9282A1C66BFBC00CE5F08 /* NotificationNames.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CB928281C66BFBC00CE5F08 /* NotificationNames.swift */; };
4CB9282B1C66BFBC00CE5F08 /* NotificationNames.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CB928281C66BFBC00CE5F08 /* NotificationNames.swift */; };
4CB9282C1C66BFBC00CE5F08 /* NotificationNames.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CB928281C66BFBC00CE5F08 /* NotificationNames.swift */; };
4CCFA79A1B2BE71600B6F460 /* URLProtocolTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CCFA7991B2BE71600B6F460 /* URLProtocolTests.swift */; };
4CCFA79B1B2BE71600B6F460 /* URLProtocolTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CCFA7991B2BE71600B6F460 /* URLProtocolTests.swift */; };
4CDE2C371AF8932A00BABAE5 /* Manager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CDE2C361AF8932A00BABAE5 /* Manager.swift */; };
Expand Down Expand Up @@ -255,6 +259,7 @@
4C812C601B535F6D0017E0BF /* testssl-expire.disig.sk.cer */ = {isa = PBXFileReference; lastKnownFileType = file; name = "testssl-expire.disig.sk.cer"; path = "disig.sk/testssl-expire.disig.sk.cer"; sourceTree = "<group>"; };
4C83F41A1B749E0E00203445 /* Stream.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Stream.swift; sourceTree = "<group>"; };
4CA028C41B7466C500C84163 /* ResultTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ResultTests.swift; sourceTree = "<group>"; };
4CB928281C66BFBC00CE5F08 /* NotificationNames.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NotificationNames.swift; sourceTree = "<group>"; };
4CCFA7991B2BE71600B6F460 /* URLProtocolTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = URLProtocolTests.swift; sourceTree = "<group>"; };
4CDE2C361AF8932A00BABAE5 /* Manager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Manager.swift; sourceTree = "<group>"; };
4CDE2C391AF899EC00BABAE5 /* Request.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Request.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -491,6 +496,7 @@
children = (
4C1DC8531B68908E00476DE3 /* Error.swift */,
4CDE2C361AF8932A00BABAE5 /* Manager.swift */,
4CB928281C66BFBC00CE5F08 /* NotificationNames.swift */,
4CE2724E1AF88FB500F1D59A /* ParameterEncoding.swift */,
4CDE2C391AF899EC00BABAE5 /* Request.swift */,
4C0B62501BB1001C009302D3 /* Response.swift */,
Expand Down Expand Up @@ -946,6 +952,7 @@
4CF627131BA7CBF60011A099 /* Validation.swift in Sources */,
4CF6270E1BA7CBF60011A099 /* MultipartFormData.swift in Sources */,
4C80F9F81BB730EF001B46D2 /* Response.swift in Sources */,
4CB9282B1C66BFBC00CE5F08 /* NotificationNames.swift in Sources */,
4CF627091BA7CBF60011A099 /* Manager.swift in Sources */,
4CF6270F1BA7CBF60011A099 /* ResponseSerialization.swift in Sources */,
4CF6270B1BA7CBF60011A099 /* Request.swift in Sources */,
Expand Down Expand Up @@ -992,6 +999,7 @@
4C1DC8551B68908E00476DE3 /* Error.swift in Sources */,
4CDE2C381AF8932A00BABAE5 /* Manager.swift in Sources */,
4C0B62521BB1001C009302D3 /* Response.swift in Sources */,
4CB9282A1C66BFBC00CE5F08 /* NotificationNames.swift in Sources */,
4DD67C251A5C590000ED2280 /* Alamofire.swift in Sources */,
4C23EB441B327C5B0090E0BC /* MultipartFormData.swift in Sources */,
4C811F8E1B51856D00E0F59A /* ServerTrustPolicy.swift in Sources */,
Expand All @@ -1013,6 +1021,7 @@
E4202FD21B667AA100C997FB /* ResponseSerialization.swift in Sources */,
E4202FD31B667AA100C997FB /* Manager.swift in Sources */,
4C0B62531BB1001C009302D3 /* Response.swift in Sources */,
4CB9282C1C66BFBC00CE5F08 /* NotificationNames.swift in Sources */,
4CEC605B1B745C9100E684F4 /* Result.swift in Sources */,
E4202FD41B667AA100C997FB /* Alamofire.swift in Sources */,
E4202FD51B667AA100C997FB /* MultipartFormData.swift in Sources */,
Expand Down Expand Up @@ -1040,6 +1049,7 @@
4C83F41B1B749E0E00203445 /* Stream.swift in Sources */,
4CDE2C3D1AF89D4900BABAE5 /* Download.swift in Sources */,
4CDE2C431AF89F0900BABAE5 /* Validation.swift in Sources */,
4CB928291C66BFBC00CE5F08 /* NotificationNames.swift in Sources */,
4C0E5BF81B673D3400816CCC /* Result.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
29 changes: 29 additions & 0 deletions Source/NotificationNames.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// NotificationNames.swift
//
// Copyright (c) 2014–2016 Alamofire Software Foundation (http://alamofire.org/)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import Foundation

public struct NotificationNames {
public static let TaskDidResume = "com.alamofire.task.did.resume"
public static let TaskDidSuspend = "com.alamofire.task.did.suspend"
public static let TaskDidCancel = "com.alamofire.task.did.suspend"
}
16 changes: 10 additions & 6 deletions Source/Request.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,19 @@ public class Request {
// MARK: - State

/**
Suspends the request.
Resumes the request.
*/
public func suspend() {
task.suspend()
public func resume() {
task.resume()
NSNotificationCenter.defaultCenter().postNotificationName(NotificationNames.TaskDidResume, object: nil)
}

/**
Resumes the request.
Suspends the request.
*/
public func resume() {
task.resume()
public func suspend() {
task.suspend()
NSNotificationCenter.defaultCenter().postNotificationName(NotificationNames.TaskDidSuspend, object: nil)
}

/**
Expand All @@ -176,6 +178,8 @@ public class Request {
} else {
task.cancel()
}

NSNotificationCenter.defaultCenter().postNotificationName(NotificationNames.TaskDidCancel, object: nil)
}

// MARK: - TaskDelegate
Expand Down

0 comments on commit 1bd2a6a

Please sign in to comment.