Skip to content

Commit 09c2e68

Browse files
authored
chore: [SDK-4218] add Live Activities support to Unity demo (#863)
1 parent dbd77db commit 09c2e68

44 files changed

Lines changed: 633 additions & 100 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public Task<bool> EnterAsync(string activityId, string token)
4040
return Task.FromResult(false);
4141
}
4242

43+
[System.Obsolete("Currently unsupported, avoid using this method.")]
4344
public Task<bool> ExitAsync(string activityId)
4445
{
4546
SDKDebug.Warn("This feature is only available for iOS.");

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public Task<bool> EnterAsync(string activityId, string token)
3737
return Task.FromResult(false);
3838
}
3939

40+
[System.Obsolete("Currently unsupported, avoid using this method.")]
4041
public Task<bool> ExitAsync(string activityId)
4142
{
4243
return Task.FromResult(false);

com.onesignal.unity.core/Runtime/LiveActivities/ILiveActivitiesManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public interface ILiveActivitiesManager
4545
/// </summary>
4646
/// <remarks>iOS Only</remarks>
4747
/// <returns>Awaitable boolean of whether the operation succeeded or failed</returns>
48+
[System.Obsolete("Currently unsupported, avoid using this method.")]
4849
Task<bool> ExitAsync(string activityId);
4950

5051
/// <summary>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public async Task<bool> EnterAsync(string activityId, string token)
7575
return await proxy;
7676
}
7777

