Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
[Issue #2119] Adding check for AF_APP_EXTENSIONS macro to conditional…
Browse files Browse the repository at this point in the history
…ly compile background method that makes unavailable API (+[UIApplication sharedApplication] call in app extensions
  • Loading branch information
mattt committed Jun 11, 2014
1 parent 7e2c4e3 commit 5b0638f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 6 additions & 2 deletions AFNetworking/AFURLConnectionOperation.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
SSL with certificate pinning is strongly recommended for any application that transmits sensitive information to an external webservice.
Connections will be validated on all matching certificates with a `.cer` extension in the bundle root.
## App Extensions
When using AFNetworking in an App Extension, `#define AF_APP_EXTENSIONS` to avoid using unavailable APIs.
## NSCoding & NSCopying Conformance
Expand Down Expand Up @@ -245,8 +249,8 @@
Specifies that the operation should continue execution after the app has entered the background, and the expiration handler for that background task.
@param handler A handler to be called shortly before the application’s remaining background time reaches 0. The handler is wrapped in a block that cancels the operation, and cleans up and marks the end of execution, unlike the `handler` parameter in `UIApplication -beginBackgroundTaskWithExpirationHandler:`, which expects this to be done in the handler itself. The handler is called synchronously on the main thread, thus blocking the application’s suspension momentarily while the application is notified.
*/
#if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
*/
#if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && !defined(AF_APP_EXTENSIONS)
- (void)setShouldExecuteAsBackgroundTaskWithExpirationHandler:(void (^)(void))handler;
#endif

Expand Down
6 changes: 3 additions & 3 deletions AFNetworking/AFURLConnectionOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ typedef NS_ENUM(NSInteger, AFOperationState) {
AFOperationFinishedState = 3,
};

#if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
#if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && !defined(AF_APP_EXTENSIONS)
typedef UIBackgroundTaskIdentifier AFBackgroundTaskIdentifier;
#else
typedef id AFBackgroundTaskIdentifier;
Expand Down Expand Up @@ -215,7 +215,7 @@ - (void)dealloc {
_outputStream = nil;
}

#if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
#if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && !defined(AF_APP_EXTENSIONS)
if (_backgroundTaskIdentifier) {
[[UIApplication sharedApplication] endBackgroundTask:_backgroundTaskIdentifier];
_backgroundTaskIdentifier = UIBackgroundTaskInvalid;
Expand Down Expand Up @@ -293,7 +293,7 @@ - (void)setOutputStream:(NSOutputStream *)outputStream {
[self.lock unlock];
}

#if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
#if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && !defined(AF_APP_EXTENSIONS)
- (void)setShouldExecuteAsBackgroundTaskWithExpirationHandler:(void (^)(void))handler {
[self.lock lock];
if (!self.backgroundTaskIdentifier) {
Expand Down

0 comments on commit 5b0638f

Please sign in to comment.