เริ่มต้นใช้งาน Unity SDK ฉบับย่อ
เริ่มต้นใช้งาน Pushwoosh Unity SDK ด้วยตัวอย่างที่รวดเร็วและเรียบง่ายนี้
ข้อกำหนดเบื้องต้น
Anchor link toในการผสานรวม Pushwoosh Unity SDK เข้ากับแอปของคุณ คุณจะต้องมีสิ่งต่อไปนี้:
ดาวน์โหลดโปรเจกต์ตัวอย่าง
Anchor link toโคลน repository ของโปรเจกต์ตัวอย่าง:
git clone https://github.com/Pushwoosh/pushwoosh-unity-sample.gitกำหนดค่าโปรเจกต์
Anchor link toเปิด Assets/Scripts/PushNotificator.cs และตั้งค่าการเริ่มต้นของ Pushwoosh:
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 toBuild โปรเจกต์ iOS จาก Unity จากนั้นไปที่ไดเรกทอรีโปรเจกต์ Xcode ที่สร้างขึ้นและติดตั้ง dependencies ของ CocoaPods:
cd ios && pod install3. ตั้งค่า API Token
Anchor link toเปิดไฟล์ ios/Unity-iPhone.xcworkspace ใน Xcode
ใน Info.plist ของคุณ เพิ่ม Pushwoosh Device API Token:
<key>Pushwoosh_API_TOKEN</key><string>__PUSHWOOSH_DEVICE_API_TOKEN__</string>Android
Anchor link to1. ตั้งค่า 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>:
<meta-data android:name="com.pushwoosh.apitoken" android:value="__YOUR_DEVICE_API_TOKEN__" />รันโปรเจกต์
Anchor link to- Build และรันโปรเจกต์
- แตะปุ่ม Register for push notifications
- ให้สิทธิ์สำหรับ push notifications อุปกรณ์จะถูกลงทะเบียนกับ Pushwoosh
ส่ง push notification
Anchor link toไปที่ Pushwoosh Control Panel และ ส่ง push notification ไปยังอุปกรณ์ที่ลงทะเบียนของคุณ