78+
[System.Obsolete("Currently unsupported, avoid using this method.")]
7879
public async Task<bool> ExitAsync(string activityId)
7980
{
8081
var (proxy, hashCode) = WaitingProxy._setupProxy<bool>();

examples/demo/.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ONESIGNAL_API_KEY=your_rest_api_key

examples/demo/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ crashlytics-build.properties
6464
# User-specific Unity Editor settings
6565
/[Uu]serSettings/
6666

67+
# Environment files
68+
.env
69+
Assets/StreamingAssets/.env
70+
Assets/StreamingAssets/.env.meta
71+
6772
# Gradle template backup files
6873
*.backup
6974
*.backup.meta

examples/demo/Assets/App/Editor/iOS/BuildPostProcessor.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,19 @@
3838
namespace App.Editor.iOS
3939
{
4040
/// <summary>
41-
/// Adds the ExampleWidgetExtension to the iOS project frameworks to the iOS project and enables the main target
41+
/// Adds the OneSignalWidgetExtension to the iOS project and enables the main target
4242
/// for Live Activities.
4343
/// </summary>
4444
public class BuildPostProcessor : IPostprocessBuildWithReport
4545
{
46-
private static readonly string WdigetExtensionTargetRelativePath = "ExampleWidget";
47-
private static readonly string WidgetExtensionTargetName = "ExampleWidgetExtension";
48-
private static readonly string WidgetExtensionPath = Path.Combine("iOS", "ExampleWidget");
46+
private static readonly string WidgetExtensionTargetRelativePath = "OneSignalWidget";
47+
private static readonly string WidgetExtensionTargetName = "OneSignalWidgetExtension";
48+
private static readonly string WidgetExtensionPath = Path.Combine("iOS", "OneSignalWidget");
4949
private static readonly string[] WidgetExtensionFiles = new string[]
5050
{
5151
"Assets.xcassets",
52-
"ExampleWidgetBundle.swift",
53-
"ExampleWidgetLiveActivity.swift",
52+
"OneSignalWidgetBundle.swift",
53+
"OneSignalWidgetLiveActivity.swift",
5454
};
5555

5656
/// <summary>
@@ -114,7 +114,7 @@ static void AddWidgetExtensionToProject(string outputPath)
114114
if (!string.IsNullOrEmpty(extensionGuid))
115115
return;
116116

117-
var widgetDestPath = Path.Combine(outputPath, WdigetExtensionTargetRelativePath);
117+
var widgetDestPath = Path.Combine(outputPath, WidgetExtensionTargetRelativePath);
118118

119119
Directory.CreateDirectory(widgetDestPath);
120120
CopyFileOrDirectory(
@@ -126,14 +126,14 @@ static void AddWidgetExtensionToProject(string outputPath)
126126
project.GetUnityMainTargetGuid(),
127127
WidgetExtensionTargetName,
128128
$"{PlayerSettings.GetApplicationIdentifier(BuildTargetGroup.iOS)}.{WidgetExtensionTargetName}",
129-
$"{WdigetExtensionTargetRelativePath}/Info.plist"
129+
$"{WidgetExtensionTargetRelativePath}/Info.plist"
130130
);
131131

132132
var buildPhaseID = project.AddSourcesBuildPhase(extensionGuid);
133133

134134
foreach (var file in WidgetExtensionFiles)
135135
{
136-
var destPathRelative = Path.Combine(WdigetExtensionTargetRelativePath, file);
136+
var destPathRelative = Path.Combine(WidgetExtensionTargetRelativePath, file);
137137
var sourceFileGuid = project.AddFile(destPathRelative, destPathRelative);
138138
project.AddFileToBuildSection(extensionGuid, buildPhaseID, sourceFileGuid);
139139
CopyFileOrDirectory(

examples/demo/Assets/Resources/Theme.uss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,14 @@ Scroller {
765765
max-height: 0;
766766
}
767767

768+
.inline-input-field > .unity-text-field__input {
769+
background-color: transparent;
770+
border-width: 0;
771+
-unity-text-align: upper-right;
772+
color: var(--os-text-primary);
773+
font-size: 14px;
774+
}
775+
768776
.unity-base-slider {
769777
display: none;
770778
}

examples/demo/Assets/Scripts/AppBootstrapper.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using OneSignalSDK;
55
using OneSignalSDK.Debug.Models;
66
using OneSignalSDK.InAppMessages;
7+
using OneSignalSDK.LiveActivities;
78
using OneSignalSDK.Notifications;
89
using UnityEngine;
910

@@ -40,12 +41,23 @@ private async void Start()
4041
}
4142

4243
_apiService.SetAppId(appId);
44+
_apiService.LoadApiKey();
4345

4446
OneSignal.Debug.LogLevel = LogLevel.Verbose;
4547
OneSignal.ConsentRequired = _prefs.ConsentRequired;
4648
OneSignal.ConsentGiven = _prefs.PrivacyConsent;
4749
OneSignal.Initialize(appId);
4850

51+
#if UNITY_IOS
52+
OneSignal.LiveActivities.SetupDefault(
53+
new LiveActivitySetupOptions
54+
{
55+
EnablePushToStart = true,
56+
EnablePushToUpdate = true,
57+
}
58+
);
59+
#endif
60+
4961
OneSignal.InAppMessages.Paused = _prefs.IamPaused;
5062
OneSignal.Location.IsShared = _prefs.LocationShared;
5163

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System.IO;
2+
using UnityEditor;
3+
using UnityEditor.Build;
4+
using UnityEditor.Build.Reporting;
5+
using UnityEngine;
6+
7+
namespace OneSignalDemo.Editor
8+
{
9+
public class CopyEnvPreBuild : IPreprocessBuildWithReport
10+
{
11+
public int callbackOrder => 0;
12+
13+
public void OnPreprocessBuild(BuildReport report)
14+
{
15+
var projectRoot = Path.GetDirectoryName(Application.dataPath);
16+
var source = Path.Combine(projectRoot, ".env");
17+
var dest = Path.Combine(Application.streamingAssetsPath, ".env");
18+
19+
if (!File.Exists(source))
20+
{
21+
Debug.LogWarning(
22+
"[OneSignalDemo] No .env file found at project root. "
23+
+ "Live Activity API calls will be disabled. "
24+
+ "Copy .env.example to .env and add your key."
25+
);
26+
if (File.Exists(dest))
27+
{
28+
File.Delete(dest);
29+
var metaPath = dest + ".meta";
30+
if (File.Exists(metaPath))
31+
File.Delete(metaPath);
32+
}
33+
return;
34+
}
35+
36+
Directory.CreateDirectory(Application.streamingAssetsPath);
37+
File.Copy(source, dest, overwrite: true);
38+
Debug.Log("[OneSignalDemo] Copied .env to StreamingAssets");
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)