Skip to content

Commit 454856a

Browse files
authored
Merge pull request #1229 from OneSignal/5.0.0/detecting_native_permission_changes
[5.0.0] Fixes to detecting native permissions
2 parents 700ee7d + d9b816f commit 454856a

File tree

5 files changed

+13
-19
lines changed

5 files changed

+13
-19
lines changed

iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ typedef void (^OSNotificationOpenedBlock)(OSNotificationOpenedResult * _Nonnull
5757
// can check responds to selector
5858
- (void)setNotificationTypes:(int)notificationTypes;
5959
- (void)setPushToken:(NSString * _Nonnull)pushToken;
60-
- (void)setReachable:(BOOL)inReachable;
6160

6261
@end
6362

iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.m

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,6 @@ + (void)updateNotificationTypes:(int)notificationTypes {
455455
+ (void)sendNotificationTypesUpdateToDelegate {
456456
// We don't delay observer update to wait until the OneSignal server is notified
457457
// TODO: We can do the above and delay observers until server is updated.
458-
if (self.delegate && [self.delegate respondsToSelector:@selector(setReachable:)]) {
459-
[self.delegate setReachable:[self getNotificationTypes] > 0];
460-
}
461458
if (self.delegate && [self.delegate respondsToSelector:@selector(setNotificationTypes:)]) {
462459
[self.delegate setNotificationTypes:[self getNotificationTypes]];
463460
}

iOS_SDK/OneSignalSDK/OneSignalNotifications/OSPermission.m

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,6 @@ + (void)fireChangesObserver:(OSPermissionStateInternal*)state {
208208
OSNotificationsManager.lastPermissionState = [state copy];
209209
[OSNotificationsManager.lastPermissionState persistAsFrom];
210210
}
211-
// Update the push subscription's _accepted property
212-
// TODO: This can be called before the User Manager has set itself as the delegate
213-
if (OSNotificationsManager.delegate && [OSNotificationsManager.delegate respondsToSelector:@selector(setReachable:)]) {
214-
[OSNotificationsManager.delegate setReachable:state.reachable];
215-
}
216211
}
217212

218213
@end

iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionModel.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ public class OSPushSubscriptionState: NSObject {
6161
"optedIn": optedIn
6262
]
6363
}
64+
65+
func equals(_ state: OSPushSubscriptionState) -> Bool {
66+
return self.id == state.id && self.token == state.token && self.optedIn == state.optedIn
67+
}
6468
}
6569

6670
@objc
@@ -156,9 +160,10 @@ class OSSubscriptionModel: OSModel {
156160

157161
// If _isDisabled is set, this supersedes as the value to send to server.
158162
if _isDisabled && notificationTypes != -2 {
163+
notificationTypes = -2
159164
return
160165
}
161-
166+
_reachable = notificationTypes > 0
162167
self.set(property: "notificationTypes", newValue: notificationTypes)
163168
}
164169
}
@@ -174,7 +179,6 @@ class OSSubscriptionModel: OSModel {
174179
guard self.type == .push && _reachable != oldValue else {
175180
return
176181
}
177-
updateNotificationTypes()
178182
firePushSubscriptionChanged(.reachable(oldValue))
179183
}
180184
}
@@ -185,7 +189,7 @@ class OSSubscriptionModel: OSModel {
185189
guard self.type == .push && _isDisabled != oldValue else {
186190
return
187191
}
188-
updateNotificationTypes()
192+
notificationTypes = -2
189193
firePushSubscriptionChanged(.isDisabled(oldValue))
190194
}
191195
}
@@ -321,6 +325,7 @@ extension OSSubscriptionModel {
321325
case address(String?)
322326
}
323327

328+
// TODO: Fix when isDisabled is set to true, the push subscription observer is not fired due to known bug.
324329
func firePushSubscriptionChanged(_ changedProperty: OSPushPropertyChanged) {
325330
var prevIsOptedIn = true
326331
var prevIsEnabled = true
@@ -358,6 +363,11 @@ extension OSSubscriptionModel {
358363

359364
let newSubscriptionState = OSPushSubscriptionState(id: subscriptionId, token: address, optedIn: newIsOptedIn)
360365

366+
// TODO: Make this method less hacky, this is a final check before firing push observer
367+
guard !prevSubscriptionState.equals(newSubscriptionState) else {
368+
return
369+
}
370+
361371
let stateChanges = OSPushSubscriptionStateChanges(to: newSubscriptionState, from: prevSubscriptionState)
362372

363373
// TODO: Don't fire observer until server is udated

iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -739,11 +739,4 @@ extension OneSignalUserManagerImpl: OneSignalNotificationsDelegate {
739739
}
740740
user.pushSubscriptionModel.address = pushToken
741741
}
742-
743-
public func setReachable(_ inReachable: Bool) {
744-
guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: nil) else {
745-
return
746-
}
747-
user.pushSubscriptionModel._reachable = inReachable
748-
}
749742
}

0 commit comments

Comments
 (0)