Skip to content

Commit

Permalink
add deprecated methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo Vandriel committed Jan 7, 2016
1 parent 2458c41 commit a8cd4e5
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 32 deletions.
7 changes: 7 additions & 0 deletions Classes/NWHub.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,11 @@
*/
- (BOOL)trimIdentifiers;

// deprecated

+ (instancetype)connectWithDelegate:(id<NWHubDelegate>)delegate identity:(NWIdentityRef)identity error:(NSError **)error __deprecated;
+ (instancetype)connectWithDelegate:(id<NWHubDelegate>)delegate PKCS12Data:(NSData *)data password:(NSString *)password error:(NSError **)error __deprecated;
- (BOOL)connectWithIdentity:(NWIdentityRef)identity error:(NSError **)error __deprecated;
- (BOOL)connectWithPKCS12Data:(NSData *)data password:(NSString *)password error:(NSError **)error __deprecated;

@end
22 changes: 22 additions & 0 deletions Classes/NWHub.m
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,26 @@ - (BOOL)trimIdentifiers
return !!old.count;
}

#pragma mark - Deprecated

- (BOOL)connectWithIdentity:(NWIdentityRef)identity error:(NSError *__autoreleasing *)error
{
return [self connectWithIdentity:identity environment:NWEnvironmentAuto error:error];
}

- (BOOL)connectWithPKCS12Data:(NSData *)data password:(NSString *)password error:(NSError *__autoreleasing *)error
{
return [self connectWithPKCS12Data:data password:password environment:NWEnvironmentAuto error:error];
}

+ (instancetype)connectWithDelegate:(id<NWHubDelegate>)delegate identity:(NWIdentityRef)identity error:(NSError *__autoreleasing *)error
{
return [self connectWithDelegate:delegate identity:identity environment:NWEnvironmentAuto error:error];
}

+ (instancetype)connectWithDelegate:(id<NWHubDelegate>)delegate PKCS12Data:(NSData *)data password:(NSString *)password error:(NSError *__autoreleasing *)error
{
return [self connectWithDelegate:delegate identity:data environment:NWEnvironmentAuto error:error];
}

@end
8 changes: 7 additions & 1 deletion Classes/NWPushFeedback.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//

#import "NWType.h"

#import <Foundation/Foundation.h>

@class NWSSLConnection;
Expand Down Expand Up @@ -55,4 +54,11 @@
/** Read all (or max) token-date pairs, where token is hex string. */
- (NSArray *)readTokenDatePairsWithMax:(NSUInteger)max error:(NSError **)error;

// deprecated

+ (instancetype)connectWithIdentity:(NWIdentityRef)identity error:(NSError **)error __deprecated;
+ (instancetype)connectWithPKCS12Data:(NSData *)data password:(NSString *)password error:(NSError **)error __deprecated;
- (BOOL)connectWithIdentity:(NWIdentityRef)identity error:(NSError **)error __deprecated;
- (BOOL)connectWithPKCS12Data:(NSData *)data password:(NSString *)password error:(NSError **)error __deprecated;

@end
24 changes: 23 additions & 1 deletion Classes/NWPushFeedback.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ @implementation NWPushFeedback
- (BOOL)connectWithIdentity:(NWIdentityRef)identity environment:(NWEnvironment)environment error:(NSError *__autoreleasing *)error
{
if (_connection) [_connection disconnect]; _connection = nil;

if (environment == NWEnvironmentAuto) environment = [NWSecTools environmentForIdentity:identity];
NSString *host = (environment == NWEnvironmentSandbox) ? NWSandboxPushHost : NWPushHost;
NWSSLConnection *connection = [[NWSSLConnection alloc] initWithHost:host port:NWPushPort identity:identity];
BOOL connected = [connection connectWithError:error];
Expand Down Expand Up @@ -123,4 +123,26 @@ - (NSArray *)readTokenDatePairsWithMax:(NSUInteger)max error:(NSError *__autorel
return pairs;
}

#pragma mark - Deprecated

- (BOOL)connectWithIdentity:(NWIdentityRef)identity error:(NSError *__autoreleasing *)error
{
return [self connectWithIdentity:identity environment:NWEnvironmentAuto error:error];
}

- (BOOL)connectWithPKCS12Data:(NSData *)data password:(NSString *)password error:(NSError *__autoreleasing *)error
{
return [self connectWithPKCS12Data:data password:password environment:NWEnvironmentAuto error:error];
}

+ (instancetype)connectWithIdentity:(NWIdentityRef)identity error:(NSError *__autoreleasing *)error
{
return [self connectWithIdentity:identity environment:NWEnvironmentAuto error:error];
}

+ (instancetype)connectWithPKCS12Data:(NSData *)data password:(NSString *)password error:(NSError *__autoreleasing *)error
{
return [self connectWithPKCS12Data:data password:password environment:NWEnvironmentAuto error:error];
}

@end
7 changes: 7 additions & 0 deletions Classes/NWPusher.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,11 @@
/** Read back multiple notification identifiers of, up to max, failed pushes. */
- (NSArray *)readFailedIdentifierErrorPairsWithMax:(NSUInteger)max error:(NSError **)error;

// deprecated

+ (instancetype)connectWithIdentity:(NWIdentityRef)identity error:(NSError **)error __deprecated;
+ (instancetype)connectWithPKCS12Data:(NSData *)data password:(NSString *)password error:(NSError **)error __deprecated;
- (BOOL)connectWithIdentity:(NWIdentityRef)identity error:(NSError **)error __deprecated;
- (BOOL)connectWithPKCS12Data:(NSData *)data password:(NSString *)password error:(NSError **)error __deprecated;

@end
26 changes: 24 additions & 2 deletions Classes/NWPusher.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ @implementation NWPusher
- (BOOL)connectWithIdentity:(NWIdentityRef)identity environment:(NWEnvironment)environment error:(NSError *__autoreleasing *)error
{
if (_connection) [_connection disconnect]; _connection = nil;

if (environment == NWEnvironmentAuto) environment = [NWSecTools environmentForIdentity:identity];
NSString *host = (environment == NWEnvironmentSandbox) ? NWSandboxPushHost : NWPushHost;
NWSSLConnection *connection = [[NWSSLConnection alloc] initWithHost:host port:NWPushPort identity:identity];
BOOL connected = [connection connectWithError:error];
Expand All @@ -39,7 +39,7 @@ - (BOOL)connectWithPKCS12Data:(NSData *)data password:(NSString *)password envir
if (!identity) {
return NO;
}
return [self connectWithIdentity:identity environment:(NWEnvironment)environment error:error];
return [self connectWithIdentity:identity environment:environment error:error];
}

- (BOOL)reconnectWithError:(NSError *__autoreleasing *)error
Expand Down Expand Up @@ -142,4 +142,26 @@ - (NSArray *)readFailedIdentifierErrorPairsWithMax:(NSUInteger)max error:(NSErro
return pairs;
}

#pragma mark - Deprecated

- (BOOL)connectWithIdentity:(NWIdentityRef)identity error:(NSError *__autoreleasing *)error
{
return [self connectWithIdentity:identity environment:NWEnvironmentAuto error:error];
}

- (BOOL)connectWithPKCS12Data:(NSData *)data password:(NSString *)password error:(NSError *__autoreleasing *)error
{
return [self connectWithPKCS12Data:data password:password environment:NWEnvironmentAuto error:error];
}

+ (instancetype)connectWithIdentity:(NWIdentityRef)identity error:(NSError *__autoreleasing *)error
{
return [self connectWithIdentity:identity environment:NWEnvironmentAuto error:error];
}

+ (instancetype)connectWithPKCS12Data:(NSData *)data password:(NSString *)password error:(NSError *__autoreleasing *)error
{
return [self connectWithPKCS12Data:data password:password environment:NWEnvironmentAuto error:error];
}

@end
8 changes: 7 additions & 1 deletion Classes/NWSecTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
This is practically the glue that connects this framework to the Security framework and allows interacting with the OS Keychain and PKCS #12 files. It is mostly an Objective-C around the Security framework, including the benefits of ARC. `NWIdentityRef`, `NWCertificateRef` and `NWKeyRef` represent respectively `SecIdentityRef`, `SecCertificateRef`, `SecKeyRef`. It uses Cocoa-style error handling, so methods return `nil` or `NO` if an error occurred.
*/

@interface NWSecTools : NSObject

/** @name Initialization */
Expand Down Expand Up @@ -67,4 +66,11 @@
+ (NSDictionary *)valuesWithCertificate:(NWCertificateRef)certificate keys:(NSArray *)keys error:(NSError **)error;
#endif

// deprecated

+ (BOOL)isSandboxIdentity:(NWIdentityRef)identity __deprecated;
+ (BOOL)isSandboxCertificate:(NWCertificateRef)certificate __deprecated;
+ (NWEnvironment)environmentForIdentity:(NWIdentityRef)identity;
+ (NWEnvironment)environmentForCertificate:(NWCertificateRef)certificate;

@end
39 changes: 38 additions & 1 deletion Classes/NWSecTools.m
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ + (BOOL)isPushCertificate:(NWCertificateRef)certificate
case kNWCertTypeWebProduction:
case kNWCertTypeVoIPServices:
return YES;

case kNWCertTypeNone:
case kNWCertTypeUnknown:
break;
Expand Down Expand Up @@ -309,4 +308,42 @@ + (NSDictionary *)valuesWithCertificate:(NWCertificateRef)certificate keys:(NSAr
}
#endif

#pragma mark - Deprecated

+ (BOOL)isSandboxIdentity:(NWIdentityRef)identity
{
return [self environmentForIdentity:identity] == NWEnvironmentSandbox;
}

+ (BOOL)isSandboxCertificate:(NWCertificateRef)certificate
{
return [self environmentForCertificate:certificate] == NWEnvironmentSandbox;
}

+ (NWEnvironment)environmentForIdentity:(NWIdentityRef)identity
{
NWCertificateRef certificate = [self certificateWithIdentity:identity error:nil];
return [self environmentForCertificate:certificate];
}

+ (NWEnvironment)environmentForCertificate:(NWCertificateRef)certificate
{
switch ([self typeWithCertificate:certificate summary:nil]) {
case kNWCertTypeIOSDevelopment:
case kNWCertTypeMacDevelopment:
return NWEnvironmentSandbox;

case kNWCertTypeIOSProduction:
case kNWCertTypeMacProduction:
return NWEnvironmentProduction;
case kNWCertTypeSimplified:
case kNWCertTypeWebProduction:
case kNWCertTypeVoIPServices:
case kNWCertTypeNone:
case kNWCertTypeUnknown:
break;
}
return NWEnvironmentOptionNone;
}

@end
6 changes: 4 additions & 2 deletions Classes/NWType.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,10 @@ typedef NS_ENUM(NSInteger, NWError) {
};

typedef NS_ENUM(NSInteger, NWEnvironment) {
NWEnvironmentSandbox = 0,
NWEnvironmentProduction = 1,
NWEnvironmentNone = 0,
NWEnvironmentSandbox = 1,
NWEnvironmentProduction = 2,
NWEnvironmentAuto = 3,
};

typedef NS_ENUM(NSInteger, NWEnvironmentOptions) {
Expand Down
32 changes: 8 additions & 24 deletions Classes/NWType.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,22 @@
NSString * descriptionForEnvironentOptions(NWEnvironmentOptions environmentOptions)
{
switch (environmentOptions) {
case NWEnvironmentOptionNone:
return @"No environment";

case NWEnvironmentOptionSandbox:
return @"Sandbox";

case NWEnvironmentOptionProduction:
return @"Production";

case NWEnvironmentOptionAny:
return @"Sandbox|Production";

default:
break;
case NWEnvironmentOptionNone: return @"No environment";
case NWEnvironmentOptionSandbox: return @"Sandbox";
case NWEnvironmentOptionProduction: return @"Production";
case NWEnvironmentOptionAny: return @"Sandbox|Production";
}

return nil;
}

NSString * descriptionForEnvironent(NWEnvironment environment)
{
switch (environment) {
case NWEnvironmentProduction:
return @"production";

case NWEnvironmentSandbox:
return @"sandbox";

default:
break;
case NWEnvironmentNone: return @"none";
case NWEnvironmentProduction: return @"production";
case NWEnvironmentSandbox: return @"sandbox";
case NWEnvironmentAuto: return @"auto";
}

return nil;
}

Expand Down

0 comments on commit a8cd4e5

Please sign in to comment.