Skip to content
Open
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
119 changes: 119 additions & 0 deletions .github/scripts/validate-unity-distribution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#!/usr/bin/env python3

import json
import re
import sys
from pathlib import Path


ROOT = Path(__file__).resolve().parents[2]
DEMO = ROOT / "examples/demo"
BOOTSTRAP = ROOT / "examples/demo/Assets/OneSignal"
SAMPLE = ROOT / "com.onesignal.unity.core/Samples~"
INVENTORY = BOOTSTRAP / "Editor/Resources/OneSignalFileInventory.asset"

EXCLUDED_PREFIXES = (
"Assets/OneSignal/Attribution",
"Assets/OneSignal/Example",
)
EXCLUDED_FILES = {
"Assets/OneSignal/Editor/OneSignalAndroidDependencies.xml",
"Assets/OneSignal/Editor/OneSignalAndroidDependencies.xml.meta",
"Assets/OneSignal/Editor/OneSignaliOSDependencies.xml",
"Assets/OneSignal/Editor/OneSignaliOSDependencies.xml.meta",
}
REQUIRED_SAMPLE_GUIDS = {
"OneSignal.UnityPackage.Example.asmdef.meta": "a28dab59edddfb3448f1fd9318f85c32",
"OneSignalExampleBehaviour.cs.meta": "1a40a711031e4cb8b9b3f674dda19d55",
"OneSignalExampleScene.unity.meta": "54284d014d2241544a24b57b13c09ac8",
"INCONSOLATA-VARIABLEFONT_WDTH,WGHT.TTF.meta": "792110c4f5f19e64196eb25f41c0b783",
}


def fail(message: str) -> None:
print(f"Unity distribution validation failed: {message}", file=sys.stderr)
raise SystemExit(1)


def is_distributed(path: str) -> bool:
if path in EXCLUDED_FILES or path.endswith("/.DS_Store"):
return False
return not any(
path == prefix
or path == f"{prefix}.meta"
or path.startswith(f"{prefix}/")
for prefix in EXCLUDED_PREFIXES
)


def validate_inventory() -> None:
actual = sorted(
path.relative_to(DEMO).as_posix()
for path in BOOTSTRAP.rglob("*")
if path.is_file() and is_distributed(path.relative_to(DEMO).as_posix())
)
recorded = re.findall(r"^\s*-\s+(Assets/OneSignal/.+)$", INVENTORY.read_text(), re.MULTILINE)

if actual != recorded:
missing = sorted(set(actual) - set(recorded))
stale = sorted(set(recorded) - set(actual))
fail(
"file inventory is out of date"
+ (f"; missing: {', '.join(missing)}" if missing else "")
+ (f"; stale: {', '.join(stale)}" if stale else "")
)


def validate_sample() -> None:
for filename, expected_guid in REQUIRED_SAMPLE_GUIDS.items():
path = SAMPLE / filename
if not path.is_file():
fail(f"sample is missing {path.relative_to(ROOT)}")
match = re.search(r"^guid:\s*(\w+)$", path.read_text(), re.MULTILINE)
if match is None or match.group(1) != expected_guid:
fail(f"{path.relative_to(ROOT)} does not preserve GUID {expected_guid}")

scene = (SAMPLE / "OneSignalExampleScene.unity").read_text()
if "OneSignalSDK.OneSignalExampleBehaviour" in scene:
fail("sample scene contains stale OneSignalExampleBehaviour type references")
if "OneSignalExampleBehaviour, OneSignal.UnityPackage.Example" not in scene:
fail("sample scene does not contain OneSignalExampleBehaviour button bindings")
behaviour = (SAMPLE / "OneSignalExampleBehaviour.cs").read_text()
if "ExitLiveActivityAsync" in scene or "LiveActivities.ExitAsync" in behaviour:
fail("sample exposes the deprecated Live Activities exit API")

asmdef = json.loads((SAMPLE / "OneSignal.UnityPackage.Example.asmdef").read_text())
required_references = {
"OneSignal.Core",
"UnityEngine.UI",
"UnityEngine.JSONSerializeModule",
}
if not required_references.issubset(asmdef["references"]):
fail("sample assembly is missing required references")

