Skip to content

Commit 0164cd5

Browse files
committed
Add can request permission
1 parent 6342801 commit 0164cd5

File tree

9 files changed

+30
-4
lines changed

9 files changed

+30
-4
lines changed

MIGRATION_GUIDE_v3_to_v5.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,10 @@ The session namespace is accessible via `OneSignal.Session` and provides access
154154
**Notifications Namespace**
155155
The notification namespace is accessible via `OneSignal.Notifications` and provides access to notification-scoped functionality.
156156

157-
| **C#** | **Description** |
158-
| -------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
157+
| **C#** | **Description** |
158+
| ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
159159
| `bool Permission` | *Whether this app has push notification permission.* |
160+
| `bool CanRequestPermission` | *Whether this app can request push notification permission.* |
160161
| `NotificationPermission PermissionNative` | *Native permission of the device. The enum NotificationPermission can be NotDetermined, Denied, Authorized, Provisional, or Ephemeral.* |
161162
| `Task<bool> RequestPermissionAsync(bool fallbackToSettings)` | *Prompt the user for permission to push notifications. This will display the native OS prompt to request push notification permission. If the user enables, a push subscription to this device will be automatically added to the user.* |
162163
| `void ClearAllNotifications()` | *Removes all OneSignal notifications.* |

OneSignalExample/Assets/OneSignal/Example/OneSignalExampleBehaviour.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,8 @@ public void RemoveAlias() {
312312
*/
313313

314314
public async void PromptForPush() {
315+
_log($"Can request push notification permission: {OneSignal.Notifications.CanRequestPermission}");
316+
315317
_log("Opening permission prompt for push notifications and awaiting result...");
316318

317319
var result = await OneSignal.Notifications.RequestPermissionAsync(true);

OneSignalExample/Assets/OneSignal/MIGRATION_GUIDE_v3_to_v5.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,10 @@ The session namespace is accessible via `OneSignal.Session` and provides access
154154
**Notifications Namespace**
155155
The notification namespace is accessible via `OneSignal.Notifications` and provides access to notification-scoped functionality.
156156

157-
| **C#** | **Description** |
158-
| -------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
157+
| **C#** | **Description** |
158+
| ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
159159
| `bool Permission` | *Whether this app has push notification permission.* |
160+
| `bool CanRequestPermission` | *Whether this app can request push notification permission.* |
160161
| `NotificationPermission PermissionNative` | *Native permission of the device. The enum NotificationPermission can be NotDetermined, Denied, Authorized, Provisional, or Ephemeral.* |
161162
| `Task<bool> RequestPermissionAsync(bool fallbackToSettings)` | *Prompt the user for permission to push notifications. This will display the native OS prompt to request push notification permission. If the user enables, a push subscription to this device will be automatically added to the user.* |
162163
| `void ClearAllNotifications()` | *Removes all OneSignal notifications.* |

com.onesignal.unity.android/Runtime/AndroidNotificationsManager.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ public bool Permission {
5151
get => _notifications.Call<bool>("getPermission");
5252
}
5353

54+
public bool CanRequestPermission {
55+
get => _notifications.Call<bool>("getCanRequestPermission");
56+
}
57+
5458
public NotificationPermission PermissionNative {
5559
get => _notifications.Call<bool>("getPermission") ? NotificationPermission.Authorized : NotificationPermission.Denied;
5660
}

com.onesignal.unity.core/Editor/Platform/NotificationsManager.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ internal sealed class NotificationsManager : INotificationsManager {
3838

3939
public bool Permission { get; }
4040

41+
public bool CanRequestPermission { get; }
42+
4143
public NotificationPermission PermissionNative { get; }
4244

4345
public Task<bool> RequestPermissionAsync(bool fallbackToSettings){

com.onesignal.unity.core/Runtime/Notifications/INotificationsManager.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ public interface INotificationsManager {
9999
/// </summary>
100100
bool Permission { get; }
101101

102+
/// <summary>
103+
/// Whether this app can request push notification permission.
104+
/// </summary>
105+
bool CanRequestPermission { get; }
106+
102107
/// <summary>
103108
/// Native permission of the device
104109
/// </summary>

com.onesignal.unity.core/Samples~/OneSignalExampleBehaviour.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,8 @@ public void RemoveAlias() {
312312
*/
313313

314314
public async void PromptForPush() {
315+
_log($"Can request push notification permission: {OneSignal.Notifications.CanRequestPermission}");
316+
315317
_log("Opening permission prompt for push notifications and awaiting result...");
316318

317319
var result = await OneSignal.Notifications.RequestPermissionAsync(true);

com.onesignal.unity.ios/Runtime/Plugins/iOS/OneSignalUnityBridgeNotifications.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ bool _notificationsGetPermission() {
121121
return [OneSignal.Notifications permission];
122122
}
123123

124+
bool _notificationsGetCanRequestPermission() {
125+
return [OneSignal.Notifications canRequestPermission];
126+
}
127+
124128
int _notificationsGetPermissionNative() {
125129
return [OneSignal.Notifications permissionNative];
126130
}

com.onesignal.unity.ios/Runtime/iOSNotificationsManager.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
namespace OneSignalSDK.iOS.Notifications {
4040
internal sealed class iOSNotificationsManager : INotificationsManager {
4141
[DllImport("__Internal")] private static extern bool _notificationsGetPermission();
42+
[DllImport("__Internal")] private static extern bool _notificationsGetCanRequestPermission();
4243
[DllImport("__Internal")] private static extern int _notificationsGetPermissionNative();
4344
[DllImport("__Internal")] private static extern void _notificationsRequestPermission(bool fallbackToSettings, int hashCode, BooleanResponseDelegate callback);
4445
[DllImport("__Internal")] private static extern void _notificationsClearAll();
@@ -66,6 +67,10 @@ public bool Permission {
6667
get => _notificationsGetPermission();
6768
}
6869

70+
public bool CanRequestPermission {
71+
get => _notificationsGetCanRequestPermission();
72+
}
73+
6974
public NotificationPermission PermissionNative {
7075
get => (NotificationPermission)_notificationsGetPermissionNative();
7176
}

0 commit comments

Comments
 (0)