Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.0.0] Fixes to detecting native permissions #1229

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}