package = json.loads((ROOT / "com.onesignal.unity.core/package.json").read_text())
if not any(sample.get("path") == "Samples~" for sample in package.get("samples", [])):
fail("core package does not register Samples~")
if not any(
version.get("name") == "com.onesignal.unity.core"
and version.get("expression") == package["version"]
and version.get("define") == "ONE_SIGNAL_INSTALLED"
for version in asmdef.get("versionDefines", [])
):
fail("sample version define does not match the core package version")


def main() -> None:
if (BOOTSTRAP / "Example").exists() or (BOOTSTRAP / "Example.meta").exists():
fail("empty legacy Asset Store Example path still exists")
if (BOOTSTRAP / "Documentation~").exists():
fail("Documentation~ is hidden from Unity and cannot be exported")
if not (BOOTSTRAP / "Documentation").is_dir():
fail("exportable bootstrap documentation is missing")
validate_inventory()
validate_sample()
print("Unity distribution layout is valid.")


if __name__ == "__main__":
main()
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ jobs:

- name: Check formatting
run: csharpier check .

- name: Validate Unity distribution layout
run: python3 .github/scripts/validate-unity-distribution.py
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ Before creating bug reports, please check this list of steps to follow.
* **Include Reproducibility** It is nearly always a good idea to include steps to reproduct the issue. If you cannot reliably reproduce the issue yourself, that's ok, but reproducible steps help best.
* **Describe your environment**, tell us what version of the Unity OneSignal SDK you are using, what platforms the issue occurs on (android/iOS), related code samples, and so on.
* **Include a Stack Trace** If your issue involves a crash/exception, ***PLEASE*** post the stack trace to help us identify the root issue.
* **Include an Example Project** This isn't required, but if you want your issue fixed quickly, it's often a good idea to include an example project as a zip and include it with the issue. You can also download the Demo project (included in the `/OneSignalExample` folder of this repo) and set up an example project with this code as a starting point.
* **Include an Example Project** This isn't required, but if you want your issue fixed quickly, it's often a good idea to include an example project as a zip and include it with the issue. You can also use the Demo project in [`examples/demo`](examples/demo) as a starting point.
2 changes: 1 addition & 1 deletion MIGRATION_GUIDE_v3_to_v5.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ The debug namespace is accessible via `OneSignal.Debug` and provides access to d
# Troubleshooting
## Android
```
Assets/OneSignal/Example/OneSignalExampleBehaviou.cs: error CS0246: The type or namespace name '...' could not be found (are you missing a using directive or an assembly reference?)
Assets/Samples/OneSignal Unity SDK - Core/<version>/Full Usage/OneSignalExampleBehaviour.cs: error CS0246: The type or namespace name '...' could not be found (are you missing a using directive or an assembly reference?)
```

```
Expand Down
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ There are two methods of installation available for the OneSignal Unity SDK:
2. Find the package waiting for you to download by clicking **Open in Unity** from that same page. This will open the Unity Editor and its Package Manager window.
3. On the SDK's listing in the Editor click the **Download** button. When it finishes click **Import**.

![onesignal unity sdk in my assets](Documentation/asset_listing.png)
![onesignal unity sdk in my assets](examples/demo/Assets/OneSignal/Documentation/asset_listing.png)

4. A prompt to import all of the files of the OneSignal Unity SDK will appear. Click **Import** to continue and compile the scripts into your project.
5. Navigate to **Window > OneSignal SDK Setup** (or follow the popup if upgrading) in the Unity Editor which will bring up a window with some final steps which need
to be completed in order to finalize the installation. The most important of these steps is **Import OneSignal packages**.

> *Depending on your project configuration and if you are upgrading from a previous version, some of these steps may already be marked as "completed"*

![sdk setup steps window](Documentation/setup_window.png)
![sdk setup steps window](examples/demo/Assets/OneSignal/Documentation/setup_window.png)

6. After importing the packages Unity will notify you that a new registry has been added and the **OneSignal SDK Setup** window will have refreshed with a few additional
steps. Following these will finalize your installation of the OneSignal Unity SDK.
Expand All @@ -95,7 +95,7 @@ There are two methods of installation available for the OneSignal Unity SDK:

1. From within the Unity Editor navigate to **Edit > Project Settings** and then to the **Package Manager** settings tab.

![unity registry manager](Documentation/package_manager_tab.png)
![unity registry manager](examples/demo/Assets/OneSignal/Documentation/package_manager_tab.png)

2. Create a *New Scoped Registry* by entering
```
Expand All @@ -111,7 +111,7 @@ There are two methods of installation available for the OneSignal Unity SDK:

