ข้ามไปยังเนื้อหา

เริ่มต้นใช้งาน Unity SDK ฉบับย่อ

เริ่มต้นใช้งาน Pushwoosh Unity SDK ด้วยตัวอย่างที่รวดเร็วและเรียบง่ายนี้

ข้อกำหนดเบื้องต้น

Anchor link to

ในการผสานรวม Pushwoosh Unity SDK เข้ากับแอปของคุณ คุณจะต้องมีสิ่งต่อไปนี้:

ดาวน์โหลดโปรเจกต์ตัวอย่าง

Anchor link to

โคลน repository ของโปรเจกต์ตัวอย่าง:

Terminal window
git clone https://github.com/Pushwoosh/pushwoosh-unity-sample.git

กำหนดค่าโปรเจกต์

Anchor link to

เปิด Assets/Scripts/PushNotificator.cs และตั้งค่าการเริ่มต้นของ Pushwoosh:

Assets/Scripts/PushNotificator.cs
Pushwoosh.ApplicationCode = "XXXXX-XXXXX";
Pushwoosh.FcmProjectNumber = "XXXXXXXXXXXX";

แทนที่ค่า ApplicationCode และ FcmProjectNumber ด้วย Pushwoosh App Code และ Firebase Project Number ของคุณ

1. ตั้งค่า Bundle Identifier
Anchor link to

ใน Unity ไปที่ Edit > Project Settings > Player > iOS > Other Settings และตั้งค่า Bundle Identifier เป็น bundle ID ของคุณ (เช่น com.example.pushwoosh)

2. Build และติดตั้ง dependencies
Anchor link to

Build โปรเจกต์ iOS จาก Unity จากนั้นไปที่ไดเรกทอรีโปรเจกต์ Xcode ที่สร้างขึ้นและติดตั้ง dependencies ของ CocoaPods:

Terminal window
cd ios && pod install
3. ตั้งค่า API Token
Anchor link to

เปิดไฟล์ ios/Unity-iPhone.xcworkspace ใน Xcode ใน Info.plist ของคุณ เพิ่ม Pushwoosh Device API Token:

Info.plist
<key>Pushwoosh_API_TOKEN</key>
<string>__PUSHWOOSH_DEVICE_API_TOKEN__</string>
1. ตั้งค่า package name
Anchor link to

ใน Unity ไปที่ Edit > Project Settings > Player > Android > Other Settings และตั้งค่า Package Name เป็น package name ของแอปของคุณ (เช่น com.example.pushwoosh)

2. เพิ่ม google-services.json
Anchor link to

คัดลอกไฟล์ google-services.json ของคุณไปยังไดเรกทอรี Assets ในโปรเจกต์ Unity ของคุณ

3. ตั้งค่า API Token
Anchor link to

ใน Assets/Plugins/Android/AndroidManifest.xml ของคุณ เพิ่ม Pushwoosh Device API Token ภายในแท็ก <application>:

AndroidManifest.xml
<meta-data android:name="com.pushwoosh.apitoken" android:value="__YOUR_DEVICE_API_TOKEN__" />

รันโปรเจกต์

Anchor link to
  1. Build และรันโปรเจกต์
  2. แตะปุ่ม Register for push notifications
  3. ให้สิทธิ์สำหรับ push notifications อุปกรณ์จะถูกลงทะเบียนกับ Pushwoosh

ส่ง push notification

Anchor link to

ไปที่ Pushwoosh Control Panel และ ส่ง push notification ไปยังอุปกรณ์ที่ลงทะเบียนของคุณ