diff --git a/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.h b/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.h index ec9fd549f..2ff01e99a 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.h +++ b/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.h @@ -57,7 +57,6 @@ typedef void (^OSNotificationOpenedBlock)(OSNotificationOpenedResult * _Nonnull // can check responds to selector - (void)setNotificationTypes:(int)notificationTypes; - (void)setPushToken:(NSString * _Nonnull)pushToken; -- (void)setReachable:(BOOL)inReachable; @end diff --git a/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.m b/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.m index 00d55dab2..e1b5ca0c4 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.m +++ b/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.m @@ -455,9 +455,6 @@ + (void)updateNotificationTypes:(int)notificationTypes { + (void)sendNotificationTypesUpdateToDelegate { // We don't delay observer update to wait until the OneSignal server is notified // TODO: We can do the above and delay observers until server is updated. - if (self.delegate && [self.delegate respondsToSelector:@selector(setReachable:)]) { - [self.delegate setReachable:[self getNotificationTypes] > 0]; - } if (self.delegate && [self.delegate respondsToSelector:@selector(setNotificationTypes:)]) { [self.delegate setNotificationTypes:[self getNotificationTypes]]; } diff --git a/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSPermission.m b/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSPermission.m index 0ae54bf99..2572a91d1 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSPermission.m +++ b/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSPermission.m @@ -208,11 +208,6 @@ + (void)fireChangesObserver:(OSPermissionStateInternal*)state { OSNotificationsManager.lastPermissionState = [state copy]; [OSNotificationsManager.lastPermissionState persistAsFrom]; } - // Update the push subscription's _accepted property - // TODO: This can be called before the User Manager has set itself as the delegate - if (OSNotificationsManager.delegate && [OSNotificationsManager.delegate respondsToSelector:@selector(setReachable:)]) { - [OSNotificationsManager.delegate setReachable:state.reachable]; - } } @end diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionModel.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionModel.swift index 345d98e85..7ffe13759 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionModel.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionModel.swift @@ -61,6 +61,10 @@ public class OSPushSubscriptionState: NSObject { "optedIn": optedIn ] } + + func equals(_ state: OSPushSubscriptionState) -> Bool { + return self.id == state.id && self.token == state.token && self.optedIn == state.optedIn + } } @objc @@ -156,9 +160,10 @@ class OSSubscriptionModel: OSModel { // If _isDisabled is set, this supersedes as the value to send to server. if _isDisabled && notificationTypes != -2 { + notificationTypes = -2 return } - + _reachable = notificationTypes > 0 self.set(property: "notificationTypes", newValue: notificationTypes) } } @@ -174,7 +179,6 @@ class OSSubscriptionModel: OSModel { guard self.type == .push && _reachable != oldValue else { return } - updateNotificationTypes() firePushSubscriptionChanged(.reachable(oldValue)) } } @@ -185,7 +189,7 @@ class OSSubscriptionModel: OSModel { guard self.type == .push && _isDisabled != oldValue else { return } - updateNotificationTypes() + notificationTypes = -2 firePushSubscriptionChanged(.isDisabled(oldValue)) } } @@ -321,6 +325,7 @@ extension OSSubscriptionModel { case address(String?) } + // TODO: Fix when isDisabled is set to true, the push subscription observer is not fired due to known bug. func firePushSubscriptionChanged(_ changedProperty: OSPushPropertyChanged) { var prevIsOptedIn = true var prevIsEnabled = true @@ -358,6 +363,11 @@ extension OSSubscriptionModel { let newSubscriptionState = OSPushSubscriptionState(id: subscriptionId, token: address, optedIn: newIsOptedIn) + // TODO: Make this method less hacky, this is a final check before firing push observer + guard !prevSubscriptionState.equals(newSubscriptionState) else { + return + } + let stateChanges = OSPushSubscriptionStateChanges(to: newSubscriptionState, from: prevSubscriptionState) // TODO: Don't fire observer until server is udated diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift index d2c9104ff..3d1626c60 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift @@ -739,11 +739,4 @@ extension OneSignalUserManagerImpl: OneSignalNotificationsDelegate { } user.pushSubscriptionModel.address = pushToken } - - public func setReachable(_ inReachable: Bool) { - guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: nil) else { - return - } - user.pushSubscriptionModel._reachable = inReachable - } }