Skip to content

Commit ed1132d

Browse files
committed
Adding ephemeral permission state
1 parent b9b83db commit ed1132d

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

iOS_SDK/OneSignalSDK/Source/OSPermission.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ typedef OSObservable<NSObject<OSPermissionStateObserver>*, OSPermissionState*> O
5050
@property (readwrite, nonatomic) BOOL answeredPrompt;
5151
@property (readwrite, nonatomic) BOOL accepted;
5252
@property (readwrite, nonatomic) BOOL provisional; //internal flag
53+
@property (readwrite, nonatomic) BOOL ephemeral;
5354
@property (readwrite, nonatomic) BOOL reachable;
5455
@property int notificationTypes;
5556

iOS_SDK/OneSignalSDK/Source/OSPermission.m

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ - (instancetype)initAsFrom {
4949
_hasPrompted = [standardUserDefaults getSavedBoolForKey:OSUD_WAS_PROMPTED_FOR_NOTIFICATIONS_FROM defaultValue:false];
5050
_answeredPrompt = [standardUserDefaults getSavedBoolForKey:OSUD_WAS_NOTIFICATION_PROMPT_ANSWERED_FROM defaultValue:false];
5151
_accepted = [standardUserDefaults getSavedBoolForKey:OSUD_PERMISSION_ACCEPTED_FROM defaultValue:false];
52+
_ephemeral = [standardUserDefaults getSavedBoolForKey:OSUD_PERMISSION_EPHEMERAL_FROM defaultValue:false];
5253
_provisional = [standardUserDefaults getSavedBoolForKey:OSUD_PROVISIONAL_PUSH_AUTHORIZATION_FROM defaultValue:false];
5354
_providesAppNotificationSettings = [standardUserDefaults getSavedBoolForKey:OSUD_APP_PROVIDES_NOTIFICATION_SETTINGS defaultValue:false];
5455

@@ -60,6 +61,7 @@ - (void)persistAsFrom {
6061
[standardUserDefaults saveBoolForKey:OSUD_WAS_PROMPTED_FOR_NOTIFICATIONS_FROM withValue:_hasPrompted];
6162
[standardUserDefaults saveBoolForKey:OSUD_WAS_NOTIFICATION_PROMPT_ANSWERED_FROM withValue:_answeredPrompt];
6263
[standardUserDefaults saveBoolForKey:OSUD_PERMISSION_ACCEPTED_FROM withValue:_accepted];
64+
[standardUserDefaults saveBoolForKey:OSUD_PERMISSION_EPHEMERAL_FROM withValue:_ephemeral];
6365
[standardUserDefaults saveBoolForKey:OSUD_PROVISIONAL_PUSH_AUTHORIZATION_FROM withValue:_provisional];
6466
[standardUserDefaults saveBoolForKey:OSUD_APP_PROVIDES_NOTIFICATION_SETTINGS withValue:_providesAppNotificationSettings];
6567
}
@@ -72,6 +74,7 @@ - (instancetype)copyWithZone:(NSZone*)zone {
7274
copy->_hasPrompted = _hasPrompted;
7375
copy->_answeredPrompt = _answeredPrompt;
7476
copy->_accepted = _accepted;
77+
copy->_ephemeral = _ephemeral;
7578
copy->_provisional = _provisional;
7679
copy->_providesAppNotificationSettings = _providesAppNotificationSettings;
7780
}
@@ -94,7 +97,7 @@ - (BOOL)hasPrompted {
9497
}
9598

9699
- (BOOL)reachable {
97-
return self.provisional || self.accepted;
100+
return self.provisional || self.accepted || self.ephemeral;
98101
}
99102

100103
- (void)setProvisional:(BOOL)provisional {
@@ -130,6 +133,13 @@ - (void)setAccepted:(BOOL)accepted {
130133
[self.observable notifyChange:self];
131134
}
132135

136+
- (void)setEphemeral:(BOOL)ephemeral {
137+
BOOL changed = _ephemeral != ephemeral;
138+
_ephemeral = ephemeral;
139+
if (changed)
140+
[self.observable notifyChange:self];
141+
}
142+
133143
- (void)setProvidesAppNotificationSettings:(BOOL)providesAppNotificationSettings {
134144
_providesAppNotificationSettings = providesAppNotificationSettings;
135145
}
@@ -141,6 +151,9 @@ - (OSNotificationPermission)status {
141151
if (self.answeredPrompt)
142152
return OSNotificationPermissionDenied;
143153

154+
if (self.ephemeral)
155+
return OSNotificationPermissionEphemeral;
156+
144157
if (self.provisional)
145158
return OSNotificationPermissionProvisional;
146159

@@ -157,12 +170,15 @@ - (NSString*)statusAsString {
157170
return @"Denied";
158171
case OSNotificationPermissionProvisional:
159172
return @"Provisional";
173+
case OSNotificationPermissionEphemeral:
174+
return @"Ephemeral";
160175
}
161176
return @"NotDetermined";
162177
}
163178

164179
- (BOOL)compare:(OSPermissionState*)from {
165180
return self.accepted != from.accepted ||
181+
self.ephemeral != from.ephemeral ||
166182
self.answeredPrompt != from.answeredPrompt ||
167183
self.hasPrompted != from.hasPrompted;
168184
}

iOS_SDK/OneSignalSDK/Source/OneSignal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ typedef NS_ENUM(NSInteger, OSNotificationPermission) {
253253

254254
// the application is only authorized to post Provisional notifications (direct to history)
255255
OSNotificationPermissionProvisional
256+
257+
// the application is authorized to send notifications for 8 hours. Only used by App Clips.
258+
OSNotificationPermissionEphemeral
256259
};
257260

258261
// Permission Classes

iOS_SDK/OneSignalSDK/Source/OneSignalCommonDefines.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
#define OSUD_PROVISIONAL_PUSH_AUTHORIZATION_TO @"OSUD_PROVISIONAL_PUSH_AUTHORIZATION_TO" // OSUD_PROVISIONAL_PUSH_AUTHORIZATION_TO
6060
#define OSUD_PROVISIONAL_PUSH_AUTHORIZATION_FROM @"ONESIGNAL_PROVISIONAL_AUTHORIZATION_LAST" // * OSUD_PROVISIONAL_PUSH_AUTHORIZATION_FROM
6161
#define OSUD_USES_PROVISIONAL_PUSH_AUTHORIZATION @"ONESIGNAL_USES_PROVISIONAL_PUSH_AUTHORIZATION" // * OSUD_USES_PROVISIONAL_PUSH_AUTHORIZATION
62+
#define OSUD_PERMISSION_EPHEMERAL_TO @"OSUD_PERMISSION_EPHEMERAL_TO" // * OSUD_PERMISSION_EPHEMERAL_TO
63+
#define OSUD_PERMISSION_EPHEMERAL_FROM @"OSUD_PERMISSION_EPHEMERAL_FROM" // * OSUD_PERMISSION_EPHEMERAL_FROM
6264
// Player
6365
#define OSUD_EXTERNAL_USER_ID @"OS_EXTERNAL_USER_ID" // * OSUD_EXTERNAL_USER_ID
6466
#define OSUD_PLAYER_ID_TO @"GT_PLAYER_ID" // * OSUD_PLAYER_ID_TO

0 commit comments

Comments
 (0)