Skip to content

Commit

Permalink
Push ActivationStateMachine tests (#662)
Browse files Browse the repository at this point in the history
* Initial Push types

* Update project

* ARTPushNotifications interface

* Realtime: integrate Push type

* Rest: integrate Push type

* Push.activate

* fixup! Push.activate

* Push.publish

 - add PushRecipient protocol

* fixup! Push.publish

* PushChannel subscribe and unsubscribe

* Fix registerCallback

* Remove warnings

 - unused methods

* Fix FormFactor

* Fix: use device token as Hex string

* Fix: should respect the default encoder

 - useBinaryProtocol

* Remove ARTPushRecipient protocol and types

* Add ULID pod

* Use ULID as DeviceId

* Push.deactivate

* Load local device

* Push: update device

* PushChannel.subscriptions

* Update ULID pod

* PushAdmin

* Update ULID pod

* Remove warnings

* JSON encoder: normalize deviceToken hex string

* Fix: Push.publish request body

* Update device forms

* Activation State Machine: init

* Activation State Machine: registration

* Removed ablyPushAuthKey, ablyPushAuthToken and ablyPushClientId from push delegate

* Add Rest argument on Push delegate

* tmp

* Fix things for push, and adapt to latest API.

* Initial State Machine tests

* ARTLocalDeviceStorage

* Fix: ARTPushActivationState

* Storage should synchronize UserDefaults

* Storage Keys accessible on tests

* State Machine tests

* ActivationStateMachine: custom delegate and other fixes

* PushActivationStateMachine

* Implement Device storage

* Fix headers

* Fix tests
  • Loading branch information
ricardopereira authored and funkyboy committed Jul 17, 2018
1 parent 7f2216e commit 2237a79
Show file tree
Hide file tree
Showing 33 changed files with 988 additions and 125 deletions.
18 changes: 17 additions & 1 deletion Ably.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
D71D30041C5F7B2F002115B0 /* RealtimeClientChannels.swift in Sources */ = {isa = PBXBuildFile; fileRef = D71D30031C5F7B2F002115B0 /* RealtimeClientChannels.swift */; };
D72304701BB72CED00F1ABDA /* RealtimeClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = D723046F1BB72CED00F1ABDA /* RealtimeClient.swift */; };
D72768211C9C19040022F8B2 /* RestClientPresence.swift in Sources */ = {isa = PBXBuildFile; fileRef = D72768201C9C19040022F8B2 /* RestClientPresence.swift */; };
D72C67DF201AB74000978EBB /* ARTPushActivationStateMachine+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = D72C67DE201AB74000978EBB /* ARTPushActivationStateMachine+Private.h */; settings = {ATTRIBUTES = (Private, ); }; };
D73691FF1DB788C40062C150 /* ARTAuthDetails.h in Headers */ = {isa = PBXBuildFile; fileRef = D73691FD1DB788C40062C150 /* ARTAuthDetails.h */; settings = {ATTRIBUTES = (Public, ); }; };
D73692001DB788C40062C150 /* ARTAuthDetails.m in Sources */ = {isa = PBXBuildFile; fileRef = D73691FE1DB788C40062C150 /* ARTAuthDetails.m */; };
D736A0C91F916553005ABE81 /* KSCrash.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D736A0C61F916553005ABE81 /* KSCrash.framework */; };
Expand Down Expand Up @@ -159,6 +160,9 @@
D7DC8AF11C6AA0C8005AF165 /* ARTDefault+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = D7DC8AF01C6A9FFC005AF165 /* ARTDefault+Private.h */; settings = {ATTRIBUTES = (Private, ); }; };
D7DEAFD11E65926D00D23F24 /* ARTLocalDevice.h in Headers */ = {isa = PBXBuildFile; fileRef = D7DEAFCF1E65926D00D23F24 /* ARTLocalDevice.h */; settings = {ATTRIBUTES = (Public, ); }; };
D7DEAFD21E65926D00D23F24 /* ARTLocalDevice.m in Sources */ = {isa = PBXBuildFile; fileRef = D7DEAFD01E65926D00D23F24 /* ARTLocalDevice.m */; };
D7DF73851EA600240013CD36 /* PushActivationStateMachine.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7DF73831EA5FE620013CD36 /* PushActivationStateMachine.swift */; };
D7DF738A1EA645300013CD36 /* ARTLocalDeviceStorage.h in Headers */ = {isa = PBXBuildFile; fileRef = D7DF73881EA645300013CD36 /* ARTLocalDeviceStorage.h */; settings = {ATTRIBUTES = (Public, ); }; };
D7DF738B1EA645300013CD36 /* ARTLocalDeviceStorage.m in Sources */ = {isa = PBXBuildFile; fileRef = D7DF73891EA645300013CD36 /* ARTLocalDeviceStorage.m */; };
D7EBE5A31BE8391E0086E675 /* RealtimeClientConnection.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7EBE5A21BE8391E0086E675 /* RealtimeClientConnection.swift */; };
D7EBE5A41BE9F6900086E675 /* ARTConnection.h in Headers */ = {isa = PBXBuildFile; fileRef = D7D29B401BE3DD0600374295 /* ARTConnection.h */; settings = {ATTRIBUTES = (Public, ); }; };
D7F1D3731BF4DE07001A4B5E /* ARTRestPresence.h in Headers */ = {isa = PBXBuildFile; fileRef = D7F1D3711BF4DE07001A4B5E /* ARTRestPresence.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand Down Expand Up @@ -337,6 +341,7 @@
D71D30031C5F7B2F002115B0 /* RealtimeClientChannels.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RealtimeClientChannels.swift; sourceTree = "<group>"; };
D723046F1BB72CED00F1ABDA /* RealtimeClient.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RealtimeClient.swift; sourceTree = "<group>"; };
D72768201C9C19040022F8B2 /* RestClientPresence.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RestClientPresence.swift; sourceTree = "<group>"; };
D72C67DE201AB74000978EBB /* ARTPushActivationStateMachine+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ARTPushActivationStateMachine+Private.h"; sourceTree = "<group>"; };
D73691FD1DB788C40062C150 /* ARTAuthDetails.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ARTAuthDetails.h; sourceTree = "<group>"; };
D73691FE1DB788C40062C150 /* ARTAuthDetails.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ARTAuthDetails.m; sourceTree = "<group>"; };
D736A0C61F916553005ABE81 /* KSCrash.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = KSCrash.framework; path = Carthage/Build/iOS/KSCrash.framework; sourceTree = "<group>"; };
Expand Down Expand Up @@ -417,6 +422,9 @@
D7DC8AF01C6A9FFC005AF165 /* ARTDefault+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ARTDefault+Private.h"; sourceTree = "<group>"; };
D7DEAFCF1E65926D00D23F24 /* ARTLocalDevice.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ARTLocalDevice.h; sourceTree = "<group>"; };
D7DEAFD01E65926D00D23F24 /* ARTLocalDevice.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ARTLocalDevice.m; sourceTree = "<group>"; };
D7DF73831EA5FE620013CD36 /* PushActivationStateMachine.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PushActivationStateMachine.swift; sourceTree = "<group>"; };
D7DF73881EA645300013CD36 /* ARTLocalDeviceStorage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ARTLocalDeviceStorage.h; sourceTree = "<group>"; };
D7DF73891EA645300013CD36 /* ARTLocalDeviceStorage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ARTLocalDeviceStorage.m; sourceTree = "<group>"; };
D7EBE5A21BE8391E0086E675 /* RealtimeClientConnection.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RealtimeClientConnection.swift; sourceTree = "<group>"; };
D7EE14F51F07964500C178D5 /* Version.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Version.xcconfig; sourceTree = "<group>"; };
D7F1D3711BF4DE07001A4B5E /* ARTRestPresence.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ARTRestPresence.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -559,6 +567,7 @@
EB1AE0CD1C5C3A4900D62250 /* Utilities.swift */,
EB7913A71C6E54C3000ABF9B /* Crypto.swift */,
D74A17B61FA0D81A006D27B5 /* PushAdmin.swift */,
D7DF73831EA5FE620013CD36 /* PushActivationStateMachine.swift */,
);
path = Spec;
sourceTree = "<group>";
Expand Down Expand Up @@ -657,6 +666,7 @@
isa = PBXGroup;
children = (
D71966E21E5DF360000974DD /* ARTPushActivationStateMachine.h */,
D72C67DE201AB74000978EBB /* ARTPushActivationStateMachine+Private.h */,
D71966E31E5DF360000974DD /* ARTPushActivationStateMachine.m */,
D71966E81E5E006E000974DD /* ARTPushActivationState.h */,
D71966E91E5E006E000974DD /* ARTPushActivationState.m */,
Expand Down Expand Up @@ -854,9 +864,11 @@
D7B621931E4A6FE600684474 /* ARTDeviceDetails.m */,
D768C6AA1E4B5B0200436011 /* ARTDevicePushDetails.h */,
D768C6AB1E4B5B0200436011 /* ARTDevicePushDetails.m */,
EBFFAC181E97919C003E7326 /* ARTLocalDevice+Private.h */,
D7DEAFCF1E65926D00D23F24 /* ARTLocalDevice.h */,
EBFFAC181E97919C003E7326 /* ARTLocalDevice+Private.h */,
D7DEAFD01E65926D00D23F24 /* ARTLocalDevice.m */,
D7DF73881EA645300013CD36 /* ARTLocalDeviceStorage.h */,
D7DF73891EA645300013CD36 /* ARTLocalDeviceStorage.m */,
D71966E71E5DFFC6000974DD /* Activation State Machine */,
D71966E61E5DFFB2000974DD /* Admin */,
);
Expand Down Expand Up @@ -888,6 +900,7 @@
EB91213E1CA0AD6600BA0A40 /* ARTMsgPackEncoder.h in Headers */,
96A507BD1A3791490077CDF8 /* ARTRealtime.h in Headers */,
EB5E058D1C77027600A48B39 /* ARTCrypto+Private.h in Headers */,
D72C67DF201AB74000978EBB /* ARTPushActivationStateMachine+Private.h in Headers */,
D7DC8AF11C6AA0C8005AF165 /* ARTDefault+Private.h in Headers */,
961343D81A42E0B7006DC822 /* ARTClientOptions.h in Headers */,
D7534C321D79E5C20054C182 /* Ably.h in Headers */,
Expand Down Expand Up @@ -982,6 +995,7 @@
D7D8F8251BC2C691009718F2 /* ARTTokenDetails.h in Headers */,
D7D8F82B1BC2C706009718F2 /* ARTTokenRequest.h in Headers */,
EB1AE0CC1C5C1EB200D62250 /* ARTEventEmitter+Private.h in Headers */,
D7DF738A1EA645300013CD36 /* ARTLocalDeviceStorage.h in Headers */,
960D07931A45F1D800ED8C8C /* ARTCrypto.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -1155,6 +1169,7 @@
856AAC991B6E312F00B07119 /* RestClient.swift in Sources */,
D746AE2C1BBB625E003ECEF8 /* RestClientChannel.swift in Sources */,
D71D30041C5F7B2F002115B0 /* RealtimeClientChannels.swift in Sources */,
D7DF73851EA600240013CD36 /* PushActivationStateMachine.swift in Sources */,
D714A63E1C74D4B2002F2CA0 /* NSObject+TestSuite.swift in Sources */,
856AAC971B6E30C800B07119 /* TestUtilities.swift in Sources */,
D72768211C9C19040022F8B2 /* RestClientPresence.swift in Sources */,
Expand Down Expand Up @@ -1224,6 +1239,7 @@
EB9121401CA0AD8200BA0A40 /* ARTMsgPackEncoder.m in Sources */,
96BF61651A35CDE1004CF2B3 /* ARTBaseMessage.m in Sources */,
D7F1D3781BF4DE72001A4B5E /* ARTRealtimePresence.m in Sources */,
D7DF738B1EA645300013CD36 /* ARTLocalDeviceStorage.m in Sources */,
D7B621911E4A6E0200684474 /* ARTPush.m in Sources */,
D7AE18D31E5B410F00478D82 /* ARTPushChannelSubscriptions.m in Sources */,
1CD8DCA01B1C7315007EAF36 /* ARTDefault.m in Sources */,
Expand Down
3 changes: 2 additions & 1 deletion Source/ARTAuth+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ NS_ASSUME_NONNULL_BEGIN
// Private TimeOffset setter for testing only
- (void)setTimeOffset:(NSTimeInterval)offset;

- (NSString *_Nullable)getClientId;
- (NSString *_Nullable)clientId;

- (NSString *_Nullable)appId;

Expand All @@ -89,6 +89,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface ARTEvent (AuthorizationState)
- (instancetype)initWithAuthorizationState:(ARTAuthorizationState)value;
+ (instancetype)newWithAuthorizationState:(ARTAuthorizationState)value;

@end

NS_ASSUME_NONNULL_END
4 changes: 2 additions & 2 deletions Source/ARTAuth.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ NS_ASSUME_NONNULL_BEGIN

@interface ARTAuth : NSObject

- (instancetype)init NS_UNAVAILABLE;
@property (nullable, readonly) NSString *clientId;

@property (nullable, readonly, getter=getClientId) NSString *clientId;
- (instancetype)init NS_UNAVAILABLE;

/**
# (RSA8) Auth#requestToken
Expand Down
2 changes: 1 addition & 1 deletion Source/ARTAuth.m
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ - (void)setProtocolClientId:(NSString *)clientId {
} ART_TRY_OR_REPORT_CRASH_END
}

- (NSString *)getClientId {
- (NSString *)clientId {
__block NSString *clientId;
dispatch_sync(_queue, ^{
ART_TRY_OR_REPORT_CRASH_START(_rest) {
Expand Down
2 changes: 1 addition & 1 deletion Source/ARTDeviceDetails.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

#import <Foundation/Foundation.h>
#import "ARTPush.h"
#import <Ably/ARTPush.h>

@class ARTDevicePushDetails;

Expand Down
5 changes: 0 additions & 5 deletions Source/ARTLocalDevice+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
// Copyright © 2017 Ably. All rights reserved.
//

#ifndef ARTLocalDevice_Private_h
#define ARTLocalDevice_Private_h

#import <Ably/ARTRest.h>

NS_ASSUME_NONNULL_BEGIN
Expand All @@ -29,5 +26,3 @@ extern NSString *const ARTDeviceTokenKey;
@end

NS_ASSUME_NONNULL_END

#endif /* ARTLocalDevice_Private_h */
2 changes: 1 addition & 1 deletion Source/ARTLocalDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

#import <Foundation/Foundation.h>
#import "ARTDeviceDetails.h"
#import <Ably/ARTDeviceDetails.h>

NS_ASSUME_NONNULL_BEGIN

Expand Down
21 changes: 9 additions & 12 deletions Source/ARTLocalDevice.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#import "ARTRest+Private.h"
#import "ARTAuth+Private.h"
#import "ARTEncoder.h"
#import "ARTLocalDeviceStorage.h"
#import <ULID/ULID.h>

NSString *const ARTDevicePlatform = @"ios";
Expand Down Expand Up @@ -59,26 +60,24 @@ + (ARTLocalDevice *)load:(ARTRest *_Nonnull)rest {
}
device.push.recipient[@"transportType"] = ARTDevicePushTransportType;

NSString *deviceId = [[NSUserDefaults standardUserDefaults] stringForKey:ARTDeviceIdKey];
NSString *deviceId = [rest.storage objectForKey:ARTDeviceIdKey];
if (!deviceId) {
deviceId = [[ULID new] ulidString];
[[NSUserDefaults standardUserDefaults] setObject:deviceId forKey:ARTDeviceIdKey];
[[NSUserDefaults standardUserDefaults] synchronize];
[rest.storage setObject:deviceId forKey:ARTDeviceIdKey];
}
device.id = deviceId;
device.updateToken = [[NSUserDefaults standardUserDefaults] stringForKey:ARTDeviceUpdateTokenKey];
device.updateToken = [rest.storage objectForKey:ARTDeviceUpdateTokenKey];

[device setDeviceToken:[[NSUserDefaults standardUserDefaults] stringForKey:ARTDeviceTokenKey]];
[device setDeviceToken:[rest.storage objectForKey:ARTDeviceTokenKey]];

return device;
}

- (void)resetId {
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:ARTDeviceIdKey];
[self.rest.storage setObject:nil forKey:ARTDeviceIdKey];
[self setAndPersistUpdateToken:nil];
NSString *deviceId = [[ULID new] ulidString];
[[NSUserDefaults standardUserDefaults] setObject:deviceId forKey:ARTDeviceIdKey];
[[NSUserDefaults standardUserDefaults] synchronize];
[self.rest.storage setObject:deviceId forKey:ARTDeviceIdKey];
self.id = deviceId;
}

Expand Down Expand Up @@ -118,14 +117,12 @@ - (void)setDeviceToken:(NSString *_Nonnull)token {
}

- (void)setAndPersistDeviceToken:(NSString *)token {
[[NSUserDefaults standardUserDefaults] setObject:token forKey:ARTDeviceTokenKey];
[[NSUserDefaults standardUserDefaults] synchronize];
[self.rest.storage setObject:token forKey:ARTDeviceTokenKey];
[self setDeviceToken:token];
}

- (void)setAndPersistUpdateToken:(NSString *)token {
[[NSUserDefaults standardUserDefaults] setObject:token forKey:ARTDeviceUpdateTokenKey];
[[NSUserDefaults standardUserDefaults] synchronize];
[self.rest.storage setObject:token forKey:ARTDeviceUpdateTokenKey];
self.updateToken = token;
}

Expand Down
22 changes: 22 additions & 0 deletions Source/ARTLocalDeviceStorage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// ARTLocalDeviceStorage.h
// Ably
//
// Created by Ricardo Pereira on 18/04/2017.
// Copyright © 2017 Ably. All rights reserved.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@protocol ARTDeviceStorage <NSObject>
- (nullable id)objectForKey:(NSString *)key;
- (void)setObject:(nullable id)value forKey:(NSString *)key;
@end