> *Depending on your project configuration and if you are upgrading from a previous version, some of these steps may already be marked as "completed"*

![my registries menu selection](Documentation/registry_menu.png)
![my registries menu selection](examples/demo/Assets/OneSignal/Documentation/registry_menu.png)

</details>

Expand All @@ -122,16 +122,16 @@ After building in Unity and exporting the XCode project follow these steps:
2. Click on the **Unity-iPhone** project and its similarly named target and select the **Signing & Capabilities** tab.
3. From here check **Automatically manage signing**, on the prompt click **Enable Automatic**, and select your **Team**.

![automatically manage signing](Documentation/ios_auto_sign.png)
![automatically manage signing](examples/demo/Assets/OneSignal/Documentation/ios_auto_sign.png)

4. Scroll down to **App Groups** and click on the refresh button.
> NOTE: You may have to press this a few times as it will ask you for each signing type.

![refresh app groups](Documentation/ios_refresh_app_groups.png)
![refresh app groups](examples/demo/Assets/OneSignal/Documentation/ios_refresh_app_groups.png)

5. Repeat the same steps above but for the **OneSignalNotificationServiceExtension** target this time.

![extension signing and groups](Documentation/ios_extension_sign_and_groups.png)
![extension signing and groups](examples/demo/Assets/OneSignal/Documentation/ios_extension_sign_and_groups.png)

6. **App Groups** should now be provisioned for you going forward for your iOS bundle id, even on clean builds.

Expand Down Expand Up @@ -168,8 +168,7 @@ With the location module disabled, Android resolves OneSignal's native modules w
When toggling the flag, clear stale native outputs (the generated Xcode project, CocoaPods/Gradle caches, and prior `Build/` artifacts) so a previously linked location module isn't reused.

## Usage
You can find a complete implementation in our included [example MonoBehaviour](OneSignalExample/Assets/OneSignal/Example/OneSignalExampleBehaviour.cs). Additionally we have included a
[sample scene](OneSignalExample/Assets/OneSignal/Example/OneSignalExampleScene.unity) which you can run to test out the SDK.
For a compact implementation of the major SDK features, open **Window > Package Manager**, select **OneSignal Unity SDK - Core**, and import the **Full Usage** sample. The sample requires Unity UI (`com.unity.ugui`). The repository's complete development demo is available in [`examples/demo`](examples/demo).

### Initialization
#### Prefab
Expand Down
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "OneSignal.UnityPackage.Example",
"rootNamespace": "",
"references": [
"OneSignal.Core",
"UnityEngine.UI",
"UnityEngine.JSONSerializeModule"
],
"includePlatforms": [
"Android",
"Editor",
"iOS"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [
{
"name": "com.onesignal.unity.core",
"expression": "5.3.0",
"define": "ONE_SIGNAL_INSTALLED"
}
],
"noEngineReferences": false
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions com.onesignal.unity.core/Samples~/OneSignalExampleBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -537,18 +537,6 @@ public async void EnterLiveActivityAsync()
_log("Live Activity enter failed");
}

public async void ExitLiveActivityAsync()
{
_log($"Exiting Live Activity with id: <b>{liveActivityId}</b> and awaiting result...");

var result = await OneSignal.LiveActivities.ExitAsync(liveActivityId);

if (result)
_log("Live Activity exit success");
else
_log("Live Activity exit failed");
}

public void SetPushToStartToken()
{
_log(
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading