Skip to content

Commit

Permalink
Merge pull request #1229 from OneSignal/5.0.0/detecting_native_permis…
Browse files Browse the repository at this point in the history
…sion_changes

[5.0.0] Fixes to detecting native permissions
  • Loading branch information
nan-li committed Oct 30, 2023
2 parents bad789e + 2643624 commit 8f67a89
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]];
}
Expand Down
5 changes: 0 additions & 5 deletions iOS_SDK/OneSignalSDK/OneSignalNotifications/OSPermission.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
Expand All @@ -174,7 +179,6 @@ class OSSubscriptionModel: OSModel {
guard self.type == .push && _reachable != oldValue else {
return
}
updateNotificationTypes()
firePushSubscriptionChanged(.reachable(oldValue))
}
}
Expand All @@ -185,7 +189,7 @@ class OSSubscriptionModel: OSModel {
guard self.type == .push && _isDisabled != oldValue else {
return
}
updateNotificationTypes()
notificationTypes = -2
firePushSubscriptionChanged(.isDisabled(oldValue))
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit 8f67a89

Please sign in to comment.