Skip to content

Commit c5dad91

Browse files
committed
Push Subscription Observer - API update
* Rename OSPushSubscriptionStateChanges to OSPushSubscriptionChangedState * Rename event from onOSPushSubscriptionChanged to onPushSubscriptionDidChange * Use current and previous instead of to and from * No other logic changes, only naming
1 parent 2cc2c36 commit c5dad91

File tree

5 files changed

+26
-26
lines changed

5 files changed

+26
-26
lines changed

iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ - (void)onNotificationPermissionDidChange:(BOOL)permission {
117117
NSLog(@"Dev App onNotificationPermissionDidChange: %d", permission);
118118
}
119119

120-
- (void)onOSPushSubscriptionChangedWithStateChanges:(OSPushSubscriptionStateChanges *)stateChanges {
121-
NSLog(@"Dev App onOSPushSubscriptionChangedWithStateChanges: %@", stateChanges);
120+
- (void)onPushSubscriptionDidChangeWithState:(OSPushSubscriptionChangedState *)state {
121+
NSLog(@"Dev App onPushSubscriptionDidChange: %@", state);
122122
ViewController* mainController = (ViewController*) self.window.rootViewController;
123-
mainController.subscriptionSegmentedControl.selectedSegmentIndex = (NSInteger) stateChanges.to.optedIn;
123+
mainController.subscriptionSegmentedControl.selectedSegmentIndex = (NSInteger) state.current.optedIn;
124124
}
125125

126126
#pragma mark OSInAppMessageDelegate

iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionModel.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import OneSignalNotifications
3333
// MARK: - Push Subscription Specific
3434

3535
@objc public protocol OSPushSubscriptionObserver { // TODO: weak reference?
36-
@objc func onOSPushSubscriptionChanged(stateChanges: OSPushSubscriptionStateChanges)
36+
@objc func onPushSubscriptionDidChange(state: OSPushSubscriptionChangedState)
3737
}
3838

3939
@objc
@@ -68,21 +68,21 @@ public class OSPushSubscriptionState: NSObject {
6868
}
6969

7070
@objc
71-
public class OSPushSubscriptionStateChanges: NSObject {
72-
@objc public let to: OSPushSubscriptionState
73-
@objc public let from: OSPushSubscriptionState
71+
public class OSPushSubscriptionChangedState: NSObject {
72+
@objc public let current: OSPushSubscriptionState
73+
@objc public let previous: OSPushSubscriptionState
7474

7575
@objc public override var description: String {
76-
return "<OSPushSubscriptionStateChanges:\nfrom: \(self.from),\nto: \(self.to)\n>"
76+
return "<OSPushSubscriptionChangedState:\nprevious: \(self.previous),\ncurrent: \(self.current)\n>"
7777
}
7878

79-
init(to: OSPushSubscriptionState, from: OSPushSubscriptionState) {
80-
self.to = to
81-
self.from = from
79+
init(current: OSPushSubscriptionState, previous: OSPushSubscriptionState) {
80+
self.current = current
81+
self.previous = previous
8282
}
8383

8484
@objc public func jsonRepresentation() -> NSDictionary {
85-
return ["from": from.jsonRepresentation(), "to": to.jsonRepresentation()]
85+
return ["from": previous.jsonRepresentation(), "to": current.jsonRepresentation()]
8686
}
8787
}
8888

@@ -368,7 +368,7 @@ extension OSSubscriptionModel {
368368
return
369369
}
370370

371-
let stateChanges = OSPushSubscriptionStateChanges(to: newSubscriptionState, from: prevSubscriptionState)
371+
let stateChanges = OSPushSubscriptionChangedState(current: newSubscriptionState, previous: prevSubscriptionState)
372372

373373
// TODO: Don't fire observer until server is udated
374374
OneSignalLog.onesignalLog(.LL_VERBOSE, message: "firePushSubscriptionChanged from \(prevSubscriptionState.jsonRepresentation()) to \(newSubscriptionState.jsonRepresentation())")

iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,12 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager {
133133
@objc public var requiresUserAuth = false
134134

135135
// Push Subscription
136-
private var _pushSubscriptionStateChangesObserver: OSObservable<OSPushSubscriptionObserver, OSPushSubscriptionStateChanges>?
137-
var pushSubscriptionStateChangesObserver: OSObservable<OSPushSubscriptionObserver, OSPushSubscriptionStateChanges> {
136+
private var _pushSubscriptionStateChangesObserver: OSObservable<OSPushSubscriptionObserver, OSPushSubscriptionChangedState>?
137+
var pushSubscriptionStateChangesObserver: OSObservable<OSPushSubscriptionObserver, OSPushSubscriptionChangedState> {
138138
if let observer = _pushSubscriptionStateChangesObserver {
139139
return observer
140140
}
141-
let pushSubscriptionStateChangesObserver = OSObservable<OSPushSubscriptionObserver, OSPushSubscriptionStateChanges>(change: #selector(OSPushSubscriptionObserver.onOSPushSubscriptionChanged(stateChanges:)))
141+
let pushSubscriptionStateChangesObserver = OSObservable<OSPushSubscriptionObserver, OSPushSubscriptionChangedState>(change: #selector(OSPushSubscriptionObserver.onPushSubscriptionDidChange(state:)))
142142
_pushSubscriptionStateChangesObserver = pushSubscriptionStateChangesObserver
143143

144144
return pushSubscriptionStateChangesObserver

iOS_SDK/OneSignalSDK/Source/OSMessagingController.m

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,22 +1008,22 @@ - (void)onApplicationDidBecomeActive {
10081008
}
10091009

10101010
#pragma mark OSPushSubscriptionObserver Methods
1011-
- (void)onOSPushSubscriptionChangedWithStateChanges:(OSPushSubscriptionStateChanges * _Nonnull)stateChanges {
1011+
- (void)onPushSubscriptionDidChangeWithState:(OSPushSubscriptionChangedState * _Nonnull)state {
10121012
// Don't pull IAMs if the new subscription ID is nil
1013-
if (stateChanges.to.id == nil) {
1014-
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"OSMessagingController onOSPushSubscriptionChangedWithStateChanges: changed to nil subscription id"];
1013+
if (state.current.id == nil) {
1014+
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"OSMessagingController onPushSubscriptionDidChange: changed to nil subscription id"];
10151015
return;
10161016
}
10171017
// Don't pull IAMs if the subscription ID has not changed
1018-
if (stateChanges.from.id != nil &&
1019-
[stateChanges.to.id isEqualToString:stateChanges.from.id]) {
1020-
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"OSMessagingController onOSPushSubscriptionChangedWithStateChanges: changed to the same subscription id"];
1018+
if (state.previous.id != nil &&
1019+
[state.current.id isEqualToString:state.previous.id]) {
1020+
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"OSMessagingController onPushSubscriptionDidChange: changed to the same subscription id"];
10211021
return;
10221022
}
10231023

10241024
// Pull new IAMs when the subscription id changes to a new valid subscription id
1025-
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"OSMessagingController onOSPushSubscriptionChangedWithStateChanges: changed to new valid subscription id"];
1026-
[self getInAppMessagesFromServer:stateChanges.to.id];
1025+
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"OSMessagingController onPushSubscriptionDidChange: changed to new valid subscription id"];
1026+
[self getInAppMessagesFromServer:state.current.id];
10271027
}
10281028

10291029
- (void)dealloc {

iOS_SDK/OneSignalSDK/Source/OneSignalLiveActivityController.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ + (void)initialize {
8686
[OneSignalUserManagerImpl.sharedInstance addObserver:shared];
8787
}
8888

89-
- (void)onOSPushSubscriptionChangedWithStateChanges:(OSPushSubscriptionStateChanges * _Nonnull)stateChanges {
90-
if(stateChanges.to.id){
89+
- (void)onPushSubscriptionDidChangeWithState:(OSPushSubscriptionChangedState * _Nonnull)state {
90+
if(state.current.id){
9191
subscriptionId = OneSignalUserManagerImpl.sharedInstance.pushSubscriptionId;
9292
[OneSignalLiveActivityController executePendingLiveActivityUpdates];
9393
}

0 commit comments

Comments
 (0)