Skip to content

Commit

Permalink
Updated Library to support watchOS
Browse files Browse the repository at this point in the history
  • Loading branch information
kcharwood committed Aug 3, 2015
1 parent c9bbbeb commit d184833
Show file tree
Hide file tree
Showing 23 changed files with 679 additions and 14 deletions.
10 changes: 8 additions & 2 deletions AFNetworking.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ Pod::Spec.new do |s|

s.ios.deployment_target = '6.0'
s.osx.deployment_target = '10.8'
s.watchos.deployment_target = '2.0'

s.public_header_files = 'AFNetworking/*.h'
s.source_files = 'AFNetworking/AFNetworking.h'

s.subspec 'Serialization' do |ss|
ss.source_files = 'AFNetworking/AFURL{Request,Response}Serialization.{h,m}'
ss.watchos.frameworks = 'MobileCoreServices', 'CoreGraphics'
ss.ios.frameworks = 'MobileCoreServices', 'CoreGraphics'
ss.osx.frameworks = 'CoreServices'
end
Expand All @@ -28,15 +30,18 @@ Pod::Spec.new do |s|

s.subspec 'Reachability' do |ss|
ss.source_files = 'AFNetworking/AFNetworkReachabilityManager.{h,m}'
ss.frameworks = 'SystemConfiguration'
ss.ios.frameworks = 'SystemConfiguration'
ss.osx.frameworks = 'SystemConfiguration'
end

s.subspec 'NSURLConnection' do |ss|
ss.dependency 'AFNetworking/Serialization'
ss.dependency 'AFNetworking/Reachability'
ss.dependency 'AFNetworking/Security'

ss.source_files = 'AFNetworking/AFURLConnectionOperation.{h,m}', 'AFNetworking/AFHTTPRequestOperation.{h,m}', 'AFNetworking/AFHTTPRequestOperationManager.{h,m}'
ss.ios.source_files = 'AFNetworking/AFURLConnectionOperation.{h,m}', 'AFNetworking/AFHTTPRequestOperation.{h,m}', 'AFNetworking/AFHTTPRequestOperationManager.{h,m}'
ss.osx.source_files = 'AFNetworking/AFURLConnectionOperation.{h,m}', 'AFNetworking/AFHTTPRequestOperation.{h,m}', 'AFNetworking/AFHTTPRequestOperationManager.{h,m}'
ss.watchos.source_files = ''
end

s.subspec 'NSURLSession' do |ss|
Expand All @@ -56,5 +61,6 @@ Pod::Spec.new do |s|
ss.ios.public_header_files = 'UIKit+AFNetworking/*.h'
ss.ios.source_files = 'UIKit+AFNetworking'
ss.osx.source_files = ''
ss.watchos.source_files = ''
end
end
4 changes: 3 additions & 1 deletion AFNetworking/AFHTTPSessionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
// THE SOFTWARE.

#import <Foundation/Foundation.h>
#if !TARGET_OS_WATCH
#import <SystemConfiguration/SystemConfiguration.h>
#endif
#import <Availability.h>

#if __IPHONE_OS_VERSION_MIN_REQUIRED
Expand Down Expand Up @@ -77,7 +79,7 @@
@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.
*/

#if (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000) || (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 1090)
#if (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000) || (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 1090) || TARGET_OS_WATCH

NS_ASSUME_NONNULL_BEGIN

Expand Down
6 changes: 4 additions & 2 deletions AFNetworking/AFHTTPSessionManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#import "AFHTTPSessionManager.h"

#if (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000) || (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 1090)
#if (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000) || (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 1090) || TARGET_WATCH_OS

#import "AFURLRequestSerialization.h"
#import "AFURLResponseSerialization.h"
Expand All @@ -37,8 +37,10 @@
#import <netdb.h>
#endif

#if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
#if TARGET_OS_IOS
#import <UIKit/UIKit.h>
#elif TARGET_OS_WATCH
#import <WatchKit/WatchKit.h>
#endif

@interface AFHTTPSessionManager ()
Expand Down
3 changes: 3 additions & 0 deletions AFNetworking/AFNetworkReachabilityManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
// THE SOFTWARE.

#import <Foundation/Foundation.h>

#if !TARGET_OS_WATCH
#import <SystemConfiguration/SystemConfiguration.h>

#ifndef NS_DESIGNATED_INITIALIZER
Expand Down Expand Up @@ -202,3 +204,4 @@ extern NSString * const AFNetworkingReachabilityNotificationStatusItem;
extern NSString * AFStringFromNetworkReachabilityStatus(AFNetworkReachabilityStatus status);

NS_ASSUME_NONNULL_END
#endif
2 changes: 2 additions & 0 deletions AFNetworking/AFNetworkReachabilityManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// THE SOFTWARE.

#import "AFNetworkReachabilityManager.h"
#if !TARGET_OS_WATCH

#import <netinet/in.h>
#import <netinet6/in6.h>
Expand Down Expand Up @@ -262,3 +263,4 @@ + (NSSet *)keyPathsForValuesAffectingValueForKey:(NSString *)key {
}

@end
#endif
6 changes: 4 additions & 2 deletions AFNetworking/AFNetworking.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@
#import "AFURLRequestSerialization.h"
#import "AFURLResponseSerialization.h"
#import "AFSecurityPolicy.h"
#if !TARGET_OS_WATCH
#import "AFNetworkReachabilityManager.h"

#import "AFURLConnectionOperation.h"
#import "AFHTTPRequestOperation.h"
#import "AFHTTPRequestOperationManager.h"
#endif

#if ( ( defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 1090) || \
( defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000 ) )
( defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000 ) || \
TARGET_OS_WATCH )
#import "AFURLSessionManager.h"
#import "AFHTTPSessionManager.h"
#endif
Expand Down
4 changes: 2 additions & 2 deletions AFNetworking/AFSecurityPolicy.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#import <AssertMacros.h>

#if !defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
#if !TARGET_OS_IOS && !TARGET_OS_WATCH
static NSData * AFSecKeyGetData(SecKeyRef key) {
CFDataRef data = NULL;

Expand All @@ -41,7 +41,7 @@
#endif

static BOOL AFSecKeyIsEqualToKey(SecKeyRef key1, SecKeyRef key2) {
#if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
#if TARGET_OS_IOS || TARGET_OS_WATCH
return [(__bridge id)key1 isEqual:(__bridge id)key2];
#else
return [AFSecKeyGetData(key1) isEqual:AFSecKeyGetData(key2)];
Expand Down
4 changes: 3 additions & 1 deletion AFNetworking/AFURLRequestSerialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
// THE SOFTWARE.

#import <Foundation/Foundation.h>
#if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
#if TARGET_OS_IOS
#import <UIKit/UIKit.h>
#elif TARGET_OS_WATCH
#import <WatchKit/WatchKit.h>
#endif

NS_ASSUME_NONNULL_BEGIN
Expand Down
5 changes: 4 additions & 1 deletion AFNetworking/AFURLRequestSerialization.m
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,12 @@ - (instancetype)init {
NSString *userAgent = nil;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wgnu"
#if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
#if TARGET_OS_IOS
// User-Agent Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.43
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]];
#elif TARGET_OS_WATCH
// User-Agent Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.43
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]];
#elif defined(__MAC_OS_X_VERSION_MIN_REQUIRED)
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]];
#endif
Expand Down
9 changes: 7 additions & 2 deletions AFNetworking/AFURLResponseSerialization.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@

#import "AFURLResponseSerialization.h"

#if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
#if TARGET_OS_IOS
#import <UIKit/UIKit.h>
#elif TARGET_OS_WATCH
#import <WatchKit/WatchKit.h>
#elif defined(__MAC_OS_X_VERSION_MIN_REQUIRED)
#import <Cocoa/Cocoa.h>
#endif
Expand Down Expand Up @@ -665,9 +667,12 @@ - (instancetype)init {

self.acceptableContentTypes = [[NSSet alloc] initWithObjects:@"image/tiff", @"image/jpeg", @"image/gif", @"image/png", @"image/ico", @"image/x-icon", @"image/bmp", @"image/x-bmp", @"image/x-xbitmap", @"image/x-win-bitmap", nil];

#if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
#if TARGET_OS_IOS
self.imageScale = [[UIScreen mainScreen] scale];
self.automaticallyInflatesResponseImage = YES;
#elif TARGET_OS_WATCH
self.imageScale = [[WKInterfaceDevice currentDevice] screenScale];
self.automaticallyInflatesResponseImage = YES;
#endif

return self;
Expand Down
6 changes: 5 additions & 1 deletion AFNetworking/AFURLSessionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
#import "AFURLResponseSerialization.h"
#import "AFURLRequestSerialization.h"
#import "AFSecurityPolicy.h"
#if !TARGET_OS_WATCH
#import "AFNetworkReachabilityManager.h"
#endif

#ifndef NS_DESIGNATED_INITIALIZER
#if __has_attribute(objc_designated_initializer)
Expand Down Expand Up @@ -91,7 +93,7 @@

NS_ASSUME_NONNULL_BEGIN

#if (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000) || (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 1090)
#if (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000) || (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 1090) || TARGET_OS_WATCH

@interface AFURLSessionManager : NSObject <NSURLSessionDelegate, NSURLSessionTaskDelegate, NSURLSessionDataDelegate, NSURLSessionDownloadDelegate, NSSecureCoding, NSCopying>

Expand Down Expand Up @@ -121,6 +123,7 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic, strong) AFSecurityPolicy *securityPolicy;

#if !TARGET_OS_WATCH
///--------------------------------------
/// @name Monitoring Network Reachability
///--------------------------------------
Expand All @@ -129,6 +132,7 @@ NS_ASSUME_NONNULL_BEGIN
The network reachability manager. `AFURLSessionManager` uses the `sharedManager` by default.
*/
@property (readwrite, nonatomic, strong) AFNetworkReachabilityManager *reachabilityManager;
#endif

///----------------------------
/// @name Getting Session Tasks
Expand Down
2 changes: 2 additions & 0 deletions AFNetworking/AFURLSessionManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,9 @@ - (instancetype)initWithSessionConfiguration:(NSURLSessionConfiguration *)config

self.securityPolicy = [AFSecurityPolicy defaultPolicy];

#if !TARGET_OS_WATCH
self.reachabilityManager = [AFNetworkReachabilityManager sharedManager];
#endif

self.mutableTaskDelegatesKeyedByTaskIdentifier = [[NSMutableDictionary alloc] init];

Expand Down
Loading

0 comments on commit d184833

Please sign in to comment.