Skip to content

Added TikTok App Events sample. #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
Added TikTok App Events sample.
Adds a sample for utilizing TikTok App Events.
  • Loading branch information
PaulMDemers committed Apr 11, 2025
commit 19c220502b11b4475f9e74eae9967f68d2ac667d
6 changes: 6 additions & 0 deletions tiktok/NuGet.Config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="maui-nativelibraryinterop" value="https://pkgs.dev.azure.com/xamarin/public/_packaging/maui-nativelibraryinterop/nuget/v3/index.json" />
</packageSources>
</configuration>
45 changes: 45 additions & 0 deletions tiktok/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# TikTok App Events Slim Binding
This folder contains a slim binding which demonstrations using [TikTok App Events][0]

## Setup
The TikTok Business sdk must be added to the root of the sample folder. The SDK is distributed via [Jitpack][3], [download the aar][4]. Next the App IDs and Tik Tok App IDs must be set in app.xaml.cs.
* The App IDs come from the respective app stores
* See [Generating TikTok App IDs][2]

## Manually Building The Android Binding
These steps may or may not be required based on your machine's configuration.

```shell
cd tiktok/android/native
./gradlew build
cd ../TikTok.Android.Binding
dotnet build -t:InstallAndroidDependencies -f net9.0-android
```

### Build and Run
```shell
dotnet build sample -t:Run -f net9.0-android
dotnet build sample -t:Run -f net9.0-ios
```

## Notes
* If you experience issues with missing references manually invoking gradlew build before building the dotnet project helps.
* NativeLibraryInterop depends on "CommunityToolkit.Maui.NativeLibraryInterop.BuildTasks", this package is not yet on Nuget, when migrating this sample into your project be sure to include the NuGet.Config in your project's folder.
* You will also need to add the following to your project's csproj
```
<ItemGroup Condition="$(TargetFramework.Contains('android'))">
<AndroidLibrary Include="tiktok-business-android-sdk-1.3.8.aar">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</AndroidLibrary>
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommunityToolkit.Maui.NativeLibraryInterop.BuildTasks" Version="0.0.1-pre1" PrivateAssets="all" />
</ItemGroup>
```

[0]: https://business-api.tiktok.com/portal/docs?id=1739584951798785
[1]: https://jitpack.io/com/github/tiktok/tiktok-business-android-sdk/1.3.8/tiktok-business-android-sdk-1.3.8.aar
[2]: https://business-api.tiktok.com/portal/docs?id=1739584951798785#item-link-Generate%20your%20TikTok%20App%20ID
[3]: https://jitpack.io/com/github/tiktok/tiktok-business-android-sdk/1.3.8/
[4]: https://jitpack.io/com/github/tiktok/tiktok-business-android-sdk/1.3.8/tiktok-business-android-sdk-1.3.8.aar
48 changes: 48 additions & 0 deletions tiktok/android/TikTok.Android.Binding/Additions/AboutAdditions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Additions allow you to add arbitrary C# to the generated classes
before they are compiled. This can be helpful for providing convenience
methods or adding pure C# classes.

== Adding Methods to Generated Classes ==

Let's say the library being bound has a Rectangle class with a constructor
that takes an x and y position, and a width and length size. It will look like
this:

public partial class Rectangle
{
public Rectangle (int x, int y, int width, int height)
{
// JNI bindings
}
}

Imagine we want to add a constructor to this class that takes a Point and
Size structure instead of 4 ints. We can add a new file called Rectangle.cs
with a partial class containing our new method:

public partial class Rectangle
{
public Rectangle (Point location, Size size) :
this (location.X, location.Y, size.Width, size.Height)
{
}
}

At compile time, the additions class will be added to the generated class
and the final assembly will a Rectangle class with both constructors.


== Adding C# Classes ==

Another thing that can be done is adding fully C# managed classes to the
generated library. In the above example, let's assume that there isn't a
Point class available in Java or our library. The one we create doesn't need
to interact with Java, so we'll create it like a normal class in C#.

By adding a Point.cs file with this class, it will end up in the binding library:

public class Point
{
public int X { get; set; }
public int Y { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0-android</TargetFramework>
<SupportedOSPlatformVersion>21</SupportedOSPlatformVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<!--
Enable trim analyzers for Android class libraries.
To learn more, see: https://learn.microsoft.com/dotnet/core/deploying/trimming/prepare-libraries-for-trimming
-->
<IsTrimmable>true</IsTrimmable>
<RootNamespace>MauiTikTokAndroid.Android.Binding</RootNamespace>
<!--
NOTE: you can simply add .aar or .jar files in this directory to be included in the project.
To learn more, see: https://learn.microsoft.com/dotnet/maui/migration/android-binding-projects
-->
</PropertyGroup>

<!-- Reference to Android Gradle project -->
<ItemGroup>
<AndroidGradleProject Include="../native/build.gradle.kts" >
<ModuleName>MauiTikTok</ModuleName>
<!-- Metadata applicable to @(AndroidLibrary) will be used if set, otherwise the following defaults will be used:
<Bind>true</Bind>
<Pack>true</Pack>
-->
</AndroidGradleProject>
</ItemGroup>

</Project>
14 changes: 14 additions & 0 deletions tiktok/android/TikTok.Android.Binding/Transforms/EnumFields.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<enum-field-mappings>
<!--
This example converts the constants Fragment_id, Fragment_name,
and Fragment_tag from android.support.v4.app.FragmentActivity.FragmentTag
to an enum called Android.Support.V4.App.FragmentTagType with values
Id, Name, and Tag.

<mapping jni-class="android/support/v4/app/FragmentActivity$FragmentTag" clr-enum-type="Android.Support.V4.App.FragmentTagType">
<field jni-name="Fragment_name" clr-name="Name" value="0" />
<field jni-name="Fragment_id" clr-name="Id" value="1" />
<field jni-name="Fragment_tag" clr-name="Tag" value="2" />
</mapping>
-->
</enum-field-mappings>
13 changes: 13 additions & 0 deletions tiktok/android/TikTok.Android.Binding/Transforms/EnumMethods.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<enum-method-mappings>
<!--
This example changes the Java method:
android.support.v4.app.Fragment.SavedState.writeToParcel (int flags)
to be:
android.support.v4.app.Fragment.SavedState.writeToParcel (Android.OS.ParcelableWriteFlags flags)
when bound in C#.

<mapping jni-class="android/support/v4/app/Fragment.SavedState">
<method jni-name="writeToParcel" parameter="flags" clr-enum-type="Android.OS.ParcelableWriteFlags" />
</mapping>
-->
</enum-method-mappings>
4 changes: 4 additions & 0 deletions tiktok/android/TikTok.Android.Binding/Transforms/Metadata.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<metadata>
<!-- Make sure the package id and name reflects the new binding name -->
<attr path="/api/package[@name='com.microsoft.tiktok']" name="managedName">MauiTikTokAndroid</attr>
</metadata>
15 changes: 15 additions & 0 deletions tiktok/android/native/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
*/build
/captures
.externalNativeBuild
.cxx
local.properties
6 changes: 6 additions & 0 deletions tiktok/android/native/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id("com.android.library") version "8.6.1" apply false
}


21 changes: 21 additions & 0 deletions tiktok/android/native/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app's APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Mon Jun 24 14:49:07 EDT 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading