diff --git a/Source/ARTLocalDevice.m b/Source/ARTLocalDevice.m index 4083ff4d6..873b751c3 100644 --- a/Source/ARTLocalDevice.m +++ b/Source/ARTLocalDevice.m @@ -153,4 +153,9 @@ - (BOOL)isRegistered { return _identityTokenDetails != nil; } +- (void)clearIdentityTokenDetailsAndClientId { + [self setAndPersistIdentityTokenDetails:nil]; + self.clientId = nil; +} + @end diff --git a/Source/ARTPushActivationState.m b/Source/ARTPushActivationState.m index 3810e627c..b8d28649e 100644 --- a/Source/ARTPushActivationState.m +++ b/Source/ARTPushActivationState.m @@ -275,7 +275,7 @@ - (ARTPushActivationState *)transition:(ARTPushActivationEvent *)event { else if ([event isKindOfClass:[ARTPushActivationEventDeregistered class]]) { #if TARGET_OS_IOS ARTLocalDevice *local = self.machine.rest.device_nosync; - [local setAndPersistIdentityTokenDetails:nil]; + [local clearIdentityTokenDetailsAndClientId]; #endif [self.machine callDeactivatedCallback:nil]; return [ARTPushActivationStateNotActivated newWithMachine:self.machine logger:self.logger]; diff --git a/Source/PrivateHeaders/Ably/ARTLocalDevice+Private.h b/Source/PrivateHeaders/Ably/ARTLocalDevice+Private.h index d94bdea8d..5c9518b41 100644 --- a/Source/PrivateHeaders/Ably/ARTLocalDevice+Private.h +++ b/Source/PrivateHeaders/Ably/ARTLocalDevice+Private.h @@ -25,6 +25,7 @@ NSString* ARTAPNSDeviceTokenKeyOfType(NSString * _Nullable tokenType); - (void)setAndPersistAPNSDeviceToken:(nullable NSString *)deviceToken; - (void)setAndPersistIdentityTokenDetails:(nullable ARTDeviceIdentityTokenDetails *)tokenDetails; - (BOOL)isRegistered; +- (void)clearIdentityTokenDetailsAndClientId; + (NSString *)generateId; + (NSString *)generateSecret; diff --git a/Test/Tests/PushActivationStateMachineTests.swift b/Test/Tests/PushActivationStateMachineTests.swift index 105cf240b..66799d4c7 100644 --- a/Test/Tests/PushActivationStateMachineTests.swift +++ b/Test/Tests/PushActivationStateMachineTests.swift @@ -822,8 +822,16 @@ class PushActivationStateMachineTests: XCTestCase { // RSH3g2 func test__054__Activation_state_machine__State_WaitingForDeregistration__on_Event_Deregistered() { - beforeEach__Activation_state_machine__State_WaitingForDeregistration() - + storage = MockDeviceStorage(startWith: ARTPushActivationStateWaitingForDeregistration(machine: initialStateMachine, logger: .init(core: MockInternalLogCore()))) + + let options = ARTClientOptions(key: "xxxx:xxxx") + options.clientId = "client1" + let rest = ARTRest(options: options) + rest.internal.storage = storage + stateMachine = ARTPushActivationStateMachine(rest: rest.internal, delegate: StateMachineDelegate(), logger: .init(core: MockInternalLogCore())) + + XCTAssertEqual(stateMachine.rest.device.clientId, "client1") + var deactivatedCallbackCalled = false let hook = stateMachine.testSuite_injectIntoMethod(after: NSSelectorFromString("callDeactivatedCallback:")) { deactivatedCallbackCalled = true @@ -841,6 +849,7 @@ class PushActivationStateMachineTests: XCTestCase { XCTAssertTrue(deactivatedCallbackCalled) XCTAssertTrue(setAndPersistIdentityTokenDetailsCalled) // RSH3g2a + XCTAssertNil(stateMachine.rest.device.clientId) XCTAssertNil(stateMachine.rest.device.identityTokenDetails) }