@interface ARTLocalDeviceStorage : NSObject<ARTDeviceStorage>

@end

NS_ASSUME_NONNULL_END
22 changes: 22 additions & 0 deletions Source/ARTLocalDeviceStorage.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// ARTLocalDeviceStorage.m
// Ably
//
// Created by Ricardo Pereira on 18/04/2017.
// Copyright © 2017 Ably. All rights reserved.
//

#import "ARTLocalDeviceStorage.h"

@implementation ARTLocalDeviceStorage

- (nullable id)objectForKey:(NSString *)key {
return [[NSUserDefaults standardUserDefaults] objectForKey:key];
}

- (void)setObject:(nullable id)value forKey:(NSString *)key {
[[NSUserDefaults standardUserDefaults] setObject:value forKey:key];
[[NSUserDefaults standardUserDefaults] synchronize];
}

@end
5 changes: 0 additions & 5 deletions Source/ARTPush+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
// Copyright © 2017 Ably. All rights reserved.
//

#ifndef ARTPush_Private_h
#define ARTPush_Private_h

#import <Ably/ARTPush.h>

NS_ASSUME_NONNULL_BEGIN
Expand All @@ -20,5 +17,3 @@ NS_ASSUME_NONNULL_BEGIN
@end

NS_ASSUME_NONNULL_END

#endif /* ARTPush_Private_h */
4 changes: 2 additions & 2 deletions Source/ARTPush.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
//

#import <Foundation/Foundation.h>
#import "ARTTypes.h"
#import "ARTPushAdmin.h"
#import <Ably/ARTTypes.h>
#import <Ably/ARTPushAdmin.h>

@class ARTRest;
@class ARTRealtime;
Expand Down
3 changes: 2 additions & 1 deletion Source/ARTPush.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#import "ARTClientOptions+Private.h"
#import "ARTPushAdmin+Private.h"
#import "ARTLocalDevice+Private.h"
#import "ARTLocalDeviceStorage.h"
#import "ARTRealtime+Private.h"

NSString *const ARTDeviceIdKey = @"ARTDeviceId";
Expand Down Expand Up @@ -59,7 +60,7 @@ + (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceTokenDa
NSString *deviceToken = [[[deviceTokenData description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]] stringByReplacingOccurrencesOfString:@" " withString:@""];

NSLog(@"ARTPush: device token received %@", deviceToken);
NSString *currentDeviceToken = [[NSUserDefaults standardUserDefaults] stringForKey:ARTDeviceTokenKey];
NSString *currentDeviceToken = [rest.storage objectForKey:ARTDeviceTokenKey];
if ([currentDeviceToken isEqualToString:deviceToken]) {
// Already stored.
return;
Expand Down
4 changes: 4 additions & 0 deletions Source/ARTPushActivationEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@
#import <Foundation/Foundation.h>

@class ARTErrorInfo;
@class ARTPushActivationState;

NS_ASSUME_NONNULL_BEGIN

@interface ARTPushActivationEvent : NSObject <NSCoding>

- (NSData *)archive;
+ (nullable ARTPushActivationState *)unarchive:(NSData *)data;

@end

/// Event with Error info
Expand Down
10 changes: 10 additions & 0 deletions Source/ARTPushActivationEvent.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ - (void)encodeWithCoder:(NSCoder *)aCoder {
// Just to persist the class info, no properties
}

#pragma mark - Archive/Unarchive

- (NSData *)archive {
return [NSKeyedArchiver archivedDataWithRootObject:self];
}

+ (ARTPushActivationEvent *)unarchive:(NSData *)data {
return [NSKeyedUnarchiver unarchiveObjectWithData:data];
}

@end

#pragma mark - Event with Error info
Expand Down
4 changes: 4 additions & 0 deletions Source/ARTPushActivationState.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithMachine:(ARTPushActivationStateMachine *)machine;
+ (instancetype)new NS_UNAVAILABLE;
+ (instancetype)newWithMachine:(ARTPushActivationStateMachine *)machine;

@property (atomic, strong, nullable) ARTPushActivationStateMachine *machine;

- (nullable ARTPushActivationState *)transition:(ARTPushActivationEvent *)event;

- (NSData *)archive;
+ (nullable ARTPushActivationState *)unarchive:(NSData *)data;

@end

/// Persistent State
Expand Down
Loading

0 comments on commit 2237a79

Please sign in to comment.