Skip to content

Commit 644f1d9

Browse files
committed
Put setting keys into constants and use them
1 parent a99008e commit 644f1d9

File tree

4 files changed

+58
-46
lines changed

4 files changed

+58
-46
lines changed

com.unity.mobile.notifications/Editor/AndroidNotificationPostProcessor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ private void InjectAndroidManifest(string projectPath)
6868

6969
var settings = NotificationSettingsManager.Initialize().AndroidNotificationSettingsFlat;
7070

71-
var useCustomActivity = (bool)settings.Find(i => i.Key == "UnityNotificationAndroidUseCustomActivity").Value;
71+
var useCustomActivity = (bool)settings.Find(i => i.Key == NotificationSettings.AndroidSettings.USE_CUSTOM_ACTIVITY).Value;
7272
if (useCustomActivity)
7373
{
74-
var customActivity = (string)settings.Find(i => i.Key == "UnityNotificationAndroidCustomActivityString").Value;
74+
var customActivity = (string)settings.Find(i => i.Key == NotificationSettings.AndroidSettings.CUSTOM_ACTIVITY_CLASS).Value;
7575
AppendAndroidMetadataField(manifestPath, manifestDoc, "custom_notification_android_activity", customActivity);
7676
}
7777

78-
var enableRescheduleOnRestart = (bool)settings.Find(i => i.Key == "UnityNotificationAndroidRescheduleOnDeviceRestart").Value;
78+
var enableRescheduleOnRestart = (bool)settings.Find(i => i.Key == NotificationSettings.AndroidSettings.RESCHEDULE_ON_RESTART).Value;
7979
if (enableRescheduleOnRestart)
8080
{
8181
AppendAndroidMetadataField(manifestPath, manifestDoc, "reschedule_notifications_on_restart", "true");

com.unity.mobile.notifications/Editor/NotificationSettings.cs

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,22 @@ private static T GetSettingValue<T>(BuildTargetGroup target, string key)
4949
/// </summary>
5050
public static class AndroidSettings
5151
{
52+
internal static readonly string RESCHEDULE_ON_RESTART = "UnityNotificationAndroidRescheduleOnDeviceRestart";
53+
internal static readonly string USE_CUSTOM_ACTIVITY = "UnityNotificationAndroidUseCustomActivity";
54+
internal static readonly string CUSTOM_ACTIVITY_CLASS = "UnityNotificationAndroidCustomActivityString";
55+
5256
/// <summary>
5357
/// By default AndroidSettings removes all scheduled notifications when the device is restarted. Enable this to automatically reschedule all non expired notifications when the device is turned back on.
5458
/// </summary>
5559
public static bool RescheduleOnDeviceRestart
5660
{
5761
get
5862
{
59-
return GetSettingValue<bool>(BuildTargetGroup.Android, "UnityNotificationAndroidRescheduleOnDeviceRestart");
63+
return GetSettingValue<bool>(BuildTargetGroup.Android, RESCHEDULE_ON_RESTART);
6064
}
6165
set
6266
{
63-
SetSettingValue<bool>(BuildTargetGroup.Android, "UnityNotificationAndroidRescheduleOnDeviceRestart", value);
67+
SetSettingValue<bool>(BuildTargetGroup.Android, RESCHEDULE_ON_RESTART, value);
6468
}
6569
}
6670

@@ -71,11 +75,11 @@ public static bool UseCustomActivity
7175
{
7276
get
7377
{
74-
return GetSettingValue<bool>(BuildTargetGroup.Android, "UnityNotificationAndroidUseCustomActivity");
78+
return GetSettingValue<bool>(BuildTargetGroup.Android, USE_CUSTOM_ACTIVITY);
7579
}
7680
set
7781
{
78-
SetSettingValue<bool>(BuildTargetGroup.Android, "UnityNotificationAndroidUseCustomActivity", value);
82+
SetSettingValue<bool>(BuildTargetGroup.Android, USE_CUSTOM_ACTIVITY, value);
7983
}
8084
}
8185

@@ -86,11 +90,11 @@ public static string CustomActivityString
8690
{
8791
get
8892
{
89-
return GetSettingValue<string>(BuildTargetGroup.Android, "UnityNotificationAndroidCustomActivityString");
93+
return GetSettingValue<string>(BuildTargetGroup.Android, CUSTOM_ACTIVITY_CLASS);
9094
}
9195
set
9296
{
93-
SetSettingValue<string>(BuildTargetGroup.Android, "UnityNotificationAndroidCustomActivityString", value);
97+
SetSettingValue<string>(BuildTargetGroup.Android, CUSTOM_ACTIVITY_CLASS, value);
9498
}
9599
}
96100

@@ -155,18 +159,26 @@ public static void ClearDrawableResources()
155159
/// </summary>
156160
public static class iOSSettings
157161
{
162+
internal static readonly string REQUEST_AUTH_ON_LAUNCH = "UnityNotificationRequestAuthorizationOnAppLaunch";
163+
internal static readonly string DEFAULT_AUTH_OPTS = "UnityNotificationDefaultAuthorizationOptions";
164+
internal static readonly string ADD_PUSH_CAPABILITY = "UnityAddRemoteNotificationCapability";
165+
internal static readonly string REQUEST_PUSH_AUTH_ON_LAUNCH = "UnityNotificationRequestAuthorizationForRemoteNotificationsOnAppLaunch";
166+
internal static readonly string PUSH_NOTIFICATION_PRESENTATION = "UnityRemoteNotificationForegroundPresentationOptions";
167+
internal static readonly string USE_APS_RELEASE = "UnityUseAPSReleaseEnvironment";
168+
internal static readonly string USE_LOCATION_TRIGGER = "UnityUseLocationNotificationTrigger";
169+
158170
/// <summary>
159171
/// It's recommended to make the authorization request during the app's launch cycle. If this is enabled the user will be shown the authorization pop-up immediately when the app launches. If it’s unchecked you’ll need to manually create an AuthorizationRequest before your app can send or receive notifications.
160172
/// </summary>
161173
public static bool RequestAuthorizationOnAppLaunch
162174
{
163175
get
164176
{
165-
return GetSettingValue<bool>(BuildTargetGroup.iOS, "UnityNotificationRequestAuthorizationOnAppLaunch");
177+
return GetSettingValue<bool>(BuildTargetGroup.iOS, REQUEST_AUTH_ON_LAUNCH);
166178
}
167179
set
168180
{
169-
SetSettingValue<bool>(BuildTargetGroup.iOS, "UnityNotificationRequestAuthorizationOnAppLaunch", value);
181+
SetSettingValue<bool>(BuildTargetGroup.iOS, REQUEST_AUTH_ON_LAUNCH, value);
170182
}
171183
}
172184

@@ -177,11 +189,11 @@ public static AuthorizationOption DefaultAuthorizationOptions
177189
{
178190
get
179191
{
180-
return GetSettingValue<AuthorizationOption>(BuildTargetGroup.iOS, "UnityNotificationDefaultAuthorizationOptions");
192+
return GetSettingValue<AuthorizationOption>(BuildTargetGroup.iOS, DEFAULT_AUTH_OPTS);
181193
}
182194
set
183195
{
184-
SetSettingValue<AuthorizationOption>(BuildTargetGroup.iOS, "UnityNotificationDefaultAuthorizationOptions", value);
196+
SetSettingValue<AuthorizationOption>(BuildTargetGroup.iOS, DEFAULT_AUTH_OPTS, value);
185197
}
186198
}
187199

@@ -192,11 +204,11 @@ public static bool AddRemoteNotificationCapability
192204
{
193205
get
194206
{
195-
return GetSettingValue<bool>(BuildTargetGroup.iOS, "UnityAddRemoteNotificationCapability");
207+
return GetSettingValue<bool>(BuildTargetGroup.iOS, ADD_PUSH_CAPABILITY);
196208
}
197209
set
198210
{
199-
SetSettingValue<bool>(BuildTargetGroup.iOS, "UnityAddRemoteNotificationCapability", value);
211+
SetSettingValue<bool>(BuildTargetGroup.iOS, ADD_PUSH_CAPABILITY, value);
200212
}
201213
}
202214

@@ -207,11 +219,11 @@ public static bool NotificationRequestAuthorizationForRemoteNotificationsOnAppLa
207219
{
208220
get
209221
{
210-
return GetSettingValue<bool>(BuildTargetGroup.iOS, "UnityNotificationRequestAuthorizationForRemoteNotificationsOnAppLaunch");
222+
return GetSettingValue<bool>(BuildTargetGroup.iOS, REQUEST_PUSH_AUTH_ON_LAUNCH);
211223
}
212224
set
213225
{
214-
SetSettingValue<bool>(BuildTargetGroup.iOS, "UnityNotificationRequestAuthorizationForRemoteNotificationsOnAppLaunch", value);
226+
SetSettingValue<bool>(BuildTargetGroup.iOS, REQUEST_PUSH_AUTH_ON_LAUNCH, value);
215227
}
216228
}
217229

@@ -222,11 +234,11 @@ public static PresentationOption RemoteNotificationForegroundPresentationOptions
222234
{
223235
get
224236
{
225-
return GetSettingValue<PresentationOption>(BuildTargetGroup.iOS, "UnityRemoteNotificationForegroundPresentationOptions");
237+
return GetSettingValue<PresentationOption>(BuildTargetGroup.iOS, PUSH_NOTIFICATION_PRESENTATION);
226238
}
227239
set
228240
{
229-
SetSettingValue<PresentationOption>(BuildTargetGroup.iOS, "UnityRemoteNotificationForegroundPresentationOptions", value);
241+
SetSettingValue<PresentationOption>(BuildTargetGroup.iOS, PUSH_NOTIFICATION_PRESENTATION, value);
230242
}
231243
}
232244

@@ -237,11 +249,11 @@ public static bool UseAPSReleaseEnvironment
237249
{
238250
get
239251
{
240-
return GetSettingValue<bool>(BuildTargetGroup.iOS, "UnityUseAPSReleaseEnvironment");
252+
return GetSettingValue<bool>(BuildTargetGroup.iOS, USE_APS_RELEASE);
241253
}
242254
set
243255
{
244-
SetSettingValue<bool>(BuildTargetGroup.iOS, "UnityUseAPSReleaseEnvironment", value);
256+
SetSettingValue<bool>(BuildTargetGroup.iOS, USE_APS_RELEASE, value);
245257
}
246258
}
247259

@@ -252,11 +264,11 @@ public static bool UseLocationNotificationTrigger
252264
{
253265
get
254266
{
255-
return GetSettingValue<bool>(BuildTargetGroup.iOS, "UnityUseLocationNotificationTrigger");
267+
return GetSettingValue<bool>(BuildTargetGroup.iOS, USE_LOCATION_TRIGGER);
256268
}
257269
set
258270
{
259-
SetSettingValue<bool>(BuildTargetGroup.iOS, "UnityUseLocationNotificationTrigger", value);
271+
SetSettingValue<bool>(BuildTargetGroup.iOS, USE_LOCATION_TRIGGER, value);
260272
}
261273
}
262274
}

com.unity.mobile.notifications/Editor/NotificationSettingsManager.cs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -102,70 +102,70 @@ public static NotificationSettingsManager Initialize()
102102
settingsManager.iOSNotificationSettings = new List<NotificationSetting>()
103103
{
104104
new NotificationSetting(
105-
"UnityNotificationRequestAuthorizationOnAppLaunch",
105+
NotificationSettings.iOSSettings.REQUEST_AUTH_ON_LAUNCH,
106106
"Request Authorization on App Launch",
107107
"It's recommended to make the authorization request during the app's launch cycle. If this is enabled the authorization pop-up will show up immediately during launching. Otherwise you need to manually create an AuthorizationRequest before sending or receiving notifications.",
108-
settingsManager.GetOrAddNotificationSettingValue("UnityNotificationRequestAuthorizationOnAppLaunch", true, false),
108+
settingsManager.GetOrAddNotificationSettingValue(NotificationSettings.iOSSettings.REQUEST_AUTH_ON_LAUNCH, true, false),
109109
dependencies: new List<NotificationSetting>()
110110
{
111111
new NotificationSetting(
112-
"UnityNotificationDefaultAuthorizationOptions",
112+
NotificationSettings.iOSSettings.DEFAULT_AUTH_OPTS,
113113
"Default Notification Authorization Options",
114114
"Configure the notification interaction types which will be included in the authorization request if \"Request Authorization on App Launch\" is enabled.",
115-
settingsManager.GetOrAddNotificationSettingValue("UnityNotificationDefaultAuthorizationOptions",
115+
settingsManager.GetOrAddNotificationSettingValue(NotificationSettings.iOSSettings.DEFAULT_AUTH_OPTS,
116116
AuthorizationOption.Alert | AuthorizationOption.Badge | AuthorizationOption.Sound, false)),
117117
}),
118118
new NotificationSetting(
119-
"UnityAddRemoteNotificationCapability",
119+
NotificationSettings.iOSSettings.ADD_PUSH_CAPABILITY,
120120
"Enable Push Notifications",
121121
"Enable this to add the push notification capability to the Xcode project, also to retrieve the device token from an AuthorizationRequest.",
122-
settingsManager.GetOrAddNotificationSettingValue("UnityAddRemoteNotificationCapability", false, false),
122+
settingsManager.GetOrAddNotificationSettingValue(NotificationSettings.iOSSettings.ADD_PUSH_CAPABILITY, false, false),
123123
false,
124124
new List<NotificationSetting>()
125125
{
126126
new NotificationSetting(
127-
"UnityNotificationRequestAuthorizationForRemoteNotificationsOnAppLaunch",
127+
NotificationSettings.iOSSettings.REQUEST_PUSH_AUTH_ON_LAUNCH,
128128
"Register for Push Notifications on App Launch",
129129
"Enable this to automatically register your app with APNs after launching to receive remote notifications. You need to manually create an AuthorizationRequest to get the device token.",
130-
settingsManager.GetOrAddNotificationSettingValue("UnityNotificationRequestAuthorizationForRemoteNotificationsOnAppLaunch", false, false)),
130+
settingsManager.GetOrAddNotificationSettingValue(NotificationSettings.iOSSettings.REQUEST_PUSH_AUTH_ON_LAUNCH, false, false)),
131131
new NotificationSetting(
132-
"UnityRemoteNotificationForegroundPresentationOptions",
132+
NotificationSettings.iOSSettings.PUSH_NOTIFICATION_PRESENTATION,
133133
"Remote Notification Foreground Presentation Options",
134134
"Configure the default presentation options for received remote notifications. In order to use the specified presentation options, your app must have received the authorization (the user might change it at any time).",
135-
settingsManager.GetOrAddNotificationSettingValue("UnityRemoteNotificationForegroundPresentationOptions", (PresentationOption)iOSPresentationOption.All, false)),
136-
new NotificationSetting("UnityUseAPSReleaseEnvironment",
135+
settingsManager.GetOrAddNotificationSettingValue(NotificationSettings.iOSSettings.PUSH_NOTIFICATION_PRESENTATION, (PresentationOption)iOSPresentationOption.All, false)),
136+
new NotificationSetting(NotificationSettings.iOSSettings.USE_APS_RELEASE,
137137
"Enable Release Environment for APS",
138138
"Enable this when signing the app with a production certificate.",
139-
settingsManager.GetOrAddNotificationSettingValue("UnityUseAPSReleaseEnvironment", false, false),
139+
settingsManager.GetOrAddNotificationSettingValue(NotificationSettings.iOSSettings.USE_APS_RELEASE, false, false),
140140
false),
141141
}),
142-
new NotificationSetting("UnityUseLocationNotificationTrigger",
142+
new NotificationSetting(NotificationSettings.iOSSettings.USE_LOCATION_TRIGGER,
143143
"Include CoreLocation Framework",
144144
"Include the CoreLocation framework to use the iOSNotificationLocationTrigger in your project.",
145-
settingsManager.GetOrAddNotificationSettingValue("UnityUseLocationNotificationTrigger", false, false),
145+
settingsManager.GetOrAddNotificationSettingValue(NotificationSettings.iOSSettings.USE_LOCATION_TRIGGER, false, false),
146146
false)
147147
};
148148

149149
// Create the settings for Android.
150150
settingsManager.AndroidNotificationSettings = new List<NotificationSetting>()
151151
{
152152
new NotificationSetting(
153-
"UnityNotificationAndroidRescheduleOnDeviceRestart",
153+
NotificationSettings.AndroidSettings.RESCHEDULE_ON_RESTART,
154154
"Reschedule on Device Restart",
155155
"Enable this to automatically reschedule all non-expired notifications after device restart. By default AndroidSettings removes all scheduled notifications after restarting.",
156-
settingsManager.GetOrAddNotificationSettingValue("UnityNotificationAndroidRescheduleOnDeviceRestart", false, true)),
156+
settingsManager.GetOrAddNotificationSettingValue(NotificationSettings.AndroidSettings.RESCHEDULE_ON_RESTART, false, true)),
157157
new NotificationSetting(
158-
"UnityNotificationAndroidUseCustomActivity",
158+
NotificationSettings.AndroidSettings.USE_CUSTOM_ACTIVITY,
159159
"Use Custom Activity",
160160
"Enable this to override the activity which will be opened when the user taps the notification.",
161-
settingsManager.GetOrAddNotificationSettingValue("UnityNotificationAndroidUseCustomActivity", false, true),
161+
settingsManager.GetOrAddNotificationSettingValue(NotificationSettings.AndroidSettings.USE_CUSTOM_ACTIVITY, false, true),
162162
dependencies: new List<NotificationSetting>()
163163
{
164164
new NotificationSetting(
165-
"UnityNotificationAndroidCustomActivityString",
165+
NotificationSettings.AndroidSettings.CUSTOM_ACTIVITY_CLASS,
166166
"Custom Activity Name",
167167
"The full class name of the activity which will be assigned to the notification.",
168-
settingsManager.GetOrAddNotificationSettingValue("UnityNotificationAndroidCustomActivityString", "com.unity3d.player.UnityPlayerActivity", true))
168+
settingsManager.GetOrAddNotificationSettingValue(NotificationSettings.AndroidSettings.CUSTOM_ACTIVITY_CLASS, "com.unity3d.player.UnityPlayerActivity", true))
169169
})
170170
};
171171

com.unity.mobile.notifications/Editor/iOSNotificationPostProcessor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
3535

3636
var settings = NotificationSettingsManager.Initialize().iOSNotificationSettingsFlat;
3737

38-
var needLocationFramework = (bool)settings.Find(i => i.Key == "UnityUseLocationNotificationTrigger").Value;
39-
var addPushNotificationCapability = (bool)settings.Find(i => i.Key == "UnityAddRemoteNotificationCapability").Value;
38+
var needLocationFramework = (bool)settings.Find(i => i.Key == NotificationSettings.iOSSettings.USE_LOCATION_TRIGGER).Value;
39+
var addPushNotificationCapability = (bool)settings.Find(i => i.Key == NotificationSettings.iOSSettings.ADD_PUSH_CAPABILITY).Value;
4040

4141
var useReleaseAPSEnv = false;
4242
if (addPushNotificationCapability)
4343
{
44-
var useReleaseAPSEnvSetting = settings.Find(i => i.Key == "UnityUseAPSReleaseEnvironment");
44+
var useReleaseAPSEnvSetting = settings.Find(i => i.Key == NotificationSettings.iOSSettings.USE_APS_RELEASE);
4545
if (useReleaseAPSEnvSetting != null)
4646
useReleaseAPSEnv = (bool)useReleaseAPSEnvSetting.Value;
4747
}

0 commit comments

Comments
 (0)